From ea06554bd915b078a2e80f6876087659bac707bf Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 12 Jan 2020 18:49:27 +0200 Subject: Working on job run liquid quantity. --- Software/Visual_Studio/Tango.BL/Entities/JobRun.cs | 38 +++++ Software/Visual_Studio/Tango.BL/Tango.BL.csproj | 3 +- .../Tango.BL/ValueObjects/JobRunLiquidQuantity.cs | 20 +++ .../ExternalBridge/ExternalBridgeTcpClient.cs | 6 + .../JobRuns/BasicJobRunsLogger.cs | 2 + .../Tango.Integration/Operation/MachineOperator.cs | 167 +++++++++++++++++---- .../Operation/PrintingEventArgs.cs | 3 + 7 files changed, 206 insertions(+), 33 deletions(-) create mode 100644 Software/Visual_Studio/Tango.BL/ValueObjects/JobRunLiquidQuantity.cs (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs b/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs index 30f28f9f4..1c4f3a5cd 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs @@ -6,11 +6,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL.Enumerations; +using Tango.BL.ValueObjects; namespace Tango.BL.Entities { public partial class JobRun : JobRunBase { + private List _liquidQuantities; + [NotMapped] [JsonIgnore] public JobRunStatus JobRunStatus @@ -19,6 +22,41 @@ namespace Tango.BL.Entities set { Status = (int)value; } } + [NotMapped] + [JsonIgnore] + public List LiquidQuantities + { + get + { + if (_liquidQuantities != null) + { + try + { + _liquidQuantities = JsonConvert.DeserializeObject>(LiquidQuantityString); + } + catch + { + _liquidQuantities = new List(); + } + } + else + { + _liquidQuantities = new List(); + } + + return _liquidQuantities; + } + set + { + _liquidQuantities = value; + + if (_liquidQuantities != null) + { + LiquidQuantityString = JsonConvert.SerializeObject(_liquidQuantities); + } + } + } + protected override void RaisePropertyChanged(string propName) { base.RaisePropertyChanged(propName); diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index b55d66606..fac46ad53 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -517,6 +517,7 @@ + @@ -594,7 +595,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.BL/ValueObjects/JobRunLiquidQuantity.cs b/Software/Visual_Studio/Tango.BL/ValueObjects/JobRunLiquidQuantity.cs new file mode 100644 index 000000000..9950e1c26 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/ValueObjects/JobRunLiquidQuantity.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Enumerations; + +namespace Tango.BL.ValueObjects +{ + public class JobRunLiquidQuantity + { + public LiquidTypes LiquidType { get; set; } + public int Quantity { get; set; } + + public override string ToString() + { + return $"{LiquidType}: {Quantity}"; + } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs index f2eceedeb..573cabb87 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs @@ -108,6 +108,9 @@ namespace Tango.Integration.ExternalBridge LogRequestSent(login); var response = await SendRequest(login); + + SessionLogger.CreateSession(); + DeviceInformation = response.Message.DeviceInformation; if (!response.Message.Authenticated) { @@ -237,6 +240,9 @@ namespace Tango.Integration.ExternalBridge } State = TransportComponentState.Disconnected; + + SessionLogger.EndSession(); + if (Adapter != null) { await Adapter.Disconnect(); diff --git a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs index 9eb010ec2..cc08de2a2 100644 --- a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs +++ b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs @@ -209,6 +209,8 @@ namespace Tango.Integration.JobRuns MachineGuid = _job.MachineGuid, EndPosition = e.JobHandler.Status.Progress, JobRunStatus = JobRunStatus.Completed, + JobLength = e.JobHandler.Status.TotalProgress, + LiquidQuantities = e.LiquidQuantities, }); e.Job.LastRun = DateTime.UtcNow; diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 6eb45619d..effd76dd2 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -72,9 +72,11 @@ namespace Tango.Integration.Operation private bool _threadLoadingSent; private static RunningJobStatus _last_job_status; private bool _isPowerDownRequestInProgress; + private List _currentJobLiquidQuantities; public static String EmbeddedLogsFolder { get; private set; } public static String EmbeddedLogsTag { get; private set; } + public static SessionFileLogger SessionLogger { get; set; } #region Constructors @@ -93,6 +95,12 @@ namespace Tango.Integration.Operation FileLogger fileLogger = new FileLogger(EmbeddedLogsFolder, EmbeddedLogsTag) { Enabled = true }; EmbeddedLogManager.RegisterLogger(fileLogger); } + + if (SessionLogger == null) + { + SessionLogger = new SessionFileLogger(); + LogManager.Default.RegisterLogger(SessionLogger); + } } /// @@ -249,6 +257,19 @@ namespace Tango.Integration.Operation #region Properties + /// + /// Gets or sets a value indicating whether to create a new designated session log file each successful connection. + /// This log file will contain standard logs that have occurred between the last connection and disconnection states. + /// + public static bool EnableSessionLogFile + { + get { return SessionLogger.Enabled; } + set + { + SessionLogger.Enabled = value; + } + } + /// /// Gets or sets the job handling mode. /// @@ -1122,6 +1143,76 @@ namespace Tango.Integration.Operation } } + /// + /// Called when the printing has been started. + /// + /// The handler. + /// The job. + protected virtual void OnPrintingStarted(JobHandler handler, Job job) + { + PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, job) + { + LiquidQuantities = _currentJobLiquidQuantities.ToList(), + }); + } + + /// + /// Called when the printing has been completed. + /// + /// The handler. + /// The job. + protected virtual void OnPrintingCompleted(JobHandler handler, Job job) + { + PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, job) + { + LiquidQuantities = _currentJobLiquidQuantities.ToList(), + }); + + OnPrintingEnded(handler, job); + } + + /// + /// Called when the printing has been failed. + /// + /// The handler. + /// The job. + /// The exception. + protected virtual void OnPrintingFailed(JobHandler handler, Job job, Exception exception) + { + PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, job, exception) + { + LiquidQuantities = _currentJobLiquidQuantities.ToList(), + }); + OnPrintingEnded(handler, job); + } + + /// + /// Called when the printing has been aborted. + /// + /// The handler. + /// The job. + protected virtual void OnPrintingAborted(JobHandler handler, Job job) + { + PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, job) + { + LiquidQuantities = _currentJobLiquidQuantities.ToList(), + }); + OnPrintingEnded(handler, job); + } + + /// + /// Called when the printing has been ended. + /// + /// The handler. + /// The job. + protected virtual void OnPrintingEnded(JobHandler handler, Job job) + { + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, job) + { + LiquidQuantities = _currentJobLiquidQuantities.ToList(), + }); + } + #endregion #region Override Methods @@ -1154,6 +1245,8 @@ namespace Tango.Integration.Operation Status = MachineStatuses.Disconnected; + SessionLogger.EndSession(); + if (State == TransportComponentState.Connected) { DisconnectRequest request = new DisconnectRequest(); @@ -1206,6 +1299,9 @@ namespace Tango.Integration.Operation try { var response = await SendRequest(request); + + SessionLogger.CreateSession(); + LogResponseReceived(response.Message); _isPowerDownRequestInProgress = false; @@ -1293,8 +1389,7 @@ namespace Tango.Integration.Operation try { var result = await SendRequest(new AbortJobRequest()); - PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + OnPrintingAborted(handler, originalJob); handler.RaiseCanceled(); } catch (Exception ex) @@ -1337,7 +1432,7 @@ namespace Tango.Integration.Operation Status = MachineStatuses.GettingReady; responseLogged = true; RunningJob = originalJob; - PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + OnPrintingStarted(handler, originalJob); LogResponseReceived(response.Message); } @@ -1373,8 +1468,7 @@ namespace Tango.Integration.Operation if (!handler.IsCanceled) { - PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, originalJob, ex)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + OnPrintingFailed(handler, originalJob, ex); handler.RaiseFailed(ex); LogRequestFailed(request, ex); } @@ -1390,8 +1484,7 @@ namespace Tango.Integration.Operation { completed = true; Status = MachineStatuses.ReadyToDye; - PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + OnPrintingCompleted(handler, originalJob); handler.RaiseCompleted(); } }); @@ -1559,7 +1652,7 @@ namespace Tango.Integration.Operation responseLogged = true; Status = MachineStatuses.Printing; RunningJob = handler.Job; - PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, handler.Job)); + OnPrintingStarted(handler, handler.Job); LogResponseReceived(response.Message); } @@ -1571,8 +1664,7 @@ namespace Tango.Integration.Operation if (!handler.IsCanceled) { - PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, handler.Job, ex)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, handler.Job)); + OnPrintingFailed(handler, handler.Job, ex); handler.RaiseFailed(ex); LogRequestFailed(request, ex); } @@ -1586,8 +1678,7 @@ namespace Tango.Integration.Operation if (segment == job.OrderedSegments.Last()) { Status = MachineStatuses.ReadyToDye; - PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, handler.Job)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, handler.Job)); + OnPrintingCompleted(handler, handler.Job); handler.RaiseCompleted(); } else @@ -1597,8 +1688,7 @@ namespace Tango.Integration.Operation ContinueSingleSpoolJob(segment.GetNextSegment(), job, processParameters, handler); }, () => { - PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, handler.Job)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, handler.Job)); + OnPrintingAborted(handler, handler.Job); Status = MachineStatuses.ReadyToDye; handler.RaiseCanceled(); }); @@ -1614,7 +1704,9 @@ namespace Tango.Integration.Operation { liquidQuantities.Add(pack.PackIndex, 0); } + int resolution = GradientGenerationConfiguration.ResolutionCM; + for (int i = 0; i < Math.Max(job.NumberOfUnits, 1); i++) { for (int segmentIndex = 0; segmentIndex < job.Segments.Count; segmentIndex++) @@ -1626,25 +1718,35 @@ namespace Tango.Integration.Operation int solid_gradient_oeff = orderedBrushCollection.Count == 1 ? 1 : 2; double prev_offset_cm = 0; + for (int brushIndex = 0; brushIndex < orderedBrushCollection.Count; brushIndex++) { var brush = orderedBrushCollection[brushIndex]; double brush_length_centimeters = 0d; double brush_offset_cm = 0; + if ((brushIndex + 1) < orderedBrushCollection.Count) { brush_offset_cm = (brush.OffsetMeters * 100d); double next_brush_offset_cm = (orderedBrushCollection[brushIndex + 1].OffsetMeters * 100d); brush_length_centimeters = ((next_brush_offset_cm - brush_offset_cm) + (brush_offset_cm - prev_offset_cm)); - if (brushIndex == 0)// add a resolution step for first brush + + if (brushIndex == 0) + { + // add a resolution step for first brush brush_length_centimeters += resolution; + } } else//last brush or solid brush { brush_length_centimeters = (segment_length_cm - prev_offset_cm); - if (orderedBrushCollection.Count > 1)// add a resolution for last brush , not solid brush + if (orderedBrushCollection.Count > 1) + { + // add a resolution for last brush , not solid brush brush_length_centimeters -= resolution; + } } + prev_offset_cm = brush_offset_cm; foreach (var liquidVolumes in brush.LiquidVolumes) @@ -1698,6 +1800,14 @@ namespace Tango.Integration.Operation } } + _currentJobLiquidQuantities = new List(); + foreach (var liquid in exception.IdsPackLevels) + { + BL.ValueObjects.JobRunLiquidQuantity quantity = new BL.ValueObjects.JobRunLiquidQuantity(); + quantity.LiquidType = liquid.IdsPack.LiquidType.Type; + quantity.Quantity = liquid.Required; + _currentJobLiquidQuantities.Add(quantity); + } if (shouldThrow) { @@ -2091,8 +2201,7 @@ namespace Tango.Integration.Operation var result = await SendRequest(new AbortJobRequest()); } - PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, clonedJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, clonedJob)); + OnPrintingAborted(handler, clonedJob); handler.RaiseCanceled(); } } @@ -2117,7 +2226,7 @@ namespace Tango.Integration.Operation { Status = MachineStatuses.GettingReady; RunningJob = clonedJob; - PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, clonedJob)); + OnPrintingStarted(handler, clonedJob); Thread.Sleep(100); @@ -2243,8 +2352,7 @@ namespace Tango.Integration.Operation { UseKeepAlive = oldKeepAlive; Status = MachineStatuses.ReadyToDye; - PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, clonedJob, ex)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, clonedJob)); + OnPrintingFailed(handler, clonedJob, ex); handler.RaiseFailed(ex); LogRequestFailed(request, ex); return; @@ -2323,8 +2431,7 @@ namespace Tango.Integration.Operation if (!handler.IsCanceled) { - PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, clonedJob, ex)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, clonedJob)); + OnPrintingFailed(handler, originalJob, ex); handler.RaiseFailed(ex); LogRequestFailed(request, ex); } @@ -2346,8 +2453,7 @@ namespace Tango.Integration.Operation UseKeepAlive = oldKeepAlive; Status = MachineStatuses.ReadyToDye; - PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, clonedJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, clonedJob)); + OnPrintingCompleted(handler, clonedJob); handler.RaiseCompleted(); } }); @@ -2523,8 +2629,7 @@ namespace Tango.Integration.Operation try { var result = await SendRequest(new StubAbortJobRequest()); - PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + OnPrintingAborted(handler, originalJob); handler.RaiseCanceled(); } catch (Exception ex) @@ -2550,7 +2655,7 @@ namespace Tango.Integration.Operation responseLogged = true; Status = MachineStatuses.Printing; RunningJob = originalJob; - PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + OnPrintingStarted(handler, originalJob); LogResponseReceived(response.Message); } }, (ex) => @@ -2561,8 +2666,7 @@ namespace Tango.Integration.Operation if (!handler.IsCanceled) { - PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, originalJob, ex)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + OnPrintingFailed(handler, originalJob, ex); handler.RaiseFailed(ex); LogRequestFailed(request, ex); } @@ -2574,8 +2678,7 @@ namespace Tango.Integration.Operation }, () => { Status = MachineStatuses.ReadyToDye; - PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + OnPrintingCompleted(handler, originalJob); handler.RaiseCompleted(); }); diff --git a/Software/Visual_Studio/Tango.Integration/Operation/PrintingEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Operation/PrintingEventArgs.cs index fe8a573a5..d4c2ad4e8 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/PrintingEventArgs.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/PrintingEventArgs.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL.Entities; +using Tango.BL.ValueObjects; namespace Tango.Integration.Operation { @@ -11,9 +12,11 @@ namespace Tango.Integration.Operation { public JobHandler JobHandler { get; private set; } public Job Job { get; private set; } + public List LiquidQuantities { get; set; } public PrintingEventArgs(JobHandler jobHandler, Job job) { + LiquidQuantities = new List(); JobHandler = jobHandler; Job = job; } -- cgit v1.3.1