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/MainViewVM.cs') 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 From df7dff9855ae205ce0a02d8fd460cd3399c5e362 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 9 Jul 2018 16:19:47 +0300 Subject: Fixed an issue with MS DB Module table scrolling lagging. Added new event type for embedded job status message. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 1572864 -> 1572864 bytes .../Controls/DbTableView.xaml | 2 +- .../ViewModels/MainViewVM.cs | 13 ++++++++----- .../Controls/MdiContainerControl.xaml | 3 --- .../Tango.MachineStudio.UI/Resources/BuildDate.txt | 2 +- .../Tango.BL/Enumerations/EventTypes.cs | 6 ++++++ .../Tango.Emulations/Emulators/MachineEmulator.cs | 15 +++++++++++---- .../Tango.Integration/Operation/JobHandler.cs | 14 +++++++++++++- 9 files changed, 40 insertions(+), 15 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 68ceada4f..4eb52310c 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 9c6151842..2db2bb930 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Controls/DbTableView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Controls/DbTableView.xaml index d0f6b045a..6602d8973 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Controls/DbTableView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Controls/DbTableView.xaml @@ -5,7 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" mc:Ignorable="d" - d:DesignHeight="720" d:DesignWidth="1300"> + d:DesignHeight="720" d:DesignWidth="1300" BorderThickness="1" BorderBrush="{StaticResource AccentColorBrush}"> 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 9c6fa6239..35221c460 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 @@ -635,7 +635,7 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Initializing relay commands..."); - TangoIOC.Default.GetInstanceWhenAvailable((vm) => + TangoIOC.Default.GetInstanceWhenAvailable((vm) => { _dataCaptureVM = vm; _dataCaptureVM.RelayCommandsInvalidated += (_, __) => StartJobAndRecordCommand.RaiseCanExecuteChanged(); @@ -998,8 +998,6 @@ namespace Tango.MachineStudio.Developer.ViewModels } JobEvents.Clear(); - //RunningJobRemainingTime = TimeSpan.Zero; - //RunningJobProgress = 0; IsJobFailed = false; IsJobCanceled = false; IsJobCompleted = false; @@ -1020,15 +1018,20 @@ namespace Tango.MachineStudio.Developer.ViewModels _eventLogger.Log(String.Format("Job '{0}' started...", ActiveJob.Name)); - _jobHandler.StatusChanged += (x, status) => + _jobHandler.StatusChanged += (x, status) => { if (IsJobRunning) { RunningJobStatus = status; + + if (status.Message != null) + { + _eventLogger.Log(BL.Enumerations.EventTypes.JobStatus, status.Message); + } } }; - _jobHandler.SegmentStarted += (x, segment) => + _jobHandler.SegmentStarted += (x, segment) => { if (!segment.IsInterSegment) { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml index b248a4aec..50c2aaf46 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml @@ -31,9 +31,6 @@ - - - diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Resources/BuildDate.txt b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Resources/BuildDate.txt index 4ab3e3519..3a3a449ca 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Resources/BuildDate.txt +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Resources/BuildDate.txt @@ -1 +1 @@ -Mon 07/09/2018 15:24:42.63 +Mon 07/09/2018 16:10:08.89 diff --git a/Software/Visual_Studio/Tango.BL/Enumerations/EventTypes.cs b/Software/Visual_Studio/Tango.BL/Enumerations/EventTypes.cs index dfa4d7ce2..07d37ead7 100644 --- a/Software/Visual_Studio/Tango.BL/Enumerations/EventTypes.cs +++ b/Software/Visual_Studio/Tango.BL/Enumerations/EventTypes.cs @@ -247,5 +247,11 @@ namespace Tango.BL.Enumerations [Description("Occures when a diagnostics recording has been stopped")] RecordingStopped = 37, + /// + /// (Occures when a job status message has been received from the embedded device) + /// + [Description("Occures when a job status message has been received from the embedded device")] + JobStatus = 38, + } } diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index 6dc406a09..ebf658250 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -385,17 +385,24 @@ namespace Tango.Emulations.Emulators double progress = 0; _cancelJob = false; + bool message_sent = false; Task.Factory.StartNew(() => { while (progress < job.Length && !_cancelJob) { + var status = new PMR.Printing.JobStatus(); + status.Progress = progress; + + if (!message_sent) + { + message_sent = true; + status.Message = "Demo Message From Emulator..."; + } + Transporter.SendResponse(new JobResponse() { - Status = new PMR.Printing.JobStatus() - { - Progress = progress - } + Status = status, }, request.Container.Token); diff --git a/Software/Visual_Studio/Tango.Integration/Operation/JobHandler.cs b/Software/Visual_Studio/Tango.Integration/Operation/JobHandler.cs index 0fcd070b3..db2220f54 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/JobHandler.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/JobHandler.cs @@ -17,6 +17,7 @@ namespace Tango.Integration.Operation { private Action _cancelAction; private List _effectiveSegments; + private String _lastStatusMessage; #region Events @@ -176,7 +177,18 @@ namespace Tango.Integration.Operation Status.Progress = s.Progress; Status.RemainingTime = Status.TotalTime - Job.TranslateProgressToTime(Status.Progress, ProcessParameters); Status.RemainingProgress = Status.TotalProgress - Status.Progress; - Status.Message = s.Message; + + if (s.Message != _lastStatusMessage && s.Message != String.Empty) + { + Status.Message = s.Message; + } + else + { + Status.Message = null; + } + + _lastStatusMessage = s.Message; + StatusChanged?.Invoke(this, Status); //Segments Completion -- cgit v1.3.1