aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-10-24 16:18:39 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-10-24 16:18:39 +0300
commit1e24679bf65e42e5df96113bd1eef371036f0940 (patch)
treebb954219f7f5ec0f6e37631cae2c6aa0ac9d184b /Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
parenta4f4b3be2917b13667217cf826c21e8bd644a8c4 (diff)
downloadTango-1e24679bf65e42e5df96113bd1eef371036f0940.tar.gz
Tango-1e24679bf65e42e5df96113bd1eef371036f0940.zip
Implemented job resume!!
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs')
-rw-r--r--Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs141
1 files changed, 141 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
index 8098f755d..d098d9bb9 100644
--- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
+++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
@@ -70,6 +70,7 @@ namespace Tango.Integration.Operation
DeviceInformation = new DeviceInformation();
MachineEventsStateProvider = new DefaultMachineEventsStateProvider();
EnableEventsNotification = true;
+ EnableJobResume = true;
LogEmbeddedDebuggingToFile = true;
}
@@ -146,6 +147,11 @@ namespace Tango.Integration.Operation
/// </summary>
public event EventHandler<PrintingEventArgs> PrintingAborted;
+ /// <summary>
+ /// Occurs when the machine operator has detected that a job is in progress after connecting to the machine.
+ /// </summary>
+ public event EventHandler<ResumingJobEventArgs> ResumingJob;
+
#endregion
#region Properties
@@ -279,6 +285,22 @@ namespace Tango.Integration.Operation
}
}
+ private bool _enableJobResume;
+ /// <summary>
+ /// Gets or sets a value indicating whether to check whether a job is in progress after connection was successful.
+ /// </summary>
+ public bool EnableJobResume
+ {
+ get
+ {
+ return _enableJobResume;
+ }
+ set
+ {
+ _enableJobResume = value; RaisePropertyChangedAuto();
+ }
+ }
+
private bool _logEmbeddedDebuggingToFile;
/// <summary>
/// Gets or sets a value indicating whether to automatically save incoming log data from the embedded device.
@@ -673,6 +695,11 @@ namespace Tango.Integration.Operation
OnEnableDiagnosticsChanged(EnableDiagnostics);
OnEnableEmbeddedDebuggingChanged(EnableEmbeddedDebugging);
OnEnableEventsNotification(EnableEventsNotification);
+
+ if (EnableJobResume)
+ {
+ ResumeJob();
+ }
}
catch (Exception ex)
{
@@ -796,6 +823,7 @@ namespace Tango.Integration.Operation
}
JobTicket ticket = new JobTicket();
+ ticket.Guid = originalJob.Guid;
ticket.EnableInterSegment = job.EnableInterSegment;
ticket.InterSegmentLength = job.InterSegmentLength;
ticket.Length = job.Length;
@@ -1345,6 +1373,119 @@ namespace Tango.Integration.Operation
#region Private Methods
+ private async void ResumeJob()
+ {
+ LogManager.Log("Checking is a job is in progress...");
+ var res = await SendRequest<CurrentJobRequest, CurrentJobResponse>(new CurrentJobRequest());
+ if (res.Message.IsJobInProgress)
+ {
+ JobTicket jobTicket = res.Message.JobTicket;
+
+ ProcessParametersTable processParameters = new ProcessParametersTable();
+ jobTicket.ProcessParameters.MapPrimitivesTo(processParameters);
+
+ ResumingJobEventArgs args = new ResumingJobEventArgs((job) =>
+ {
+ if (Status != MachineStatuses.ReadyToDye)
+ {
+ throw new InvalidOperationException("Could not print while status = " + Status);
+ }
+
+ RunningJob = null;
+ RunningJobStatus = null;
+
+ var originalJob = job;
+
+ CurrentProcessParameters = processParameters;
+
+ if (job.NumberOfUnits < 1)
+ {
+ job.NumberOfUnits = 1;
+ }
+
+ job = job.Clone();
+
+ var segments = job.Segments.ToList();
+
+ for (int i = 0; i < job.NumberOfUnits - 1; i++)
+ {
+ foreach (var s in segments)
+ {
+ job.Segments.Add(s);
+ }
+ }
+
+ var request = new ResumeCurrentJobRequest();
+
+ JobHandler handler = null;
+
+ handler = new JobHandler(async () =>
+ {
+ try
+ {
+ var result = await SendRequest<AbortJobRequest, AbortJobResponse>(new AbortJobRequest());
+ PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, originalJob));
+ handler.RaiseCanceled();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Failed to cancel job.");
+ }
+ }, originalJob, processParameters, JobHandlingMode);
+
+ handler.StatusChanged += (x, s) =>
+ {
+ RunningJobStatus = s;
+ };
+
+ LogRequestSent(request);
+
+ bool responseLogged = false;
+
+ SendContinuousRequest<ResumeCurrentJobRequest, ResumeCurrentJobResponse>(request, null, TimeSpan.FromSeconds(2)).Subscribe((response) =>
+ {
+ handler.RaiseStatusReceived(response.Message.Status);
+
+ if (!responseLogged)
+ {
+ responseLogged = true;
+ Status = MachineStatuses.Printing;
+ RunningJob = originalJob;
+ PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, originalJob));
+ LogResponseReceived(response.Message);
+ }
+ }, (ex) =>
+ {
+ if (!(ex is ContinuousResponseAbortedException))
+ {
+ Status = MachineStatuses.ReadyToDye;
+
+ if (!handler.IsCanceled)
+ {
+ PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, originalJob, ex));
+ handler.RaiseFailed(ex);
+ LogRequestFailed(request, ex);
+ }
+ }
+ else
+ {
+ Status = MachineStatuses.ReadyToDye;
+ }
+ }, () =>
+ {
+ Status = MachineStatuses.ReadyToDye;
+ PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, originalJob));
+ handler.RaiseCompleted();
+ });
+
+ return handler;
+ });
+
+ args.JobGuid = jobTicket.Guid;
+ ResumingJob?.Invoke(this, args);
+ }
+ }
+
/// <summary>
/// Logs the request sent.
/// </summary>