aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
committerMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
commit00a491d93733d4625ad329b2ba8237f445364b3f (patch)
tree4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs
parent124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff)
downloadTango-00a491d9.tar.gz
Tango-00a491d9.zip
merge
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs134
1 files changed, 0 insertions, 134 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs
deleted file mode 100644
index e3ab7d111..000000000
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs
+++ /dev/null
@@ -1,134 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.Core.Commands;
-using Tango.Integration.Operation;
-using Tango.PMR.Power;
-using Tango.PPC.Common;
-using Tango.PPC.UI.AppBarItems;
-using Tango.PPC.UI.Views;
-
-namespace Tango.PPC.UI.ViewModels
-{
- public class PowerOffViewVM : PPCViewModel
- {
- private PowerDownHandler _handler;
- private PowerOffAppBarItem _appBarItem;
- private int _abortTries;
-
- private StartPowerDownResponse _status;
- public StartPowerDownResponse Status
- {
- get { return _status; }
- set { _status = value; RaisePropertyChangedAuto(); }
- }
-
- public RelayCommand AbortCommand { get; set; }
-
- public PowerOffViewVM()
- {
- _appBarItem = new PowerOffAppBarItem();
- _appBarItem.Pressed += (x, e) =>
- {
- NavigationManager.NavigateTo<InternalModule>(nameof(PowerOffView));
- };
- AbortCommand = new RelayCommand(AbortPowerOff);
- }
-
- public override void OnApplicationStarted()
- {
-
- }
-
- public override void OnApplicationReady()
- {
- base.OnApplicationReady();
- MachineProvider.MachineOperator.PowerDownStarted += MachineOperator_PowerDownStarted;
- }
-
- private void MachineOperator_PowerDownStarted(object sender, PowerDownStartedEventArgs e)
- {
- _abortTries = 0;
- _handler = e.Handler;
-
- _handler.StatusChanged += OnStatusChanged;
- _handler.Failed += OnFailed;
- _handler.Completed += OnCompleted;
-
- InvokeUI(async () =>
- {
- await NavigationManager.NavigateTo<InternalModule>(nameof(PowerOffView));
- NotificationProvider.PushAppBarItem(_appBarItem);
- });
- }
-
- private void OnStatusChanged(object sender, PowerDownStatusChangedEventArgs e)
- {
- Status = e.Status;
- _appBarItem.Status = Status;
- }
-
- private void OnCompleted(object sender, EventArgs e)
- {
- InvokeUI(async () =>
- {
- if (IsVisible)
- {
- await NavigationManager.NavigateBack();
- }
-
- NotificationProvider.PopAppBarItem(_appBarItem);
- });
- }
-
- private void OnFailed(object sender, Exception ex)
- {
- InvokeUI(async () =>
- {
- await NotificationProvider.ShowError($"An error occurred while powering off the machine.\n{ex.FlattenMessage()}");
-
- if (IsVisible)
- {
- await NavigationManager.NavigateBack();
- }
-
- NotificationProvider.PopAppBarItem(_appBarItem);
- });
- }
-
- private async void AbortPowerOff()
- {
- try
- {
- NotificationProvider.SetGlobalBusyMessage("Aborting machine power off...");
- await _handler.Abort();
- await NavigationManager.NavigateBack();
- NotificationProvider.PopAppBarItem(_appBarItem);
- }
- catch (Exception ex)
- {
- _abortTries++;
- LogManager.Log(ex, "Power down abort error.");
- NotificationProvider.ReleaseGlobalBusyMessage();
- await NotificationProvider.ShowError($"An error occurred while trying to abort the power off sequence.\n{ex.FlattenMessage()}");
-
- if (_abortTries > 2)
- {
- if (IsVisible)
- {
- await NavigationManager.NavigateBack();
- }
-
- NotificationProvider.PopAppBarItem(_appBarItem);
- }
- }
- finally
- {
- NotificationProvider.ReleaseGlobalBusyMessage();
- }
- }
- }
-}