From ca72de8f6669d89e33eb86652ec3aabbffa44643 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sat, 1 Aug 2020 23:07:50 +0300 Subject: Added head cleaning jobs to job runs as "IS_HEAD_CLEANING" --- .../JobRuns/BasicJobRunsLogger.cs | 92 +++++++++++++++++++++- .../Tango.Integration/JobRuns/IJobRunsLogger.cs | 7 ++ 2 files changed, 98 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/Tango.Integration/JobRuns') 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; } + /// + /// Sets the head cleaning parameters. + /// + /// The machine. + 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. /// void Stop(); + + /// + /// Sets the head cleaning parameters. + /// + /// The machine. + void SetDefaultMachine(Machine machine); } } -- cgit v1.3.1