diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-01-21 18:48:44 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-01-21 18:48:44 +0200 |
| commit | a8b092b3d28c44beff66c6d17ece06103291eaff (patch) | |
| tree | 23a42257d3791957576b9da7873a22b6ced79259 /Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs | |
| parent | edb3800ebc5baee6728dbcc5154a6d7a28a9c5eb (diff) | |
| download | Tango-a8b092b3d28c44beff66c6d17ece06103291eaff.tar.gz Tango-a8b092b3d28c44beff66c6d17ece06103291eaff.zip | |
Refactored JobRunsLogger to save job length, name, source and JobString.
Fixed issue with machine emulator number of units.
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs | 166 |
1 files changed, 49 insertions, 117 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs index 78cc9a284..ce175e3d2 100644 --- a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs +++ b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs @@ -76,31 +76,7 @@ namespace Tango.Integration.JobRuns return IsStarted && _job != null && JobDesignation.HasFlag(_job.Designation); } - #endregion - - #region Public Methods - - /// <summary> - /// Starts the logger. - /// </summary> - public void Start() - { - IsStarted = true; - } - - /// <summary> - /// Stops the logger. - /// </summary> - public void Stop() - { - IsStarted = false; - } - - #endregion - - #region Event Handlers - - private void Machine_PrintingFailed(object sender, PrintingFailedEventArgs e) + private void InsertJobRun(PrintingEventArgs e, JobRunStatus status, Exception exception) { if (ShouldLog()) { @@ -112,64 +88,27 @@ namespace Tango.Integration.JobRuns { using (var db = ObservablesContext.CreateDefault()) { - db.JobRuns.Add(new JobRun() - { - StartDate = _start_date, - EndDate = DateTime.UtcNow, - JobGuid = _job.Guid, - MachineGuid = _job.MachineGuid, - JobRunStatus = JobRunStatus.Failed, - EndPosition = e.JobHandler.Status.Progress, - FailedMessage = e.Exception.Message, - JobLength = e.JobHandler.Status.TotalProgress, - LiquidQuantities = e.LiquidQuantities, - }); - - e.Job.LastRun = DateTime.UtcNow; - _job.LastRun = DateTime.UtcNow; + JobRun run = new JobRun(); - var job = db.Jobs.SingleOrDefault(x => x.Guid == _job.Guid); + run.StartDate = _start_date; + run.EndDate = DateTime.UtcNow; + run.JobName = _job.Name; + run.JobLength = _job.LengthIncludingNumberOfUnits; + run.JobSource = _job.Source; + run.JobGuid = _job.Guid; + run.MachineGuid = _job.MachineGuid; + run.JobRunStatus = status; + run.EndPosition = e.JobHandler.Status.Progress; + run.JobLength = e.JobHandler.Status.TotalProgress; + run.LiquidQuantities = e.LiquidQuantities; + run.JobString = _job.ToJobFileWhenLoaded().ToString(); - if (job != null) + if (exception != null) { - job.LastRun = DateTime.UtcNow; + run.FailedMessage = exception.FlattenMessage(); } - db.SaveChanges(); - } - } - catch (Exception ex) - { - LogManager.Log(ex, "Error logging the current job run to the database."); - } - }); - } - } - } - - private void Machine_PrintingAborted(object sender, PrintingEventArgs e) - { - if (ShouldLog()) - { - if (e.Job.Guid == _job.Guid) - { - Task.Factory.StartNew(() => - { - try - { - using (var db = ObservablesContext.CreateDefault()) - { - db.JobRuns.Add(new JobRun() - { - StartDate = _start_date, - EndDate = DateTime.UtcNow, - JobGuid = _job.Guid, - MachineGuid = _job.MachineGuid, - EndPosition = e.JobHandler.Status.Progress, - JobRunStatus = JobRunStatus.Aborted, - JobLength = e.JobHandler.Status.TotalProgress, - LiquidQuantities = e.LiquidQuantities, - }); + db.JobRuns.Add(run); e.Job.LastRun = DateTime.UtcNow; _job.LastRun = DateTime.UtcNow; @@ -193,50 +132,43 @@ namespace Tango.Integration.JobRuns } } - private void Machine_PrintingCompleted(object sender, PrintingEventArgs e) + #endregion + + #region Public Methods + + /// <summary> + /// Starts the logger. + /// </summary> + public void Start() { - if (ShouldLog()) - { - if (e.Job.Guid == _job.Guid) - { - Task.Factory.StartNew(() => - { - try - { - using (var db = ObservablesContext.CreateDefault()) - { - db.JobRuns.Add(new JobRun() - { - StartDate = _start_date, - EndDate = DateTime.UtcNow, - JobGuid = _job.Guid, - MachineGuid = _job.MachineGuid, - EndPosition = e.JobHandler.Status.Progress, - JobRunStatus = JobRunStatus.Completed, - JobLength = e.JobHandler.Status.TotalProgress, - LiquidQuantities = e.LiquidQuantities, - }); + IsStarted = true; + } - e.Job.LastRun = DateTime.UtcNow; - _job.LastRun = DateTime.UtcNow; + /// <summary> + /// Stops the logger. + /// </summary> + public void Stop() + { + IsStarted = false; + } - var job = db.Jobs.SingleOrDefault(x => x.Guid == _job.Guid); + #endregion - if (job != null) - { - job.LastRun = DateTime.UtcNow; - } + #region Event Handlers - db.SaveChanges(); - } - } - catch (Exception ex) - { - LogManager.Log(ex, "Error logging the current job run to the database."); - } - }); - } - } + private void Machine_PrintingFailed(object sender, PrintingFailedEventArgs e) + { + InsertJobRun(e, JobRunStatus.Failed, e.Exception); + } + + private void Machine_PrintingAborted(object sender, PrintingEventArgs e) + { + InsertJobRun(e, JobRunStatus.Aborted, null); + } + + private void Machine_PrintingCompleted(object sender, PrintingEventArgs e) + { + InsertJobRun(e, JobRunStatus.Completed, null); } private void Machine_PrintingStarted(object sender, PrintingEventArgs e) |
