aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2020-01-21 18:48:44 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2020-01-21 18:48:44 +0200
commita8b092b3d28c44beff66c6d17ece06103291eaff (patch)
tree23a42257d3791957576b9da7873a22b6ced79259 /Software/Visual_Studio
parentedb3800ebc5baee6728dbcc5154a6d7a28a9c5eb (diff)
downloadTango-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')
-rw-r--r--Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs2
-rw-r--r--Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs166
2 files changed, 50 insertions, 118 deletions
diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs
index 06a287693..0c06448e1 100644
--- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs
+++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs
@@ -704,7 +704,7 @@ namespace Tango.Emulations.Emulators
List<JobBrushStop> calculatedStops = new List<JobBrushStop>();
- for (int i = 0; i < job.NumberOfUnits; i++)
+ for (int i = 0; i < units; i++)
{
double progress = 0;
double lastProgress = 0;
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)