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 ! --- .../PPCApplication/DefaultPPCApplicationManager.cs | 44 +++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication') 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); } -- cgit v1.3.1