diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/DefaultJobResumeManager.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/DefaultJobResumeManager.cs | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/DefaultJobResumeManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/DefaultJobResumeManager.cs new file mode 100644 index 000000000..5f819d34d --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/DefaultJobResumeManager.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Core.DI; +using Tango.Integration.Operation; +using Tango.PPC.Common.Build; +using Tango.PPC.Common.Connection; + +namespace Tango.PPC.Common.Resume +{ + public class DefaultJobResumeManager : ExtendedObject, IJobResumeManager + { + private IMachineProvider _machineProvider; + private IBuildProvider _buildProvider; + + public event EventHandler<JobResumeUpdatedEventArgs> JobResumeUpdated; + public event EventHandler<JobResumeDroppedEventArgs> JobResumeDropped; + + [TangoInject] + public DefaultJobResumeManager(IMachineProvider machineProvider,IBuildProvider buildProvider) + { + _machineProvider = machineProvider; + _buildProvider = buildProvider; + machineProvider.MachineOperator.PrintingEnded += MachineOperator_PrintingEnded; + } + + private void MachineOperator_PrintingEnded(object sender, PrintingEventArgs e) + { + if (_buildProvider.IsEureka) + { + UpdateJobResume(e); + } + } + + private void UpdateJobResume(PrintingEventArgs e) + { + try + { + if (!e.JobHandler.Status.IsCompleted) + { + if (e.JobHandler.JobStatus.Progress <= e.JobHandler.ProcessParameters.DryerBufferLengthMeters) return; + + var model = JobResumeDB.Default.Get(e.Job.Guid); + bool insert = false; + if (model == null) + { + model = new JobResumeModel(); + insert = true; + } + + model.JobGuid = e.Job.Guid; + model.FirstUnitStartPosition = e.JobHandler.Status.CurrentUnitProgress; + model.RemainingUnits = e.JobHandler.Status.RemainingUnits; + model.GlobalStartPosition = e.JobHandler.JobStatus.Progress; + + if (insert) + { + JobResumeDB.Default.Add(model); + } + else + { + JobResumeDB.Default.Update(model); + } + + JobResumeUpdated?.Invoke(this, new JobResumeUpdatedEventArgs() + { + JobGuid = e.Job.Guid, + ResumeModel = model + }); + } + else + { + JobResumeDB.Default.Delete(e.Job.Guid); + + JobResumeUpdated?.Invoke(this, new JobResumeUpdatedEventArgs() + { + JobGuid = e.Job.Guid, + ResumeModel = null + }); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error inserting/updating job resume info on db."); + } + } + + public JobResumeModel GetJobResumeModel(string jobGuid) + { + return JobResumeDB.Default.Get(jobGuid); + } + + public void DropResume(string jobGuid) + { + JobResumeDB.Default.Delete(jobGuid); + + JobResumeDropped?.Invoke(this, new JobResumeDroppedEventArgs() { JobGuid = jobGuid }); + } + } +} |
