diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-01 11:39:19 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-01 11:39:19 +0200 |
| commit | 06ad24ef8a414fc89c0cf42b9f5264d584292afe (patch) | |
| tree | 7bbe6eadb54d21996aba8d50855137ce20750578 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels | |
| parent | f573292928d08acbf04acb8ea74f55f7561390a0 (diff) | |
| download | Tango-06ad24ef8a414fc89c0cf42b9f5264d584292afe.tar.gz Tango-06ad24ef8a414fc89c0cf42b9f5264d584292afe.zip | |
Improved RequestShutDown Mechanism on machine studio UI implementation.
Fixed issue with job brush markers visibility.
Implemented Job Progress Indicator.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs | 75 |
1 files changed, 73 insertions, 2 deletions
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 85febd0f1..4f7447253 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 @@ -15,6 +15,7 @@ using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.StudioApplication; using Tango.SharedUI; using System.Runtime.CompilerServices; +using System.Windows.Threading; namespace Tango.MachineStudio.Developer.ViewModels { @@ -22,7 +23,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// Represents the developer module main view, view model. /// </summary> /// <seealso cref="Tango.SharedUI.ViewModel" /> - public class MainViewVM : ViewModel + public class MainViewVM : ViewModel, IShutdownRequestBlocker { private INotificationProvider _notification; @@ -203,13 +204,35 @@ namespace Tango.MachineStudio.Developer.ViewModels } private bool _isJobRunning; - + /// <summary> + /// Gets or sets a value indicating whether a job is currently running. + /// </summary> public bool IsJobRunning { get { return _isJobRunning; } set { _isJobRunning = value; RaisePropertyChangedAuto(); } } + private Job _runningJob; + /// <summary> + /// Gets or sets the currently running job. + /// </summary> + public Job RunningJob + { + get { return _runningJob; } + set { _runningJob = value; RaisePropertyChangedAuto(); } + } + + private double _runningJobProgress; + /// <summary> + /// Gets or sets the running job current progress. + /// </summary> + public double RunningJobProgress + { + get { return _runningJobProgress; } + set { _runningJobProgress = value; RaisePropertyChangedAuto(); } + } + #endregion #region Commands @@ -279,6 +302,11 @@ namespace Tango.MachineStudio.Developer.ViewModels /// </summary> public RelayCommand StartJobCommand { get; set; } + /// <summary> + /// Gets or sets the stop job command. + /// </summary> + public RelayCommand StopJobCommand { get; set; } + #endregion #region Constructors @@ -324,6 +352,7 @@ namespace Tango.MachineStudio.Developer.ViewModels RemoveBrushStopCommand = new RelayCommand(RemoveBrushStop, () => SelectedBrushStop != null); SaveJobsCommand = new RelayCommand(SaveJobs, () => SelectedMachine != null); StartJobCommand = new RelayCommand(StartJob, () => SelectedJob != null && !IsJobRunning); + StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); } #endregion @@ -438,9 +467,32 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Private Methods + private void StopJob() + { + RunningJobProgress = 0; + IsJobRunning = false; + RunningJob = null; + } + private void StartJob() { IsJobRunning = true; + RunningJob = SelectedJob; + + DispatcherTimer timer = new DispatcherTimer(); + timer.Interval = TimeSpan.FromSeconds(0.1); + timer.Tick += (x, y) => + { + if (RunningJob == null || RunningJobProgress >= RunningJob.Length) + { + timer.Stop(); + StopJob(); + return; + } + RunningJobProgress += 0.1; + }; + + timer.Start(); } private async void SaveJobs() @@ -739,5 +791,24 @@ namespace Tango.MachineStudio.Developer.ViewModels } #endregion + + #region IShutdownRequestBlocker + + public Task<bool> OnShutdownRequest() + { + if (IsJobRunning) + { + InvokeUI(() => + { + _notification.ShowWarning("Please stop the currently running job before closing the developer module."); + }); + + return Task.FromResult(false); + } + + return Task.FromResult(true); + } + + #endregion } } |
