aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration/JobRuns
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
committerMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
commit00a491d93733d4625ad329b2ba8237f445364b3f (patch)
tree4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/Tango.Integration/JobRuns
parent124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff)
downloadTango-00a491d9.tar.gz
Tango-00a491d9.zip
merge
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/JobRuns')
-rw-r--r--Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs298
-rw-r--r--Software/Visual_Studio/Tango.Integration/JobRuns/IJobRunsLogger.cs14
2 files changed, 106 insertions, 206 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs
index 64ad60db5..bacae9324 100644
--- a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs
+++ b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs
@@ -4,7 +4,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
-using Tango.BL.Builders;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.Core;
@@ -18,8 +17,8 @@ namespace Tango.Integration.JobRuns
/// <seealso cref="Tango.Integration.JobRuns.IJobRunsLogger" />
public class BasicJobRunsLogger : ExtendedObject, IJobRunsLogger
{
+ private DateTime _start_date;
private Job _job;
- private Machine _defaultMachine;
#region Properties
@@ -36,12 +35,7 @@ namespace Tango.Integration.JobRuns
/// <summary>
/// Gets or sets the job designations of which the logger should log (supports multiple flags).
/// </summary>
- public JobDesignations JobDesignationFilter { get; set; }
-
- /// <summary>
- /// Gets or sets the job run source when logging job runs.
- /// </summary>
- public JobSource JobSource { get; set; }
+ public JobDesignations JobDesignation { get; set; }
#endregion
@@ -53,7 +47,7 @@ namespace Tango.Integration.JobRuns
/// <param name="machineOperator">The machine operator.</param>
public BasicJobRunsLogger(IMachineOperator machineOperator)
{
- JobDesignationFilter = JobDesignations.Default | JobDesignations.SampleDye | JobDesignations.FineTuning;
+ JobDesignation = JobDesignations.Default;
MachineOperator = machineOperator;
Init();
}
@@ -75,15 +69,38 @@ namespace Tango.Integration.JobRuns
MachineOperator.PrintingAborted += Machine_PrintingAborted;
MachineOperator.PrintingFailed -= Machine_PrintingFailed;
MachineOperator.PrintingFailed += Machine_PrintingFailed;
- MachineOperator.HeadCleaningEnded += MachineOperator_HeadCleaningEnded;
}
private bool ShouldLog()
{
- return IsStarted && _job != null && JobDesignationFilter.HasFlag(_job.Designation);
+ 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;
}
- private void InsertJobRun(PrintingEventArgs e, JobRunStatus status, Exception exception)
+ #endregion
+
+ #region Event Handlers
+
+ private void Machine_PrintingFailed(object sender, PrintingFailedEventArgs e)
{
if (ShouldLog())
{
@@ -95,65 +112,15 @@ namespace Tango.Integration.JobRuns
{
using (var db = ObservablesContext.CreateDefault())
{
- JobRun run = new JobRun();
-
- run.UserGuid = _job.UserGuid;
- run.StartDate = e.StartDate;
- run.UploadingStartDate = e.UploadingStartTime;
- run.HeatingStartDate = e.HeatingStartTime;
- run.ActualStartDate = e.ActualStartTime;
- run.EndDate = DateTime.UtcNow;
- run.JobName = _job.Name;
- run.Source = JobSource;
- run.Designation = _job.Designation;
- run.JobGuid = _job.Guid;
- run.RmlGuid = _job.RmlGuid;
- run.MachineGuid = _job.MachineGuid;
- run.JobRunStatus = status;
- run.EndPosition = e.JobHandler.Status.Progress;
- //run.JobLength = _job.LengthIncludingNumberOfUnits; //Should I use this or the below ??
- run.JobLength = e.JobHandler.Status.TotalProgress;
- run.LiquidQuantities = e.LiquidQuantities;
- run.IsGradient = _job.Segments.Any(x => x.BrushStops.Count > 1);
- run.GradientResolutionCm = MachineOperator.GradientGenerationConfiguration.ResolutionCM;
- run.JobString = _job.ToJobFileWhenLoaded().ToString();
-
- //Set individual liquid quantities
-
- //Cyan
- var cyan = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Cyan);
- run.CyanQuantity = cyan != null ? cyan.Quantity : 0;
-
- //Magenta
- var magenta = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Magenta);
- run.MagentaQuantity = magenta != null ? magenta.Quantity : 0;
-
- //Yellow
- var yellow = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Yellow);
- run.YellowQuantity = yellow != null ? yellow.Quantity : 0;
-
- //Black
- var black = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Black);
- run.BlackQuantity = black != null ? black.Quantity : 0;
-
- //TI
- var ti = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.TransparentInk);
- run.TransparentQuantity = ti != null ? ti.Quantity : 0;
-
- //Lubricant
- var lubricant = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Lubricant);
- run.LubricantQuantity = lubricant != null ? lubricant.Quantity : 0;
-
- //Cleaner
- var cleaner = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Cleaner);
- run.CleanerQuantity = cleaner != null ? cleaner.Quantity : 0;
-
- if (exception != null)
+ db.JobRuns.Add(new JobRun()
{
- run.FailedMessage = exception.FlattenMessage();
- }
-
- db.JobRuns.Add(run);
+ StartDate = _start_date,
+ EndDate = DateTime.UtcNow,
+ JobGuid = _job.Guid,
+ JobRunStatus = JobRunStatus.Failed,
+ EndPosition = e.JobHandler.Status.Progress,
+ FailedMessage = e.Exception.Message,
+ });
e.Job.LastRun = DateTime.UtcNow;
_job.LastRun = DateTime.UtcNow;
@@ -170,158 +137,103 @@ namespace Tango.Integration.JobRuns
}
catch (Exception ex)
{
- LogManager.Log(ex, "Error logging the last job run to the database.");
+ LogManager.Log(ex, "Error logging the current job run to the database.");
}
});
}
}
}
- private void InsertHeadCleaningJobRun(HeadCleaningEndedEventArgs e)
+ private void Machine_PrintingAborted(object sender, PrintingEventArgs e)
{
- if (IsStarted && _defaultMachine != null)
+ if (ShouldLog())
{
- Task.Factory.StartNew(() =>
+ if (e.Job.Guid == _job.Guid)
{
- try
+ Task.Factory.StartNew(() =>
{
- using (var db = ObservablesContext.CreateDefault())
+ try
{
- JobRun run = new JobRun();
-
- run.IsHeadCleaning = true;
- run.StartDate = e.StartDate;
- run.UploadingStartDate = e.StartDate;
- run.HeatingStartDate = e.StartDate;
- run.ActualStartDate = e.StartDate;
- run.EndDate = DateTime.UtcNow;
- run.JobName = "HEAD CLEANING";
- run.Source = JobSource;
- run.MachineGuid = _defaultMachine.Guid;
- run.JobRunStatus = e.Status;
- run.EndPosition = e.EndPosition;
- run.JobLength = e.Length;
- run.LiquidQuantities = e.LiquidQuantities;
-
- //Set individual liquid quantities
-
- //Cyan
- var cyan = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Cyan);
- run.CyanQuantity = cyan != null ? cyan.Quantity : 0;
-
- //Magenta
- var magenta = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Magenta);
- run.MagentaQuantity = magenta != null ? magenta.Quantity : 0;
-
- //Yellow
- var yellow = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Yellow);
- run.YellowQuantity = yellow != null ? yellow.Quantity : 0;
-
- //Black
- var black = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Black);
- run.BlackQuantity = black != null ? black.Quantity : 0;
-
- //TI
- var ti = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.TransparentInk);
- run.TransparentQuantity = ti != null ? ti.Quantity : 0;
-
- //Lubricant
- var lubricant = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Lubricant);
- run.LubricantQuantity = lubricant != null ? lubricant.Quantity : 0;
+ using (var db = ObservablesContext.CreateDefault())
+ {
+ db.JobRuns.Add(new JobRun()
+ {
+ StartDate = _start_date,
+ EndDate = DateTime.UtcNow,
+ JobGuid = _job.Guid,
+ EndPosition = e.JobHandler.Status.Progress,
+ JobRunStatus = JobRunStatus.Aborted,
+ });
- //Cleaner
- var cleaner = run.LiquidQuantities.SingleOrDefault(x => x.LiquidType == LiquidTypes.Cleaner);
- run.CleanerQuantity = cleaner != null ? cleaner.Quantity : 0;
+ e.Job.LastRun = DateTime.UtcNow;
+ _job.LastRun = DateTime.UtcNow;
- //if (exception != null)
- //{
- // run.FailedMessage = exception.FlattenMessage();
- //}
+ var job = db.Jobs.SingleOrDefault(x => x.Guid == _job.Guid);
- db.JobRuns.Add(run);
+ if (job != null)
+ {
+ job.LastRun = DateTime.UtcNow;
+ }
- db.SaveChanges();
+ db.SaveChanges();
+ }
}
- }
- catch (Exception ex)
- {
- LogManager.Log(ex, "Error logging the last head cleaning job run to the database.");
- }
- });
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error logging the current job run to the database.");
+ }
+ });
+ }
}
}
- #endregion
-
- #region Public Methods
-
- /// <summary>
- /// Starts the logger.
- /// </summary>
- public void Start()
- {
- IsStarted = true;
- }
-
- /// <summary>
- /// Stops the logger.
- /// </summary>
- public void Stop()
- {
- IsStarted = false;
- }
-
- /// <summary>
- /// Sets the head cleaning parameters.
- /// </summary>
- /// <param name="machine">The machine.</param>
- public void SetDefaultMachine(Machine machine)
- {
- _defaultMachine = machine;
- }
-
- #endregion
-
- #region Event Handlers
-
- 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 async void Machine_PrintingStarted(object sender, PrintingEventArgs e)
- {
- _job = e.Job;
-
- if (e.IsResumed)
+ if (ShouldLog())
{
- try
+ if (e.Job.Guid == _job.Guid)
{
- using (ObservablesContext db = ObservablesContext.CreateDefault())
+ Task.Factory.StartNew(() =>
{
- _job = await new JobBuilder(db).Set(e.Job.Guid).WithConfiguration().WithSegments().WithBrushStops().BuildAsync();
- }
- }
- catch (Exception ex)
- {
- LogManager.Log(ex, "Error loading resumed job from database.");
+ try
+ {
+ using (var db = ObservablesContext.CreateDefault())
+ {
+ db.JobRuns.Add(new JobRun()
+ {
+ StartDate = _start_date,
+ EndDate = DateTime.UtcNow,
+ JobGuid = _job.Guid,
+ EndPosition = e.JobHandler.Status.Progress,
+ JobRunStatus = JobRunStatus.Completed,
+ });
+
+ e.Job.LastRun = DateTime.UtcNow;
+ _job.LastRun = DateTime.UtcNow;
+
+ var job = db.Jobs.SingleOrDefault(x => x.Guid == _job.Guid);
+
+ if (job != null)
+ {
+ job.LastRun = DateTime.UtcNow;
+ }
+
+ db.SaveChanges();
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error logging the current job run to the database.");
+ }
+ });
}
}
}
- private void MachineOperator_HeadCleaningEnded(object sender, HeadCleaningEndedEventArgs e)
+ private void Machine_PrintingStarted(object sender, PrintingEventArgs e)
{
- InsertHeadCleaningJobRun(e);
+ _job = e.Job;
+ _start_date = DateTime.UtcNow;
}
#endregion
diff --git a/Software/Visual_Studio/Tango.Integration/JobRuns/IJobRunsLogger.cs b/Software/Visual_Studio/Tango.Integration/JobRuns/IJobRunsLogger.cs
index 386298bb9..8c4174311 100644
--- a/Software/Visual_Studio/Tango.Integration/JobRuns/IJobRunsLogger.cs
+++ b/Software/Visual_Studio/Tango.Integration/JobRuns/IJobRunsLogger.cs
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.Integration.Operation;
@@ -22,12 +21,7 @@ namespace Tango.Integration.JobRuns
/// <summary>
/// Gets or sets the job designations of which the logger should log (supports multiple flags).
/// </summary>
- JobDesignations JobDesignationFilter { get; set; }
-
- /// <summary>
- /// Gets or sets the job run source when logging job runs.
- /// </summary>
- JobSource JobSource { get; set; }
+ JobDesignations JobDesignation { get; set; }
/// <summary>
/// Gets a value indicating whether this instance is started.
@@ -43,11 +37,5 @@ namespace Tango.Integration.JobRuns
/// Stops the logger.
/// </summary>
void Stop();
-
- /// <summary>
- /// Sets the head cleaning parameters.
- /// </summary>
- /// <param name="machine">The machine.</param>
- void SetDefaultMachine(Machine machine);
}
}