aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2020-01-12 15:56:50 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2020-01-12 15:56:50 +0200
commit9949e351e152a929da696ef2f0a1f8b1668e83fa (patch)
tree40212bc488ea64cbaf137455c6a2280333c997dc /Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
parent9016d57f876a70952dda4419d68b568b586ef0ec (diff)
downloadTango-9949e351e152a929da696ef2f0a1f8b1668e83fa.tar.gz
Tango-9949e351e152a929da696ef2f0a1f8b1668e83fa.zip
Merged Beta+ fixes to master.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs53
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