diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-03-14 13:25:32 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-03-14 13:25:32 +0200 |
| commit | c5cde62cecfdd413e9902b26b30b0d4dfd05a24d (patch) | |
| tree | bc6cd0fc62c13bc65bcb1eeebfac4f5d6112f7ae /Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs | |
| parent | 81d88a18ac614604befb041a81781ab33eb08067 (diff) | |
| download | Tango-c5cde62cecfdd413e9902b26b30b0d4dfd05a24d.tar.gz Tango-c5cde62cecfdd413e9902b26b30b0d4dfd05a24d.zip | |
Machine Studio v4.0.10
PPC v1.0.9
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs | 579 |
1 files changed, 307 insertions, 272 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 520b06626..ba9d21451 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -88,6 +88,7 @@ namespace Tango.Integration.Operation EnableJobResume = true; LogEmbeddedDebuggingToFile = true; FirmwareUpgradeMode = FirmwareUpgradeModes.DFU | FirmwareUpgradeModes.TFP_PACKAGE; + GradientGenerationConfiguration = new DefaultGradientGenerationConfiguration(); } /// <summary> @@ -144,6 +145,11 @@ namespace Tango.Integration.Operation public event EventHandler<IMessage> ResponseReceived; /// <summary> + /// Reports about the job printing preparation progress. + /// </summary> + public event EventHandler<PreparingJobProgressEventArgs> PreparingJobProgress; + + /// <summary> /// Occurs when a printing process has started. /// </summary> public event EventHandler<PrintingEventArgs> PrintingStarted; @@ -378,6 +384,16 @@ namespace Tango.Integration.Operation set { _deviceInformation = value; RaisePropertyChangedAuto(); } } + private IGradientGenerationConfiguration _gradientGenerationConfiguration; + /// <summary> + /// Gets or sets the gradients generation configuration. + /// </summary> + public IGradientGenerationConfiguration GradientGenerationConfiguration + { + get { return _gradientGenerationConfiguration; } + set { _gradientGenerationConfiguration = value; RaisePropertyChangedAuto(); } + } + #endregion #region Virtual Methods @@ -933,7 +949,17 @@ namespace Tango.Integration.Operation jobSegment.Length = segment.LengthWithFactor; jobSegment.Name = segment.Name; - foreach (var stop in segment.BrushStops) + var stops = segment.BrushStops.ToList(); + + if (GradientGenerationConfiguration != null && GradientGenerationConfiguration.IsEnabled) + { + GradientGenerationConfiguration.Generate(segment, processParameters, (e) => + { + PreparingJobProgress?.Invoke(this, e); + }); + } + + foreach (var stop in stops) { JobBrushStop jobStop = new JobBrushStop(); jobStop.Index = stop.StopIndex; @@ -1073,7 +1099,7 @@ namespace Tango.Integration.Operation /// </summary> /// <param name="job">The job.</param> /// <returns></returns> - public JobHandler Print(Job job) + public Task<JobHandler> Print(Job job) { //Check not brush stop has color space 'Volume'. if (job.Segments.SelectMany(x => x.BrushStops).ToList().Exists(x => x.ColorSpace.Code == ColorSpaces.Volume.ToInt32())) @@ -1217,181 +1243,185 @@ namespace Tango.Integration.Operation /// <param name="job">The job.</param> /// <param name="processParameters">Process parameters table</param> /// <returns></returns> - public JobHandler Print(Job job, ProcessParametersTable processParameters) + public Task<JobHandler> Print(Job job, ProcessParametersTable processParameters) { - if (Status != MachineStatuses.ReadyToDye) + return Task.Factory.StartNew(() => { - throw new InvalidOperationException("Could not print while status = " + Status); - } + if (Status != MachineStatuses.ReadyToDye) + { + throw new InvalidOperationException("Could not print while status = " + Status); + } - RunningJob = null; - RunningJobStatus = null; + RunningJob = null; + RunningJobStatus = null; - var originalJob = job; + var originalJob = job; - CurrentProcessParameters = processParameters; + CurrentProcessParameters = processParameters; - JobRequest request = new JobRequest(); + JobRequest request = new JobRequest(); - if (job.NumberOfUnits < 1) - { - job.NumberOfUnits = 1; - } + if (job.NumberOfUnits < 1) + { + job.NumberOfUnits = 1; + } - job = job.Clone(); + job = job.Clone(); - int max = job.OrderedSegments.Last().SegmentIndex; + int max = job.OrderedSegments.Last().SegmentIndex; - var segments = job.OrderedSegments.ToList(); + var segments = job.OrderedSegments.ToList(); - for (int i = 0; i < job.NumberOfUnits - 1; i++) - { - foreach (var s in segments) + for (int i = 0; i < job.NumberOfUnits - 1; i++) { - var cloned = s.Clone(job); - cloned.SegmentIndex = max++; - job.Segments.Add(cloned); + foreach (var s in segments) + { + var cloned = s.Clone(job); + cloned.SegmentIndex = max++; + job.Segments.Add(cloned); + } } - } - JobTicket ticket = new JobTicket(); - ticket.Guid = originalJob.Guid; - ticket.EnableInterSegment = job.EnableInterSegment; - ticket.InterSegmentLength = job.InterSegmentLength; - ticket.EnableLubrication = job.EnableLubrication; - ticket.Length = job.Length; - ticket.WindingMethod = (JobWindingMethod)job.WindingMethod.Code; - ticket.Spool = new JobSpool(); + JobTicket ticket = new JobTicket(); + ticket.Guid = originalJob.Guid; + ticket.EnableInterSegment = job.EnableInterSegment; + ticket.InterSegmentLength = job.InterSegmentLength; + ticket.EnableLubrication = job.EnableLubrication; + ticket.Length = job.Length; + ticket.WindingMethod = (JobWindingMethod)job.WindingMethod.Code; + ticket.Spool = new JobSpool(); - job.SpoolType.MapPrimitivesTo(ticket.Spool); + job.SpoolType.MapPrimitivesTo(ticket.Spool); - var spool = job.Machine.Spools.SingleOrDefault(x => x.SpoolType == job.SpoolType); + var spool = job.Machine.Spools.SingleOrDefault(x => x.SpoolType == job.SpoolType); - if (spool == null) - { - throw new InvalidOperationException("Job spool type is not registered with this machine."); - } - else - { - spool.MapPrimitivesTo(ticket.Spool); - } + if (spool == null) + { + throw new InvalidOperationException("Job spool type is not registered with this machine."); + } + else + { + spool.MapPrimitivesTo(ticket.Spool); + } - ticket.Spool.JobSpoolType = (JobSpoolType)job.SpoolType.Code; + ticket.Spool.JobSpoolType = (JobSpoolType)job.SpoolType.Code; - ProcessParameters process = new ProcessParameters(); - processParameters.MapPrimitivesTo(process); - ticket.ProcessParameters = process; + ProcessParameters process = new ProcessParameters(); + processParameters.MapPrimitivesTo(process); + ticket.ProcessParameters = process; - foreach (var segment in job.OrderedSegments) - { - ticket.Segments.Add(CreatePMRJobSegment(segment, job, processParameters)); - } + foreach (var segment in job.OrderedSegments) + { + ticket.Segments.Add(CreatePMRJobSegment(segment, job, processParameters)); + } - request.JobTicket = ticket.Clone(); + request.JobTicket = ticket.Clone(); - JobHandler handler = null; + JobHandler handler = null; - handler = new JobHandler(async () => - { - try - { - var result = await SendRequest<AbortJobRequest, AbortJobResponse>(new AbortJobRequest()); - PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - handler.RaiseCanceled(); - } - catch (Exception ex) + handler = new JobHandler(async () => { - LogManager.Log(ex, "Failed to cancel job."); - } - }, originalJob, ticket, processParameters, JobHandlingMode); + try + { + var result = await SendRequest<AbortJobRequest, AbortJobResponse>(new AbortJobRequest()); + PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseCanceled(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Failed to cancel job."); + } + }, originalJob, ticket, processParameters, JobHandlingMode); - handler.StatusChanged += (x, s) => - { - RunningJobStatus = s; - }; + handler.StatusChanged += (x, s) => + { + RunningJobStatus = s; + }; - if (!job.IsAllSegmentsPerSpool) - { - ContinueSingleSpoolJob(job.OrderedSegments.First(), job, processParameters, handler); - return handler; - } + if (!job.IsAllSegmentsPerSpool) + { + ContinueSingleSpoolJob(job.OrderedSegments.First(), job, processParameters, handler); + return handler; + } - request.JobTicket.UploadStrategy = JobUploadStrategy; + request.JobTicket.UploadStrategy = JobUploadStrategy; - ThreadFactory.StartNew(async () => - { - if (JobUploadStrategy == JobUploadStrategy.JobDescriptionFile) + ThreadFactory.StartNew(async () => { - request.JobTicket.Segments.Clear(); - - JobDescriptionFile jobDescriptionFile = new JobDescriptionFile(ticket.Segments); - MemoryStream ms = jobDescriptionFile.ToStream(); + if (JobUploadStrategy == JobUploadStrategy.JobDescriptionFile) + { + request.JobTicket.Segments.Clear(); - var storage = CreateStorageManager(); + JobDescriptionFile jobDescriptionFile = new JobDescriptionFile(ticket.Segments); + MemoryStream ms = jobDescriptionFile.ToStream(); - var storageInfo = await storage.GetStorageDrive(); - var root_folder = await storage.GetRootFolder(); + var storage = CreateStorageManager(); - var existing_item = root_folder.Items.SingleOrDefault(x => x.Name == JOB_DESCRIPTION_FILE_NAME); - if (existing_item != null) - { - await storage.DeleteItem(existing_item); - } + var storageInfo = await storage.GetStorageDrive(); + var root_folder = await storage.GetRootFolder(); - String job_file_path = Path.Combine(storageInfo.Root, JOB_DESCRIPTION_FILE_NAME); + var existing_item = root_folder.Items.SingleOrDefault(x => x.Name == JOB_DESCRIPTION_FILE_NAME); + if (existing_item != null) + { + await storage.DeleteItem(existing_item); + } - await storage.UploadFileSync(job_file_path, ms); + String job_file_path = Path.Combine(storageInfo.Root, JOB_DESCRIPTION_FILE_NAME); - ms.Dispose(); + await storage.UploadFileSync(job_file_path, ms); - request.JobTicket.JobDescriptionFile = job_file_path; - } + ms.Dispose(); - LogRequestSent(request); - bool responseLogged = false; + request.JobTicket.JobDescriptionFile = job_file_path; + } - Status = MachineStatuses.Printing; - RunningJob = originalJob; - PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + LogRequestSent(request); + bool responseLogged = false; - SendContinuousRequest<JobRequest, JobResponse>(request, null, TimeSpan.FromSeconds(2)).Subscribe((response) => - { - handler.RaiseStatusReceived(response.Message.Status); + Status = MachineStatuses.Printing; + RunningJob = originalJob; + PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - if (!responseLogged) + SendContinuousRequest<JobRequest, JobResponse>(request, null, TimeSpan.FromSeconds(2)).Subscribe((response) => { - responseLogged = true; - LogResponseReceived(response.Message); - } - }, (ex) => - { - if (!(ex is ContinuousResponseAbortedException)) + handler.RaiseStatusReceived(response.Message.Status); + + if (!responseLogged) + { + responseLogged = true; + LogResponseReceived(response.Message); + } + }, (ex) => { - Status = MachineStatuses.ReadyToDye; + if (!(ex is ContinuousResponseAbortedException)) + { + Status = MachineStatuses.ReadyToDye; - if (!handler.IsCanceled) + if (!handler.IsCanceled) + { + PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, originalJob, ex)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseFailed(ex); + LogRequestFailed(request, ex); + } + } + else { - PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, originalJob, ex)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - handler.RaiseFailed(ex); - LogRequestFailed(request, ex); + Status = MachineStatuses.ReadyToDye; } - } - else + }, () => { Status = MachineStatuses.ReadyToDye; - } - }, () => - { - Status = MachineStatuses.ReadyToDye; - PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - handler.RaiseCompleted(); + PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseCompleted(); + }); }); - }); - return handler; + return handler; + + }); } /// <summary> @@ -1415,204 +1445,209 @@ namespace Tango.Integration.Operation /// or /// Liquid volume not found for color conversion output liquid '" + outputLiquid.LiquidType + "'. /// </exception> - public JobHandler PrintStub(Job job) + public Task<JobHandler> PrintStub(Job job) { - //Check not brush stop has color space 'Volume'. - if (job.Segments.SelectMany(x => x.BrushStops).ToList().Exists(x => x.ColorSpace.Code == ColorSpaces.Volume.ToInt32())) + return Task.Factory.StartNew<JobHandler>(() => { - throw new InvalidOperationException("Cannot print a brush stop with volume color space when process parameters table has not been specified."); - } - //Get least common process parameters table index. - int processParametersTableIndex = 0; + //Check not brush stop has color space 'Volume'. + if (job.Segments.SelectMany(x => x.BrushStops).ToList().Exists(x => x.ColorSpace.Code == ColorSpaces.Volume.ToInt32())) + { + throw new InvalidOperationException("Cannot print a brush stop with volume color space when process parameters table has not been specified."); + } - if (job.Rml == null) - { - throw new NullReferenceException("Job RML is null"); - } + //Get least common process parameters table index. + int processParametersTableIndex = 0; - var processGroup = job.Rml.ProcessParametersTablesGroups.FirstOrDefault(x => x.Active); + if (job.Rml == null) + { + throw new NullReferenceException("Job RML is null"); + } - if (processGroup == null) - { - throw new NullReferenceException("Could not locate an active process parameters tables group for RML " + job.Rml.Name); - } + var processGroup = job.Rml.ProcessParametersTablesGroups.FirstOrDefault(x => x.Active); - var processParameters = processGroup.ProcessParametersTables.FirstOrDefault(x => x.TableIndex == processParametersTableIndex); + if (processGroup == null) + { + throw new NullReferenceException("Could not locate an active process parameters tables group for RML " + job.Rml.Name); + } - if (processParameters == null) - { - throw new NullReferenceException("Could not locate process parameters table index " + processParametersTableIndex + " in group " + processGroup.Name + " for RML " + job.Rml.Name); - } + var processParameters = processGroup.ProcessParametersTables.FirstOrDefault(x => x.TableIndex == processParametersTableIndex); - //Perform color correction - foreach (var stop in job.Segments.SelectMany(x => x.BrushStops)) - { - if (stop.LiquidVolumes == null) + if (processParameters == null) { - stop.SetLiquidVolumes(job.Machine.Configuration, job.Rml, processParameters); + throw new NullReferenceException("Could not locate process parameters table index " + processParametersTableIndex + " in group " + processGroup.Name + " for RML " + job.Rml.Name); } - foreach (var liquidVolume in stop.LiquidVolumes) + //Perform color correction + foreach (var stop in job.Segments.SelectMany(x => x.BrushStops)) { - liquidVolume.Volume = 10; + if (stop.LiquidVolumes == null) + { + stop.SetLiquidVolumes(job.Machine.Configuration, job.Rml, processParameters); + } + + foreach (var liquidVolume in stop.LiquidVolumes) + { + liquidVolume.Volume = 10; + } } - } - if (Status != MachineStatuses.ReadyToDye) - { - throw new InvalidOperationException("Could not print while status = " + Status); - } + if (Status != MachineStatuses.ReadyToDye) + { + throw new InvalidOperationException("Could not print while status = " + Status); + } - RunningJob = null; - RunningJobStatus = null; + RunningJob = null; + RunningJobStatus = null; - var originalJob = job; + var originalJob = job; - CurrentProcessParameters = processParameters; + CurrentProcessParameters = processParameters; - StubJobRequest request = new StubJobRequest(); + StubJobRequest request = new StubJobRequest(); - if (job.NumberOfUnits < 1) - { - job.NumberOfUnits = 1; - } + if (job.NumberOfUnits < 1) + { + job.NumberOfUnits = 1; + } - job = job.Clone(); + job = job.Clone(); - var segments = job.OrderedSegments.ToList(); + var segments = job.OrderedSegments.ToList(); - for (int i = 0; i < job.NumberOfUnits - 1; i++) - { - foreach (var s in segments) + for (int i = 0; i < job.NumberOfUnits - 1; i++) { - job.Segments.Add(s); + foreach (var s in segments) + { + job.Segments.Add(s); + } } - } - - JobTicket ticket = new JobTicket(); - ticket.Guid = originalJob.Guid; - ticket.EnableInterSegment = job.EnableInterSegment; - ticket.InterSegmentLength = job.InterSegmentLength; - ticket.Length = job.Length; - ticket.WindingMethod = (JobWindingMethod)job.WindingMethod.Code; - ticket.Spool = new JobSpool(); - job.SpoolType.MapPrimitivesTo(ticket.Spool); - ticket.Spool.JobSpoolType = (JobSpoolType)job.SpoolType.Code; + JobTicket ticket = new JobTicket(); + ticket.Guid = originalJob.Guid; + ticket.EnableInterSegment = job.EnableInterSegment; + ticket.InterSegmentLength = job.InterSegmentLength; + ticket.Length = job.Length; + ticket.WindingMethod = (JobWindingMethod)job.WindingMethod.Code; + ticket.Spool = new JobSpool(); - ProcessParameters process = new ProcessParameters(); - processParameters.MapPrimitivesTo(process); - ticket.ProcessParameters = process; + job.SpoolType.MapPrimitivesTo(ticket.Spool); + ticket.Spool.JobSpoolType = (JobSpoolType)job.SpoolType.Code; - foreach (var segment in job.OrderedSegments) - { - JobSegment jobSegment = new JobSegment(); - jobSegment.Length = segment.LengthWithFactor; - jobSegment.Name = segment.Name; + ProcessParameters process = new ProcessParameters(); + processParameters.MapPrimitivesTo(process); + ticket.ProcessParameters = process; - foreach (var stop in segment.BrushStops) + foreach (var segment in job.OrderedSegments) { - JobBrushStop jobStop = new JobBrushStop(); - jobStop.Index = stop.StopIndex; - jobStop.OffsetPercent = stop.OffsetPercent; - jobStop.OffsetMeters = stop.OffsetMeters; + JobSegment jobSegment = new JobSegment(); + jobSegment.Length = segment.LengthWithFactor; + jobSegment.Name = segment.Name; - if (stop.LiquidVolumes == null) + foreach (var stop in segment.BrushStops) { - stop.SetLiquidVolumes(job.Machine.Configuration, job.Rml, processParameters); - } + JobBrushStop jobStop = new JobBrushStop(); + jobStop.Index = stop.StopIndex; + jobStop.OffsetPercent = stop.OffsetPercent; + jobStop.OffsetMeters = stop.OffsetMeters; - foreach (var liquidVolume in stop.LiquidVolumes) - { - JobDispenser dispenser = new JobDispenser(); - dispenser.Index = liquidVolume.IdsPack.PackIndex; - dispenser.Volume = liquidVolume.Volume; - dispenser.DispenserLiquidType = (DispenserLiquidType)liquidVolume.IdsPack.LiquidType.Code; - dispenser.DispenserStepDivision = (DispenserStepDivision)liquidVolume.DispenserStepDivision; + if (stop.LiquidVolumes == null) + { + stop.SetLiquidVolumes(job.Machine.Configuration, job.Rml, processParameters); + } - dispenser.NanoliterPerPulse = liquidVolume.IdsPack.Dispenser.NlPerPulse; + foreach (var liquidVolume in stop.LiquidVolumes) + { + JobDispenser dispenser = new JobDispenser(); + dispenser.Index = liquidVolume.IdsPack.PackIndex; + dispenser.Volume = liquidVolume.Volume; + dispenser.DispenserLiquidType = (DispenserLiquidType)liquidVolume.IdsPack.LiquidType.Code; + dispenser.DispenserStepDivision = (DispenserStepDivision)liquidVolume.DispenserStepDivision; + + dispenser.NanoliterPerPulse = liquidVolume.IdsPack.Dispenser.NlPerPulse; - dispenser.LiquidMaxNanoliterPerCentimeter = liquidVolume.LiquidMaxNanoliterPerCentimeter; - dispenser.NanoliterPerCentimeter = liquidVolume.NanoliterPerCentimeter; - dispenser.NanolitterPerSecond = liquidVolume.NanoliterPerSecond; - dispenser.PulsePerSecond = liquidVolume.PulsePerSecond; + dispenser.LiquidMaxNanoliterPerCentimeter = liquidVolume.LiquidMaxNanoliterPerCentimeter; + dispenser.NanoliterPerCentimeter = liquidVolume.NanoliterPerCentimeter; + dispenser.NanolitterPerSecond = liquidVolume.NanoliterPerSecond; + dispenser.PulsePerSecond = liquidVolume.PulsePerSecond; - jobStop.Dispensers.Add(dispenser); + jobStop.Dispensers.Add(dispenser); + } + + jobSegment.BrushStops.Add(jobStop); } - jobSegment.BrushStops.Add(jobStop); + ticket.Segments.Add(jobSegment); } - ticket.Segments.Add(jobSegment); - } + request.JobTicket = ticket; - request.JobTicket = ticket; - - JobHandler handler = null; + JobHandler handler = null; - handler = new JobHandler(async () => - { - try + handler = new JobHandler(async () => { - var result = await SendRequest<StubAbortJobRequest, StubAbortJobResponse>(new StubAbortJobRequest()); - PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - handler.RaiseCanceled(); - } - catch (Exception ex) - { - LogManager.Log(ex, "Failed to cancel job."); - } - }, originalJob, ticket, processParameters, JobHandlingMode); - - handler.StatusChanged += (x, s) => - { - RunningJobStatus = s; - }; + try + { + var result = await SendRequest<StubAbortJobRequest, StubAbortJobResponse>(new StubAbortJobRequest()); + PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseCanceled(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Failed to cancel job."); + } + }, originalJob, ticket, processParameters, JobHandlingMode); - LogRequestSent(request); - bool responseLogged = false; + handler.StatusChanged += (x, s) => + { + RunningJobStatus = s; + }; - SendContinuousRequest<StubJobRequest, StubJobResponse>(request, null, TimeSpan.FromSeconds(2)).Subscribe((response) => - { - handler.RaiseStatusReceived(response.Message.Status); + LogRequestSent(request); + bool responseLogged = false; - if (!responseLogged) + SendContinuousRequest<StubJobRequest, StubJobResponse>(request, null, TimeSpan.FromSeconds(2)).Subscribe((response) => { - responseLogged = true; - Status = MachineStatuses.Printing; - RunningJob = originalJob; - PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - LogResponseReceived(response.Message); - } - }, (ex) => - { - if (!(ex is ContinuousResponseAbortedException)) + 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) => { - Status = MachineStatuses.ReadyToDye; + if (!(ex is ContinuousResponseAbortedException)) + { + Status = MachineStatuses.ReadyToDye; - if (!handler.IsCanceled) + if (!handler.IsCanceled) + { + PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, originalJob, ex)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseFailed(ex); + LogRequestFailed(request, ex); + } + } + else { - PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, originalJob, ex)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - handler.RaiseFailed(ex); - LogRequestFailed(request, ex); + Status = MachineStatuses.ReadyToDye; } - } - else + }, () => { Status = MachineStatuses.ReadyToDye; - } - }, () => - { - Status = MachineStatuses.ReadyToDye; - PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - handler.RaiseCompleted(); - }); + PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseCompleted(); + }); + + return handler; - return handler; + }); } /// <summary> |
