diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-02-17 15:52:11 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-02-17 15:52:11 +0200 |
| commit | e29d962c5602fc9fc3a54fa4da8957609de7eea4 (patch) | |
| tree | 857c8448611b79c3d3834f37edb00965ad5435ba /Software/Visual_Studio/PPC/Tango.PPC.UI | |
| parent | 0cd0b590f62b31a8874ea21f225ba75c7a37053c (diff) | |
| download | Tango-e29d962c5602fc9fc3a54fa4da8957609de7eea4.tar.gz Tango-e29d962c5602fc9fc3a54fa4da8957609de7eea4.zip | |
Completed PPC watchdog !
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI')
6 files changed, 46 insertions, 8 deletions
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<IPPCApplicationManager>().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; /// <summary> /// 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<CoreSettings>(); @@ -323,16 +333,23 @@ namespace Tango.PPC.UI.PPCApplication /// </summary> 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<PPCViewModel>()) + try { - vm.OnApplicationShuttingDown(); + LogManager.Log("Shutting down application..."); + _watchdogServer.Dispose(); + + foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<PPCViewModel>()) + { + vm.OnApplicationShuttingDown(); + } } + catch { } + + Environment.Exit(0); } /// <summary> @@ -340,6 +357,23 @@ namespace Tango.PPC.UI.PPCApplication /// </summary> public void Restart() { + if (IsShuttingDown) return; + + IsShuttingDown = true; + + try + { + LogManager.Log("Restarting the application..."); + + _watchdogServer.Dispose(); + + foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<PPCViewModel>()) + { + 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 /// <param name="machineSetupManager">The machine setup manager.</param> 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(); } /// <summary> 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 |
