From c2471c200471e62b80133542183eb14af7c79bc7 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 4 Aug 2019 12:59:34 +0300 Subject: Implemented emergency switch. --- .../PPC/Tango.PPC.UI/ViewModels/EmergencyViewVM.cs | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/EmergencyViewVM.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/EmergencyViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/EmergencyViewVM.cs new file mode 100644 index 000000000..87b3c012b --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/EmergencyViewVM.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Emergency; +using Tango.PPC.Common; +using Tango.PPC.Common.Navigation; + +namespace Tango.PPC.UI.ViewModels +{ + public class EmergencyViewVM : PPCViewModel + { + private bool _isActive; + + public override void OnApplicationStarted() + { + + } + + public override void OnApplicationReady() + { + base.OnApplicationReady(); + MachineProvider.MachineOperator.EmergencyNotificationProvider.StatusChanged += EmergencyNotificationProvider_StatusChanged; + } + + private void EmergencyNotificationProvider_StatusChanged(object sender, EmergencyStatusChangedEventArgs e) + { + InvokeUI(async () => + { + if (e.Status == EmergencyStatus.On && !_isActive) + { + LogManager.Log("Emergency switch activated..."); + _isActive = true; + await NavigationManager.NavigateTo(NavigationView.EmergencyView); + } + else if (_isActive) + { + LogManager.Log("Emergency switch deactivated..."); + _isActive = false; + await NavigationManager.NavigateTo(NavigationView.LayoutView); + } + + if (e.Status == EmergencyStatus.Error && e.ErrorException != null) + { + LogManager.Log(e.ErrorException, "Error occurred while detecting emergency switch."); + } + }); + } + } +} -- cgit v1.3.1