diff options
| author | Roy <Roy.mail.net@gmail.com> | 2022-11-15 11:14:01 +0200 |
|---|---|---|
| committer | Roy <Roy.mail.net@gmail.com> | 2022-11-15 11:14:01 +0200 |
| commit | 59052dd593c0d3d4eb2bf6c579e44c06daf7a038 (patch) | |
| tree | d39dd9289e16d897e82efe8be4c48509c4895cbb /Software/Visual_Studio/Tango.Integration/JobRuns | |
| parent | 81b37f187ad6823bb27ce132782301fb0bbd0c75 (diff) | |
| download | Tango-59052dd593c0d3d4eb2bf6c579e44c06daf7a038.tar.gz Tango-59052dd593c0d3d4eb2bf6c579e44c06daf7a038.zip | |
Job runs extended info.
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/JobRuns')
| -rw-r--r-- | Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs | 63 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Integration/JobRuns/JobRunInfo.cs | 26 |
2 files changed, 88 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs index 60b2efa9b..38fc472bc 100644 --- a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs +++ b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs @@ -1,16 +1,21 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using Tango.BL; using Tango.BL.Builders; +using Tango.BL.DTO; using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Core; using Tango.Core.ExtensionMethods; using Tango.Integration.Operation; +using Tango.PMR.MachineStatus; +using Tango.PMR.Printing; namespace Tango.Integration.JobRuns { @@ -22,6 +27,9 @@ namespace Tango.Integration.JobRuns { private Job _job; private Machine _defaultMachine; + private List<MachinesEvent> _currentJobEvents; + private MachineStatus _startMachineStatus; + private JobTicket _jobTicket; #region Properties @@ -45,6 +53,16 @@ namespace Tango.Integration.JobRuns /// </summary> public JobSource JobSource { get; set; } + /// <summary> + /// Gets or sets a value indicating whether create job run files with job ticket information and more. + /// </summary> + public bool CreateJobRunsFiles { get; set; } + + /// <summary> + /// Gets or sets the job runs files folder. + /// </summary> + public String JobRunsFolder { get; set; } + #endregion #region Constructors @@ -78,6 +96,21 @@ namespace Tango.Integration.JobRuns MachineOperator.PrintingFailed -= Machine_PrintingFailed; MachineOperator.PrintingFailed += Machine_PrintingFailed; MachineOperator.HeadCleaningEnded += MachineOperator_HeadCleaningEnded; + MachineOperator.MachineEventsStateProvider.EventsReceived -= MachineEventsStateProvider_EventsReceived; + MachineOperator.MachineEventsStateProvider.EventsReceived += MachineEventsStateProvider_EventsReceived; + + _currentJobEvents = new List<MachinesEvent>(); + + JobRunsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "Twine", "Tango", "JobRuns Extended Info"); + } + + private void MachineEventsStateProvider_EventsReceived(object sender, IEnumerable<MachinesEvent> events) + { + foreach (var item in events.ToList()) + { + _currentJobEvents.Add(item); + } } private bool ShouldLog() @@ -113,8 +146,9 @@ namespace Tango.Integration.JobRuns 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.NumberOfUnits = _job.NumberOfUnits; run.JobLength = e.JobHandler.Status.TotalProgress; + run.JobLogicalLength = e.Job.Length; run.LiquidQuantities = e.LiquidQuantities; run.IsGradient = _job.Segments.Any(x => x.BrushStops.Count > 1); run.GradientResolutionCm = MachineOperator.GradientGenerationConfiguration.ResolutionCM; @@ -187,6 +221,30 @@ namespace Tango.Integration.JobRuns LogManager.Log($"Inserting job run for '{run.JobName}'...\n{run.ToJsonString(nameof(JobRun.JobString), nameof(JobRun.LiquidQuantityString))}"); db.SaveChanges(); + + if (CreateJobRunsFiles) + { + try + { + Directory.CreateDirectory(JobRunsFolder); + + JobRunInfo jobRunInfo = new JobRunInfo(); + jobRunInfo.JobRunID = run.ID; + jobRunInfo.JobTicket = _jobTicket; + jobRunInfo.Events = _currentJobEvents.Select(x => MachinesEventDTO.FromObservable(x)).ToList(); + jobRunInfo.StartMachineStatus = _startMachineStatus; + jobRunInfo.EndMachineStatus = MachineOperator.MachineStatus?.Clone(); + + String json = jobRunInfo.ToJsonString(); + File.WriteAllText(Path.Combine(JobRunsFolder, $"{run.ID}.run"), json); + + LogManager.Log($"JobRun extended info file '{run.ID}' created."); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error creating job run extended info file."); + } + } } } catch (Exception ex) @@ -337,6 +395,9 @@ namespace Tango.Integration.JobRuns private async void Machine_PrintingStarted(object sender, PrintingEventArgs e) { _job = e.Job; + _currentJobEvents = new List<MachinesEvent>(); + _startMachineStatus = MachineOperator.MachineStatus?.Clone(); + _jobTicket = e.JobHandler.JobTicket; if (_job.Designation == JobDesignations.FineTuning) return; diff --git a/Software/Visual_Studio/Tango.Integration/JobRuns/JobRunInfo.cs b/Software/Visual_Studio/Tango.Integration/JobRuns/JobRunInfo.cs new file mode 100644 index 000000000..ae2172ec2 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/JobRuns/JobRunInfo.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.DTO; +using Tango.BL.Entities; +using Tango.PMR.MachineStatus; +using Tango.PMR.Printing; + +namespace Tango.Integration.JobRuns +{ + public class JobRunInfo + { + public int JobRunID { get; set; } + public JobTicket JobTicket { get; set; } + public MachineStatus StartMachineStatus { get; set; } + public MachineStatus EndMachineStatus { get; set; } + public List<MachinesEventDTO> Events { get; set; } + + public JobRunInfo() + { + Events = new List<MachinesEventDTO>(); + } + } +} |
