blob: ce47ec06387b6938f97aa01b6cad84ad71da1771 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Builders;
using Tango.BL.Entities;
using Tango.Core;
using Tango.Integration.Operation;
using Z.EntityFramework.Plus;
namespace Tango.JobRunsGenerator
{
class Program
{
static void Main(string[] args)
{
DataSource dataSource = new DataSource();
dataSource.Catalog = "Tango_DEV";
dataSource.Address = "twine.database.windows.net";
dataSource.IntegratedSecurity = false;
dataSource.UserName = "Roy";
dataSource.Password = "Aa123456";
using (ObservablesContext db = ObservablesContext.CreateDefault(dataSource))
{
var count = db.JobRuns.Where(x => x.JobGuid != null).Count();
int index = 0;
int saveIndex = 0;
var runsGroup = db.JobRuns.Where(x => x.JobGuid != null).GroupBy(x => x.JobGuid).ToList();
foreach (var runGroup in runsGroup)
{
var runs = runGroup;
var firstRun = runs.First();
var job = new JobBuilder(db).Set(x => x.Guid == firstRun.JobGuid).WithSegments().WithBrushStops().WithRML().Build();
if (job == null)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Job '{firstRun.JobGuid}' was not found on the database!");
Console.ForegroundColor = ConsoleColor.Gray;
continue;
}
var machine = new MachineBuilder(db).Set(job.MachineGuid).WithConfiguration().Build();
foreach (var segment in job.Segments)
{
foreach (var stop in segment.BrushStops)
{
stop.SetLiquidVolumes(machine.Configuration, job.Rml, job.Rml.GetActiveProcessGroup().ProcessParametersTables.First());
}
}
foreach (var run in runs)
{
Console.WriteLine($"Fixing job {job.Name}... ({index++}/{count})");
run.MachineGuid = job.MachineGuid;
run.JobSource = job.Source;
if (run.JobLength == 0) run.JobLength = job.LengthIncludingNumberOfUnits;
if (run.JobName == null) run.JobName = job.Name;
if (run.RmlGuid == null) run.RmlGuid = job.RmlGuid;
if (run.JobString == null) run.JobString = job.ToJobFileWhenLoaded().ToString();
if (run.LiquidQuantityString == null) run.LiquidQuantities = MachineOperator.CreateJobRunLiquidQuantitiesUsingIntegral(job, machine.Configuration, job.Rml.GetActiveProcessGroup().ProcessParametersTables.First(), run.EndPosition, job.LengthIncludingNumberOfUnits);
if (run.UserGuid == null) run.UserGuid = job.UserGuid;
if (run.UploadingStartDate == null) run.UploadingStartDate = run.StartDate;
if (run.HeatingStartDate == null) run.HeatingStartDate = run.StartDate;
if (run.ActualStartDate == null) run.ActualStartDate = run.StartDate;
run.IsGradient = job.Segments.Any(x => x.BrushStops.Count > 1);
//Set new liquid quantities.
if (run.CyanQuantity == 0 &&
run.MagentaQuantity == 0 &&
run.YellowQuantity == 0 &&
run.BlackQuantity == 0 &&
run.TransparentQuantity == 0 &&
run.LubricantQuantity == 0 &&
run.CleanerQuantity == 0)
{
//Cyan
var cyan = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Cyan);
run.CyanQuantity = cyan != null ? cyan.Quantity : 0;
//Magenta
var magenta = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Magenta);
run.MagentaQuantity = magenta != null ? magenta.Quantity : 0;
//Yellow
var yellow = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Yellow);
run.YellowQuantity = yellow != null ? yellow.Quantity : 0;
//Black
var black = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Black);
run.BlackQuantity = black != null ? black.Quantity : 0;
//TI
var ti = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Transparent);
run.TransparentQuantity = ti != null ? ti.Quantity : 0;
//Lubricant
var lubricant = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Lubricant);
run.LubricantQuantity = lubricant != null ? lubricant.Quantity : 0;
//Cleaner
var cleaner = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Cleaner);
run.CleanerQuantity = cleaner != null ? cleaner.Quantity : 0;
}
saveIndex++;
if (saveIndex > 100)
{
saveIndex = 0;
Console.WriteLine("Saving changes...");
db.SaveChanges();
}
}
}
Console.WriteLine("Saving changes...");
db.SaveChanges();
Console.WriteLine("Done!");
Console.ReadLine();
}
}
}
}
|