aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs
diff options
context:
space:
mode:
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.cs77
1 files changed, 77 insertions, 0 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 9e8a9fe34..2bb4e9286 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs
@@ -10,6 +10,7 @@ using Tango.Integration.Operation;
using Tango.PPC.Common;
using Tango.PPC.Common.Modules;
using Tango.PPC.Common.Navigation;
+using Tango.PPC.UI.Views;
using Tango.PPC.UI.ViewsContracts;
using Tango.SharedUI;
@@ -22,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.
@@ -121,6 +123,16 @@ namespace Tango.PPC.UI.ViewModels
/// </summary>
public RelayCommand RestartApplicationCommand { get; set; }
+ /// <summary>
+ /// Gets or sets the power off command.
+ /// </summary>
+ public RelayCommand PowerOffCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the reset command.
+ /// </summary>
+ public RelayCommand ResetCommand { get; set; }
+
#endregion
#region Constructors
@@ -146,6 +158,8 @@ namespace Tango.PPC.UI.ViewModels
PowerCommand = new RelayCommand(() => IsPowerOpened = true);
RestartApplicationCommand = new RelayCommand(RestartApplication);
+ PowerOffCommand = new RelayCommand(PowerOffMachine, () => MachineProvider.MachineOperator.Status != MachineStatuses.Disconnected);
+ ResetCommand = new RelayCommand(ResetMachine, () => MachineProvider.MachineOperator.Status != MachineStatuses.Disconnected);
}
#endregion
@@ -239,6 +253,54 @@ namespace Tango.PPC.UI.ViewModels
}
}
+ /// <summary>
+ /// Powers off the machine.
+ /// </summary>
+ private async void PowerOffMachine()
+ {
+ IsMenuOpened = false;
+
+ if (await NotificationProvider.ShowQuestion("Are you sure you wish to turn off the machine?"))
+ {
+ try
+ {
+ await MachineProvider.MachineOperator.PowerDown();
+ }
+ 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
@@ -260,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