From 4147c287ad90a05eae551d4ccfdccc707bebd86f Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 9 Jul 2018 15:27:55 +0300 Subject: Refactored job progress handling !!! --- .../ViewModels/MainViewVM.cs | 143 ++++----------------- 1 file changed, 27 insertions(+), 116 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index e2bba2d1d..9c6fa6239 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -67,6 +67,16 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Properties + private RunningJobStatus _runningJobStatus; + /// + /// Gets or sets the running job status. + /// + public RunningJobStatus RunningJobStatus + { + get { return _runningJobStatus; } + set { _runningJobStatus = value; RaisePropertyChangedAuto(); } + } + private ObservableCollection _machines; /// /// Gets or sets the machines. @@ -331,26 +341,6 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _runningJob = value; RaisePropertyChangedAuto(); } } - private double _runningJobProgress; - /// - /// Gets or sets the running job current progress. - /// - public double RunningJobProgress - { - get { return _runningJobProgress; } - set { _runningJobProgress = value; RaisePropertyChangedAuto(); } - } - - private TimeSpan _runningJobRemainingTime; - /// - /// Gets or sets the job remaining time. - /// - public TimeSpan RunningJobRemainingTime - { - get { return _runningJobRemainingTime; } - set { _runningJobRemainingTime = value; RaisePropertyChangedAuto(); } - } - private bool _isJobCompleted; /// /// Gets or sets a value indicating whether the running job has completed successfully. @@ -401,16 +391,6 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _machineOperator = value; RaisePropertyChangedAuto(); } } - private IRealTimeGraph _fullScreenGraph; - /// - /// Gets or sets the full screen graph. - /// - public IRealTimeGraph FullScreenGraph - { - get { return _fullScreenGraph; } - set { _fullScreenGraph = value; RaisePropertyChangedAuto(); } - } - private List _runningJobSegments; /// /// Gets or sets the running job segments. @@ -1018,8 +998,8 @@ namespace Tango.MachineStudio.Developer.ViewModels } JobEvents.Clear(); - RunningJobRemainingTime = TimeSpan.Zero; - RunningJobProgress = 0; + //RunningJobRemainingTime = TimeSpan.Zero; + //RunningJobProgress = 0; IsJobFailed = false; IsJobCanceled = false; IsJobCompleted = false; @@ -1028,7 +1008,7 @@ namespace Tango.MachineStudio.Developer.ViewModels RunningJob = ActiveJob; _runningJobEstimatedDuration = EstimatedDuration; - RunningJobSegments = CreateRunningJobEffectiveSegments(RunningJob); + RunningJobSegments = RunningJob.GetEffectiveSegment(); _navigation.NavigateTo(DeveloperNavigationView.RunningJobView); @@ -1040,55 +1020,25 @@ namespace Tango.MachineStudio.Developer.ViewModels _eventLogger.Log(String.Format("Job '{0}' started...", ActiveJob.Name)); - _jobHandler.StatusReceived += (x, status) => + _jobHandler.StatusChanged += (x, status) => { if (IsJobRunning) { - - RunningJobRemainingTime = _runningJobEstimatedDuration - TimeSpan.FromSeconds(RunningJobProgress / (SelectedProcessParametersTable.DyeingSpeed / 100d)); - RunningJobProgress = status.Progress; + RunningJobStatus = status; } + }; - foreach (var segment in RunningJobSegments) + _jobHandler.SegmentStarted += (x, segment) => + { + if (!segment.IsInterSegment) { - if (!IsJobRunning) - { - break; - } - - var previousSegmentsWithThis = RunningJobSegments.Where(s => RunningJobSegments.IndexOf(s) <= RunningJobSegments.IndexOf(segment)).ToList(); - var segmentsDuration = TimeSpan.FromSeconds(previousSegmentsWithThis.Sum(s => s.Length) / (SelectedProcessParametersTable.DyeingSpeed / 100d)); - var segmentDuration = TimeSpan.FromSeconds(segment.Length / (SelectedProcessParametersTable.DyeingSpeed / 100d)); - TimeSpan remaining = segmentsDuration - TimeSpan.FromSeconds(RunningJobProgress / (SelectedProcessParametersTable.DyeingSpeed / 100d)); - if (remaining >= TimeSpan.Zero) - { - segment.RemainingTime = remaining; - } - if (remaining < segmentDuration) - { - if (!segment.Started) - { - segment.Started = true; - - if (segment.ID != -1) - { - _speech.SpeakInfo(String.Format("Segment {0} Started.", segment.SegmentIndex)); - _eventLogger.Log(String.Format("Segment {0} Started.", segment.SegmentIndex) + Environment.NewLine + segment.ToJsonString()); - } - else - { - _speech.SpeakInfo(String.Format("Inter Segment Started.")); - _eventLogger.Log("Inter Segment Started."); - } - } - } - if (remaining <= TimeSpan.Zero) - { - if (!segment.Completed) - { - segment.Completed = true; - } - } + _speech.SpeakInfo(String.Format("Segment {0} Started.", segment.SegmentIndex)); + _eventLogger.Log(String.Format("Segment {0} Started.", segment.SegmentIndex) + Environment.NewLine + segment.ToJsonString()); + } + else + { + _speech.SpeakInfo(String.Format("Inter Segment Started.")); + _eventLogger.Log("Inter Segment Started."); } }; @@ -1153,45 +1103,6 @@ namespace Tango.MachineStudio.Developer.ViewModels } } - /// - /// Creates the running job effective segments. - /// - /// The job. - /// - private List CreateRunningJobEffectiveSegments(Job job) - { - LogManager.Log("Creating job effective segments..."); - - List segments = new List(); - foreach (var s in job.Segments) - { - s.Completed = false; - s.Started = false; - segments.Add(s); - - if (job.EnableInterSegment && job.Segments.IndexOf(s) != job.Segments.Count - 1) - { - segments.Add(new Segment() - { - Length = job.InterSegmentLength, - ID = -1, - BrushStops = new System.Collections.ObjectModel.ObservableCollection() - { - new BrushStop() - { - ColorSpace = ColorSpaces.Single(x => x.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32()), - Color = Colors.White, - } - }, - Started = false, - Completed = false - }); - } - } - - return segments; - } - #endregion #region RML @@ -1445,7 +1356,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (ActiveJob != null && SelectedProcessParametersTable != null && SelectedProcessParametersTable.DyeingSpeed > 0) { - EstimatedDuration = TimeSpan.FromSeconds(ActiveJob.Length / (SelectedProcessParametersTable.DyeingSpeed / 100d)); + EstimatedDuration = ActiveJob.GetEstimatedDuration(SelectedProcessParametersTable); } } -- cgit v1.3.1