aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL
diff options
context:
space:
mode:
authorRoy <Roy.mail.net@gmail.com>2022-11-01 17:58:50 +0200
committerRoy <Roy.mail.net@gmail.com>2022-11-01 17:58:50 +0200
commit5ab455fb09c659e92ad4de41ec7472e2b8e48499 (patch)
tree77a6786eee4e5ae07d9b2b8e14fca7d8a6b3bcc3 /Software/Visual_Studio/Tango.BL
parenta8a1e530d7fb014a92b39e7414385b02691236a8 (diff)
downloadTango-5ab455fb09c659e92ad4de41ec7472e2b8e48499.tar.gz
Tango-5ab455fb09c659e92ad4de41ec7472e2b8e48499.zip
Hot folder impl completed.
Diffstat (limited to 'Software/Visual_Studio/Tango.BL')
-rw-r--r--Software/Visual_Studio/Tango.BL/Helpers/SegmentsCsvHelper.cs108
1 files changed, 71 insertions, 37 deletions
diff --git a/Software/Visual_Studio/Tango.BL/Helpers/SegmentsCsvHelper.cs b/Software/Visual_Studio/Tango.BL/Helpers/SegmentsCsvHelper.cs
index 395f9e826..f41d8c4f1 100644
--- a/Software/Visual_Studio/Tango.BL/Helpers/SegmentsCsvHelper.cs
+++ b/Software/Visual_Studio/Tango.BL/Helpers/SegmentsCsvHelper.cs
@@ -16,77 +16,91 @@ namespace Tango.BL.Helpers
{
private const double MAX_VOLUME = 200;
+ public class SegmentsCsvResult
+ {
+ public Rml Rml { get; set; }
+ public List<Segment> Segments { get; set; }
+
+ public SegmentsCsvResult()
+ {
+ Segments = new List<Segment>();
+ }
+ }
+
public class SegmentCsvModel
{
[CsvOrder(0)]
public String Index { get; set; }
[CsvOrder(1)]
- public String ColorSpace { get; set; }
+ public String ThreadName { get; set; }
[CsvOrder(2)]
+ public String ColorSpace { get; set; }
+
+ [CsvOrder(3)]
public String Length { get; set; }
- [CsvOrder(4)]
+ [CsvOrder(5)]
public String CatalogName1 { get; set; }
- [CsvOrder(5)]
+ [CsvOrder(6)]
public String CatalogItem1 { get; set; }
- [CsvOrder(6)]
- public String Red1 { get; set; }
[CsvOrder(7)]
- public String Green1 { get; set; }
+ public String Red1 { get; set; }
[CsvOrder(8)]
+ public String Green1 { get; set; }
+ [CsvOrder(9)]
public String Blue1 { get; set; }
- [CsvOrder(9)]
- public String L1 { get; set; }
[CsvOrder(10)]
- public String A1 { get; set; }
+ public String L1 { get; set; }
[CsvOrder(11)]
+ public String A1 { get; set; }
+ [CsvOrder(12)]
public String B1 { get; set; }
- [CsvOrder(12)]
- public String Cyan1 { get; set; }
[CsvOrder(13)]
- public String Magenta1 { get; set; }
+ public String Cyan1 { get; set; }
[CsvOrder(14)]
- public String Yellow1 { get; set; }
+ public String Magenta1 { get; set; }
[CsvOrder(15)]
+ public String Yellow1 { get; set; }
+ [CsvOrder(16)]
public String Black1 { get; set; }
- [CsvOrder(17)]
- public String CatalogName2 { get; set; }
[CsvOrder(18)]
+ public String CatalogName2 { get; set; }
+ [CsvOrder(19)]
public String CatalogItem2 { get; set; }
- [CsvOrder(19)]
- public String Red2 { get; set; }
[CsvOrder(20)]
- public String Green2 { get; set; }
+ public String Red2 { get; set; }
[CsvOrder(21)]
+ public String Green2 { get; set; }
+ [CsvOrder(22)]
public String Blue2 { get; set; }
- [CsvOrder(22)]
- public String L2 { get; set; }
[CsvOrder(23)]
- public String A2 { get; set; }
+ public String L2 { get; set; }
[CsvOrder(24)]
+ public String A2 { get; set; }
+ [CsvOrder(25)]
public String B2 { get; set; }
- [CsvOrder(25)]
- public String Cyan2{ get; set; }
[CsvOrder(26)]
- public String Magenta2 { get; set; }
+ public String Cyan2 { get; set; }
[CsvOrder(27)]
- public String Yellow2 { get; set; }
+ public String Magenta2 { get; set; }
[CsvOrder(28)]
+ public String Yellow2 { get; set; }
+ [CsvOrder(29)]
public String Black2 { get; set; }
-
+
public bool IsRgb2NullOrEqual()
{
if (String.IsNullOrWhiteSpace(Red2) || String.IsNullOrWhiteSpace(Green2) || String.IsNullOrWhiteSpace(Blue2)) return true;
@@ -96,7 +110,7 @@ namespace Tango.BL.Helpers
internal bool IsVolumeNullOrEqual()
{
- if (String.IsNullOrWhiteSpace(Cyan2) || String.IsNullOrWhiteSpace(Magenta2 ) || String.IsNullOrWhiteSpace(Yellow2) || String.IsNullOrWhiteSpace(Black2)) return true;
+ if (String.IsNullOrWhiteSpace(Cyan2) || String.IsNullOrWhiteSpace(Magenta2) || String.IsNullOrWhiteSpace(Yellow2) || String.IsNullOrWhiteSpace(Black2)) return true;
if (Cyan1 == Cyan2 && Magenta1 == Magenta2 && Yellow1 == Yellow2 && Black1 == Black2) return true;
return false;
}
@@ -116,12 +130,12 @@ namespace Tango.BL.Helpers
}
}
- public static Task<List<Segment>> FromFile(String filePath, Machine machine, ObservablesContext context)
+ public static Task<SegmentsCsvResult> FromFile(String filePath, Machine machine, ObservablesContext context)
{
return Task.Factory.StartNew(() =>
{
List<SegmentCsvModel> rows = CsvFile.Read<SegmentCsvModel>(new CsvSource(filePath)).ToList();
-
+
List<Segment> segments = new List<Segment>();
var catalogs = new CatalogsCollectionBuilder(context).SetAll().WithGroups().WithItems().BuildList();
@@ -132,6 +146,21 @@ namespace Tango.BL.Helpers
machine = new MachineBuilder(context).Set(machine.Guid).WithConfiguration().Build();
}
+ String threadName = null;
+
+ if (rows.Count > 0)
+ {
+ threadName = rows.First().ThreadName;
+ }
+
+ Rml rml = null;
+
+ if (threadName.IsNotNullOrEmpty())
+ {
+ rml = context.Rmls.FirstOrDefault(x => x.Name == threadName || x.DisplayName == threadName);
+ if (rml == null) throw new InvalidOperationException($"Thread type '{threadName}' not found.");
+ }
+
var idsPacks = machine.Configuration.NoneEmptyIdsPacks.ToList();
var cyanIdsPack = idsPacks.FirstOrDefault(x => x.LiquidType.Type == LiquidTypes.Cyan);
@@ -179,7 +208,7 @@ namespace Tango.BL.Helpers
if (colorSpace.Space == ColorSpaces.RGB)
{
int red1;
- if(!int.TryParse(row.Red1, out red1))
+ if (!int.TryParse(row.Red1, out red1))
{
throw new InvalidOperationException($"Value Red1 '{row.Red1}' should be a number on line'{lineCount}'.");
}
@@ -363,7 +392,7 @@ namespace Tango.BL.Helpers
else if (colorSpace.Space == ColorSpaces.LAB)
{
double number;
- if(!double.TryParse(row.L1, out number))
+ if (!double.TryParse(row.L1, out number))
throw new InvalidOperationException($"Value L1 '{row.L1}' should be a number on line'{lineCount}'.");
stop1.L = number;
if (stop1.L < 0 || stop1.L > 100) throw new InvalidOperationException($"Value L1 '{row.L1}' is out of range on line '{lineCount}'.");
@@ -387,7 +416,7 @@ namespace Tango.BL.Helpers
double l2;
if (!double.TryParse(row.L2, out l2))
throw new InvalidOperationException($"Value L2 '{row.L2}' should be a number on line'{lineCount}'.");
- stop2.L =l2;
+ stop2.L = l2;
if (stop2.L < 0 || stop2.L > 100) throw new InvalidOperationException($"Value L2 '{row.L2}' is out of range on line '{lineCount}'.");
double a2;
@@ -414,7 +443,11 @@ namespace Tango.BL.Helpers
}
}
- return segments;
+ return new SegmentsCsvResult()
+ {
+ Segments = segments,
+ Rml = rml
+ };
});
}
@@ -424,15 +457,16 @@ namespace Tango.BL.Helpers
{
SegmentCsvModel model = new SegmentCsvModel();
List<string> columnNames = model.GetType().GetProperties().Select(x => x.Name).ToList();
- CsvFile<SegmentCsvModel> csvFile = new CsvFile<SegmentCsvModel>(new CsvDestination(filePath), new CsvDefinition() {
+ CsvFile<SegmentCsvModel> csvFile = new CsvFile<SegmentCsvModel>(new CsvDestination(filePath), new CsvDefinition()
+ {
Columns = columnNames
});
- foreach(var segment in segments)
+ foreach (var segment in segments)
{
SegmentCsvModel csvmodel = new SegmentCsvModel();
csvmodel.Index = segment.SegmentIndex.ToString();
csvmodel.Length = segment.Length.ToString();
- if(segment.BrushStops.Count > 2 ) throw new InvalidOperationException($"Cannot save more than two brush stops!");
+ if (segment.BrushStops.Count > 2) throw new InvalidOperationException($"Cannot save more than two brush stops!");
//save first brush stop
if (segment.BrushStops.Count > 0)
{
@@ -491,7 +525,7 @@ namespace Tango.BL.Helpers
csvmodel.B2 = brushStop2.B.ToString();
}
}
-
+
csvFile.Append(csvmodel);
}
});