aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs75
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
}
}