diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index d7717e6db..2bb4e9286 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -23,6 +23,7 @@ namespace Tango.PPC.UI.ViewModels public class LayoutViewVM : PPCViewModel<ILayoutView> { private JobHandler _jobHandler; + private bool _resettingDevice; /// <summary> /// Gets or sets the module loader. @@ -127,6 +128,11 @@ namespace Tango.PPC.UI.ViewModels /// </summary> public RelayCommand PowerOffCommand { get; set; } + /// <summary> + /// Gets or sets the reset command. + /// </summary> + public RelayCommand ResetCommand { get; set; } + #endregion #region Constructors @@ -152,7 +158,8 @@ namespace Tango.PPC.UI.ViewModels PowerCommand = new RelayCommand(() => IsPowerOpened = true); RestartApplicationCommand = new RelayCommand(RestartApplication); - PowerOffCommand = new RelayCommand(PowerOffMachine); + PowerOffCommand = new RelayCommand(PowerOffMachine, () => MachineProvider.MachineOperator.Status != MachineStatuses.Disconnected); + ResetCommand = new RelayCommand(ResetMachine, () => MachineProvider.MachineOperator.Status != MachineStatuses.Disconnected); } #endregion @@ -252,6 +259,7 @@ namespace Tango.PPC.UI.ViewModels private async void PowerOffMachine() { IsMenuOpened = false; + if (await NotificationProvider.ShowQuestion("Are you sure you wish to turn off the machine?")) { try @@ -261,10 +269,38 @@ namespace Tango.PPC.UI.ViewModels catch (Exception ex) { LogManager.Log(ex, "Error triggering power down."); + await NotificationProvider.ShowError(ex.FlattenMessage()); } } } + /// <summary> + /// Resets the machine. + /// </summary> + private async void ResetMachine() + { + IsMenuOpened = false; + + if (!await NotificationProvider.ShowQuestion("Are you sure you want to reset the machine?")) return; + + try + { + _resettingDevice = true; + ResetCommand.RaiseCanExecuteChanged(); + await MachineProvider.MachineOperator.Reset(); + await NotificationProvider.ShowInfo("Machine was successfully restarted."); + } + catch (Exception ex) + { + await NotificationProvider.ShowError(ex.FlattenMessage()); + } + finally + { + _resettingDevice = false; + ResetCommand.RaiseCanExecuteChanged(); + } + } + #endregion #region Override Methods @@ -286,6 +322,21 @@ namespace Tango.PPC.UI.ViewModels } + public override void OnApplicationReady() + { + base.OnApplicationReady(); + MachineProvider.MachineOperator.StatusChanged += MachineOperator_StatusChanged; + } + + private void MachineOperator_StatusChanged(object sender, MachineStatuses e) + { + InvokeUI(() => + { + PowerOffCommand.RaiseCanExecuteChanged(); + ResetCommand.RaiseCanExecuteChanged(); + }); + } + #endregion #region Public Methods |
