diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-01-12 18:49:27 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-01-12 18:49:27 +0200 |
| commit | ea06554bd915b078a2e80f6876087659bac707bf (patch) | |
| tree | ad02efd032c630d34a3c000f21eeaa323629b454 /Software/Visual_Studio/Tango.Integration | |
| parent | 2d59177c20966741d9b1ac052fe8ee6ca9ed2119 (diff) | |
| download | Tango-ea06554bd915b078a2e80f6876087659bac707bf.tar.gz Tango-ea06554bd915b078a2e80f6876087659bac707bf.zip | |
Working on job run liquid quantity.
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration')
4 files changed, 146 insertions, 32 deletions
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<ExternalBridgeLoginRequest, ExternalBridgeLoginResponse>(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<BL.ValueObjects.JobRunLiquidQuantity> _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); + } } /// <summary> @@ -250,6 +258,19 @@ namespace Tango.Integration.Operation #region Properties /// <summary> + /// 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. + /// </summary> + public static bool EnableSessionLogFile + { + get { return SessionLogger.Enabled; } + set + { + SessionLogger.Enabled = value; + } + } + + /// <summary> /// Gets or sets the job handling mode. /// </summary> public JobHandlerModes JobHandlingMode { get; set; } @@ -1122,6 +1143,76 @@ namespace Tango.Integration.Operation } } + /// <summary> + /// Called when the printing has been started. + /// </summary> + /// <param name="handler">The handler.</param> + /// <param name="job">The job.</param> + protected virtual void OnPrintingStarted(JobHandler handler, Job job) + { + PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, job) + { + LiquidQuantities = _currentJobLiquidQuantities.ToList(), + }); + } + + /// <summary> + /// Called when the printing has been completed. + /// </summary> + /// <param name="handler">The handler.</param> + /// <param name="job">The job.</param> + protected virtual void OnPrintingCompleted(JobHandler handler, Job job) + { + PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, job) + { + LiquidQuantities = _currentJobLiquidQuantities.ToList(), + }); + + OnPrintingEnded(handler, job); + } + + /// <summary> + /// Called when the printing has been failed. + /// </summary> + /// <param name="handler">The handler.</param> + /// <param name="job">The job.</param> + /// <param name="exception">The exception.</param> + protected virtual void OnPrintingFailed(JobHandler handler, Job job, Exception exception) + { + PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, job, exception) + { + LiquidQuantities = _currentJobLiquidQuantities.ToList(), + }); + OnPrintingEnded(handler, job); + } + + /// <summary> + /// Called when the printing has been aborted. + /// </summary> + /// <param name="handler">The handler.</param> + /// <param name="job">The job.</param> + protected virtual void OnPrintingAborted(JobHandler handler, Job job) + { + PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, job) + { + LiquidQuantities = _currentJobLiquidQuantities.ToList(), + }); + OnPrintingEnded(handler, job); + } + + /// <summary> + /// Called when the printing has been ended. + /// </summary> + /// <param name="handler">The handler.</param> + /// <param name="job">The job.</param> + 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<ConnectRequest, ConnectResponse>(request); + + SessionLogger.CreateSession(); + LogResponseReceived(response.Message); _isPowerDownRequestInProgress = false; @@ -1293,8 +1389,7 @@ namespace Tango.Integration.Operation try { var result = await SendRequest<AbortJobRequest, AbortJobResponse>(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<BL.ValueObjects.JobRunLiquidQuantity>(); + 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<AbortJobRequest, AbortJobResponse>(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<StubAbortJobRequest, StubAbortJobResponse>(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<JobRunLiquidQuantity> LiquidQuantities { get; set; } public PrintingEventArgs(JobHandler jobHandler, Job job) { + LiquidQuantities = new List<JobRunLiquidQuantity>(); JobHandler = jobHandler; Job = job; } |
