From e29d962c5602fc9fc3a54fa4da8957609de7eea4 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 17 Feb 2019 15:52:11 +0200 Subject: Completed PPC watchdog ! --- .../Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs | 1 + .../PPC/Tango.PPC.UI/MainWindow.xaml.cs | 2 +- .../PPCApplication/DefaultPPCApplicationManager.cs | 44 +++++++++++++++++++--- .../Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs | 4 +- .../Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs | 2 +- .../PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs | 1 + 6 files changed, 46 insertions(+), 8 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs index 98ed016ae..0eb982d08 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs @@ -12,6 +12,7 @@ using Tango.Core; using Tango.Core.Helpers; using Tango.Logging; using Tango.PPC.Common; +using Tango.PPC.Common.WatchDog; using Tango.Settings; namespace Tango.PPC.UI diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs index 4ca4a1fb7..edc7cce52 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs @@ -89,7 +89,7 @@ namespace Tango.PPC.UI private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { - Environment.Exit(0); + TangoIOC.Default.GetInstance().ShutDown(); } protected override void OnPreviewKeyDown(System.Windows.Input.KeyEventArgs e) diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index 39ce8cd30..43b0cc047 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -27,6 +27,7 @@ using System.Diagnostics; using Tango.PPC.Common.EventLogging; using Tango.BL.Enumerations; using Tango.PPC.Common.Notifications; +using Tango.PPC.Common.WatchDog; namespace Tango.PPC.UI.PPCApplication { @@ -44,6 +45,7 @@ namespace Tango.PPC.UI.PPCApplication private IEventLogger _eventLogger; private IPPCModuleLoader _moduleLoader; private INotificationProvider _notificationProvider; + private WatchDogServer _watchdogServer; /// /// Occurs when a system restart is required. @@ -157,6 +159,14 @@ namespace Tango.PPC.UI.PPCApplication LogManager.Log(settings.ToJsonString()); + //Start watchdog + _watchdogServer = new WatchDogServer(Application.Current.Dispatcher); + + if (settings.EnableWatchDog) + { + _watchdogServer.Start(); + } + LogManager.Log("Reading Core settings..."); var coreSettings = SettingsManager.Default.GetOrCreate(); @@ -323,16 +333,23 @@ namespace Tango.PPC.UI.PPCApplication /// public void ShutDown() { - //TODO: Needs some work on logging and shutdown procedures! Do I really need this? - - LogManager.Log("Shutting down application..."); + if (IsShuttingDown) return; IsShuttingDown = true; - foreach (var vm in TangoIOC.Default.GetAllInstancesByBase()) + try { - vm.OnApplicationShuttingDown(); + LogManager.Log("Shutting down application..."); + _watchdogServer.Dispose(); + + foreach (var vm in TangoIOC.Default.GetAllInstancesByBase()) + { + vm.OnApplicationShuttingDown(); + } } + catch { } + + Environment.Exit(0); } /// @@ -340,6 +357,23 @@ namespace Tango.PPC.UI.PPCApplication /// public void Restart() { + if (IsShuttingDown) return; + + IsShuttingDown = true; + + try + { + LogManager.Log("Restarting the application..."); + + _watchdogServer.Dispose(); + + foreach (var vm in TangoIOC.Default.GetAllInstancesByBase()) + { + vm.OnApplicationShuttingDown(); + } + } + catch { } + Process.Start(Application.ResourceAssembly.Location); Environment.Exit(0); } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs index ee1b39ca6..48aae2b8f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs @@ -59,6 +59,7 @@ namespace Tango.PPC.UI.ViewModels private MachineSetupResult _setup_result; private IOperationSystemManager _operationSystemManager; + private IPPCApplicationManager _appManager; #region Properties @@ -193,6 +194,7 @@ namespace Tango.PPC.UI.ViewModels /// The machine setup manager. public MachineSetupViewVM(IPPCApplicationManager applicationManager, IMachineSetupManager machineSetupManager, IOperationSystemManager operationSystemManager) { + _appManager = applicationManager; MachineSetupManager = machineSetupManager; DeploymentSlot = Settings.DeploymentSlot; @@ -282,7 +284,7 @@ namespace Tango.PPC.UI.ViewModels LogManager.Log($"Executing '{updater_exe}' with arguments '{PathHelper.GetStartupPath()}'..."); Process.Start(updater_exe, PathHelper.GetStartupPath()); LogManager.Log("Terminating application process!"); - Environment.Exit(0); + _appManager.ShutDown(); } /// diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs index 07d034964..2f6199ecb 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -220,7 +220,7 @@ namespace Tango.PPC.UI.ViewModels LogManager.Log($"Executing '{updater_exe}' with arguments '{PathHelper.GetStartupPath()}'..."); Process.Start(updater_exe, PathHelper.GetStartupPath()); LogManager.Log("Terminating application process!"); - Environment.Exit(0); + ApplicationManager.ShutDown(); } else { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs index b01be3734..a4f550a39 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs @@ -13,6 +13,7 @@ using Tango.PPC.Common.ExternalBridge; using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; +using Tango.PPC.Common.WatchDog; using Tango.SharedUI; namespace Tango.PPC.UI.ViewModels -- cgit v1.3.1