aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-01 23:07:50 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-01 23:07:50 +0300
commitca72de8f6669d89e33eb86652ec3aabbffa44643 (patch)
tree8688478ba6cbc13e05dddc540af8a14615c4c66f /Software/Visual_Studio/Tango.Integration
parentaf0cef3da965c7cf6f58faad51788816f001490e (diff)
downloadTango-ca72de8f6669d89e33eb86652ec3aabbffa44643.tar.gz
Tango-ca72de8f6669d89e33eb86652ec3aabbffa44643.zip
Added head cleaning jobs to job runs as "IS_HEAD_CLEANING"
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration')
-rw-r--r--Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs92
-rw-r--r--Software/Visual_Studio/Tango.Integration/JobRuns/IJobRunsLogger.cs7
-rw-r--r--Software/Visual_Studio/Tango.Integration/Operation/HeadCleaningEndedEventArgs.cs24
-rw-r--r--Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs5
-rw-r--r--Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs72
-rw-r--r--Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj3
6 files changed, 191 insertions, 12 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs
index e7308dfc7..64ad60db5 100644
--- a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs
+++ b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs
@@ -19,6 +19,7 @@ namespace Tango.Integration.JobRuns
public class BasicJobRunsLogger : ExtendedObject, IJobRunsLogger
{
private Job _job;
+ private Machine _defaultMachine;
#region Properties
@@ -74,6 +75,7 @@ namespace Tango.Integration.JobRuns
MachineOperator.PrintingAborted += Machine_PrintingAborted;
MachineOperator.PrintingFailed -= Machine_PrintingFailed;
MachineOperator.PrintingFailed += Machine_PrintingFailed;
+ MachineOperator.HeadCleaningEnded += MachineOperator_HeadCleaningEnded;
}
private bool ShouldLog()
@@ -168,13 +170,87 @@ namespace Tango.Integration.JobRuns
}
catch (Exception ex)
{
- LogManager.Log(ex, "Error logging the current job run to the database.");
+ LogManager.Log(ex, "Error logging the last job run to the database.");
}
});
}
}
}
+ private void InsertHeadCleaningJobRun(HeadCleaningEndedEventArgs e)
+ {
+ if (IsStarted && _defaultMachine != null)
+ {
+ Task.Factory.StartNew(() =>
+ {
+ try
+ {
+ using (var db = ObservablesContext.CreateDefault())
+ {
+ JobRun run = new JobRun();
+
+ run.IsHeadCleaning = true;
+ run.StartDate = e.StartDate;
+ run.UploadingStartDate = e.StartDate;
+ run.HeatingStartDate = e.StartDate;
+ run.ActualStartDate = e.StartDate;
+ run.EndDate = DateTime.UtcNow;
+ run.JobName = "HEAD CLEANING";
+ run.Source = JobSource;
+ run.MachineGuid = _defaultMachine.Guid;
+ run.JobRunStatus = e.Status;
+ run.EndPosition = e.EndPosition;
+ run.JobLength = e.Length;
+ run.LiquidQuantities = e.LiquidQuantities;
+
+ //Set individual liquid quantities
+
+ //Cyan
+ var cyan = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Cyan);
+ run.CyanQuantity = cyan != null ? cyan.Quantity : 0;
+
+ //Magenta
+ var magenta = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Magenta);
+ run.MagentaQuantity = magenta != null ? magenta.Quantity : 0;
+
+ //Yellow
+ var yellow = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Yellow);
+ run.YellowQuantity = yellow != null ? yellow.Quantity : 0;
+
+ //Black
+ var black = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Black);
+ run.BlackQuantity = black != null ? black.Quantity : 0;
+
+ //TI
+ var ti = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.TransparentInk);
+ run.TransparentQuantity = ti != null ? ti.Quantity : 0;
+
+ //Lubricant
+ var lubricant = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Lubricant);
+ run.LubricantQuantity = lubricant != null ? lubricant.Quantity : 0;
+
+ //Cleaner
+ var cleaner = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Cleaner);
+ run.CleanerQuantity = cleaner != null ? cleaner.Quantity : 0;
+
+ //if (exception != null)
+ //{
+ // run.FailedMessage = exception.FlattenMessage();
+ //}
+
+ db.JobRuns.Add(run);
+
+ db.SaveChanges();
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error logging the last head cleaning job run to the database.");
+ }
+ });
+ }
+ }
+
#endregion
#region Public Methods
@@ -195,6 +271,15 @@ namespace Tango.Integration.JobRuns
IsStarted = false;
}
+ /// <summary>
+ /// Sets the head cleaning parameters.
+ /// </summary>
+ /// <param name="machine">The machine.</param>
+ public void SetDefaultMachine(Machine machine)
+ {
+ _defaultMachine = machine;
+ }
+
#endregion
#region Event Handlers
@@ -234,6 +319,11 @@ namespace Tango.Integration.JobRuns
}
}
+ private void MachineOperator_HeadCleaningEnded(object sender, HeadCleaningEndedEventArgs e)
+ {
+ InsertHeadCleaningJobRun(e);
+ }
+
#endregion
}
}
diff --git a/Software/Visual_Studio/Tango.Integration/JobRuns/IJobRunsLogger.cs b/Software/Visual_Studio/Tango.Integration/JobRuns/IJobRunsLogger.cs
index a5242c1a4..386298bb9 100644
--- a/Software/Visual_Studio/Tango.Integration/JobRuns/IJobRunsLogger.cs
+++ b/Software/Visual_Studio/Tango.Integration/JobRuns/IJobRunsLogger.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.Integration.Operation;
@@ -42,5 +43,11 @@ namespace Tango.Integration.JobRuns
/// Stops the logger.
/// </summary>
void Stop();
+
+ /// <summary>
+ /// Sets the head cleaning parameters.
+ /// </summary>
+ /// <param name="machine">The machine.</param>
+ void SetDefaultMachine(Machine machine);
}
}
diff --git a/Software/Visual_Studio/Tango.Integration/Operation/HeadCleaningEndedEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Operation/HeadCleaningEndedEventArgs.cs
new file mode 100644
index 000000000..0929c1254
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Integration/Operation/HeadCleaningEndedEventArgs.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.Enumerations;
+using Tango.BL.ValueObjects;
+
+namespace Tango.Integration.Operation
+{
+ public class HeadCleaningEndedEventArgs : EventArgs
+ {
+ public List<JobRunLiquidQuantity> LiquidQuantities { get; set; }
+ public DateTime StartDate { get; set; }
+ public double EndPosition { get; set; }
+ public double Length { get; set; }
+ public JobRunStatus Status { get; set; }
+
+ public HeadCleaningEndedEventArgs()
+ {
+ LiquidQuantities = new List<JobRunLiquidQuantity>();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs
index d006848de..bee4a7523 100644
--- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs
+++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs
@@ -241,6 +241,11 @@ namespace Tango.Integration.Operation
event EventHandler<StartThreadLoadingResponse> ThreadLoadingFailed;
/// <summary>
+ /// Occurs when a head cleaning job has ended.
+ /// </summary>
+ event EventHandler<HeadCleaningEndedEventArgs> HeadCleaningEnded;
+
+ /// <summary>
/// Gets or sets a value indicating whether direct the embedded device to send diagnostics messages.
/// </summary>
bool EnableDiagnostics { get; set; }
diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
index 0ae2086d3..57613aae2 100644
--- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
+++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
@@ -74,9 +74,10 @@ namespace Tango.Integration.Operation
private static RunningJobStatus _last_job_status;
private bool _isPowerDownRequestInProgress;
private bool _isHeadCleaningInProgress;
- private List<BL.ValueObjects.JobRunLiquidQuantity> _currentJobLiquidQuantities;
+ private List<BL.ValueObjects.JobRunLiquidQuantity> _lastJobLiquidQuantities;
private DateTime _diagnosticsTime;
private MachineStatus _machineStatusBeforeJobStart;
+ private Configuration _machineConfiguration;
private DateTime _jobStartDate;
private DateTime? _jobUploadingStartDate;
@@ -271,6 +272,11 @@ namespace Tango.Integration.Operation
/// </summary>
public event EventHandler PowerUpEnded;
+ /// <summary>
+ /// Occurs when a head cleaning job has ended.
+ /// </summary>
+ public event EventHandler<HeadCleaningEndedEventArgs> HeadCleaningEnded;
+
#endregion
#region Properties
@@ -1115,7 +1121,7 @@ namespace Tango.Integration.Operation
{
PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, job)
{
- LiquidQuantities = _currentJobLiquidQuantities.ToList(),
+ LiquidQuantities = _lastJobLiquidQuantities.ToList(),
StartDate = _jobStartDate,
UploadingStartTime = _jobUploadingStartDate,
HeatingStartTime = _jobHeatingStartDate,
@@ -1135,7 +1141,7 @@ namespace Tango.Integration.Operation
{
PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, job, exception)
{
- LiquidQuantities = _currentJobLiquidQuantities.ToList(),
+ LiquidQuantities = _lastJobLiquidQuantities.ToList(),
StartDate = _jobStartDate,
UploadingStartTime = _jobUploadingStartDate,
HeatingStartTime = _jobHeatingStartDate,
@@ -1153,7 +1159,7 @@ namespace Tango.Integration.Operation
{
PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, job)
{
- LiquidQuantities = _currentJobLiquidQuantities.ToList(),
+ LiquidQuantities = _lastJobLiquidQuantities.ToList(),
StartDate = _jobStartDate,
UploadingStartTime = _jobUploadingStartDate,
HeatingStartTime = _jobHeatingStartDate,
@@ -1171,7 +1177,7 @@ namespace Tango.Integration.Operation
{
PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, job)
{
- LiquidQuantities = _currentJobLiquidQuantities.ToList(),
+ LiquidQuantities = _lastJobLiquidQuantities.ToList(),
StartDate = _jobStartDate,
UploadingStartTime = _jobUploadingStartDate,
HeatingStartTime = _jobHeatingStartDate,
@@ -1179,6 +1185,20 @@ namespace Tango.Integration.Operation
});
}
+ protected virtual void OnHeadCleaningEnded(HeadCleaningHandler handler, JobRunStatus status)
+ {
+ SaveLastJobLiquidQuantities(null, null, null, null);
+
+ HeadCleaningEnded?.Invoke(this, new HeadCleaningEndedEventArgs()
+ {
+ StartDate = _jobStartDate,
+ Length = handler.Status.Total,
+ EndPosition = handler.Status.Progress,
+ Status = status,
+ LiquidQuantities = _lastJobLiquidQuantities.ToList(),
+ });
+ }
+
#endregion
#region Override Methods
@@ -1893,9 +1913,14 @@ namespace Tango.Integration.Operation
/// <param name="handler">The handler.</param>
private void SaveLastJobLiquidQuantities(Job job, Configuration configuration, ProcessParametersTable processParameters, JobHandler handler)
{
+ if (configuration == null)
+ {
+ configuration = _machineConfiguration;
+ }
+
try
{
- _currentJobLiquidQuantities = new List<BL.ValueObjects.JobRunLiquidQuantity>();
+ _lastJobLiquidQuantities = new List<BL.ValueObjects.JobRunLiquidQuantity>();
if (JobLiquidQuantityCalculationMode == JobLiquidQuantityCalculationMode.MachineStatus)
{
@@ -1906,7 +1931,7 @@ namespace Tango.Integration.Operation
if (packLevelAfter != null && packLevelBefore != null)
{
- _currentJobLiquidQuantities.Add(new BL.ValueObjects.JobRunLiquidQuantity()
+ _lastJobLiquidQuantities.Add(new BL.ValueObjects.JobRunLiquidQuantity()
{
LiquidType = pack.LiquidType.Type,
Quantity = packLevelBefore.DispenserLevel - packLevelAfter.DispenserLevel,
@@ -1916,7 +1941,7 @@ namespace Tango.Integration.Operation
}
else
{
- _currentJobLiquidQuantities = CreateJobRunLiquidQuantities(job, configuration, processParameters, handler.Status.Progress, handler.Status.TotalProgress);
+ _lastJobLiquidQuantities = CreateJobRunLiquidQuantities(job, configuration, processParameters, handler.Status.Progress, handler.Status.TotalProgress);
}
}
catch (Exception ex)
@@ -2319,7 +2344,7 @@ namespace Tango.Integration.Operation
LogManager.Log($"Executing job '{job.Name}'...");
- _currentJobLiquidQuantities = new List<BL.ValueObjects.JobRunLiquidQuantity>();
+ _lastJobLiquidQuantities = new List<BL.ValueObjects.JobRunLiquidQuantity>();
_jobUploadingStartDate = null;
_jobHeatingStartDate = null;
_jobActualStartDate = null;
@@ -2906,6 +2931,8 @@ namespace Tango.Integration.Operation
/// <returns></returns>
public async Task<UploadHardwareConfigurationResponse> UploadHardwareConfiguration(HardwareVersion hardwareVersion, Configuration configuration)
{
+ _machineConfiguration = configuration;
+
try
{
hardwareVersion = configuration.GetHardwareConfiguration().Merge(hardwareVersion);
@@ -3745,11 +3772,20 @@ namespace Tango.Integration.Operation
}
_isHeadCleaningInProgress = true;
+ bool _completed = false;
- HeadCleaningHandler handler = new HeadCleaningHandler(() =>
+ HeadCleaningHandler handler = null;
+ handler = new HeadCleaningHandler(() =>
{
_isHeadCleaningInProgress = false;
Thread.Sleep(1000);
+
+ if (!_completed)
+ {
+ _completed = true;
+ OnHeadCleaningEnded(handler, JobRunStatus.Aborted);
+ }
+
var r = SendRequest<AbortHeadCleaningRequest, AbortHeadCleaningResponse>(new AbortHeadCleaningRequest(), new TransportRequestConfig() { ShouldLog = true }).Result;
});
@@ -3757,7 +3793,11 @@ namespace Tango.Integration.Operation
{
Thread.Sleep(100);
+ _lastJobLiquidQuantities = new List<BL.ValueObjects.JobRunLiquidQuantity>();
+ _machineStatusBeforeJobStart = MachineStatus.Clone();
+
bool firstResponse = true;
+ _jobStartDate = DateTime.UtcNow;
SendContinuousRequest<StartHeadCleaningRequest, StartHeadCleaningResponse>(new StartHeadCleaningRequest(), new TransportContinuousRequestConfig() { ContinuousTimeout = TimeSpan.FromSeconds(5), ShouldLog = true }).ObserveOn(new NewThreadScheduler()).Subscribe((response) =>
{
@@ -3775,10 +3815,22 @@ namespace Tango.Integration.Operation
LogManager.Log(ex, "Head cleaning error.");
handler.RaiseFailed(ex);
}
+
+ if (!_completed)
+ {
+ _completed = true;
+ OnHeadCleaningEnded(handler, JobRunStatus.Failed);
+ }
}, () =>
{
_isHeadCleaningInProgress = false;
handler.RaiseCompleted();
+
+ if (!_completed)
+ {
+ _completed = true;
+ OnHeadCleaningEnded(handler, JobRunStatus.Completed);
+ }
});
});
diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj
index 91edb951e..7efd29d0a 100644
--- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj
+++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj
@@ -117,6 +117,7 @@
<Compile Include="Operation\DefaultMachineEventsStateProvider.cs" />
<Compile Include="Logging\EmbeddedLogItem.cs" />
<Compile Include="Operation\DefaultGradientGenerationConfiguration.cs" />
+ <Compile Include="Operation\HeadCleaningEndedEventArgs.cs" />
<Compile Include="Operation\HeadCleaningHandler.cs" />
<Compile Include="Operation\HeadCleaningStatusChangedEventArgs.cs" />
<Compile Include="Operation\IGradientGenerationConfiguration.cs" />
@@ -219,7 +220,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
+ <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file