diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-25 03:41:56 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-25 03:41:56 +0300 |
| commit | 16389f246971059da6e4476808d35dc1022f8870 (patch) | |
| tree | 6b881d78ebd7f79561ecdfc3635aa702f5848b5a /Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication | |
| parent | 07173155f536396f80501839b336adac76c90f7b (diff) | |
| download | Tango-16389f246971059da6e4476808d35dc1022f8870.tar.gz Tango-16389f246971059da6e4476808d35dc1022f8870.zip | |
Improved PPC application start event logging.
Improved PP application shutdown finalization + Added termination event.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs | 57 |
1 files changed, 41 insertions, 16 deletions
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 29f4e65be..3414fda4f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -35,6 +35,7 @@ using Tango.Core.ExtensionMethods; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Synchronization; using Tango.Insights; +using System.Threading; namespace Tango.PPC.UI.PPCApplication { @@ -315,7 +316,6 @@ namespace Tango.PPC.UI.PPCApplication { LogManager.Log($"Raising {nameof(ApplicationStarted)} event..."); - _eventLogger.Log(EventTypes.APPLICATION_STARTED, "Application Started!"); ApplicationStarted?.Invoke(this, new EventArgs()); LogManager.Log("Invoking PPC view models OnApplicationStarted methods..."); @@ -414,6 +414,7 @@ namespace Tango.PPC.UI.PPCApplication _dispatcher.Invoke(() => { LogManager.Log($"Invoking {nameof(ApplicationReady)} event."); + _eventLogger.Log(EventTypes.APPLICATION_STARTED, "Application Started!"); ApplicationReady?.Invoke(this, new EventArgs()); LogManager.Log("Notifying view models about application ready..."); @@ -454,7 +455,7 @@ namespace Tango.PPC.UI.PPCApplication /// <summary> /// Shutdown the application. /// </summary> - public void ShutDown() + public async void ShutDown() { if (IsShuttingDown) return; @@ -474,11 +475,12 @@ namespace Tango.PPC.UI.PPCApplication try { - var frame = InsightsFrame.CreateEmpty(DateTime.UtcNow); - InsightsManager.Default.InsertFrame(frame); - InsightsManager.Default.Dispose(); + await FinalizeApplication(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error occurred on application shutdown finalization."); } - catch {} Environment.Exit(0); } @@ -527,11 +529,12 @@ namespace Tango.PPC.UI.PPCApplication try { - var frame = InsightsFrame.CreateEmpty(DateTime.UtcNow); - InsightsManager.Default.InsertFrame(frame); - InsightsManager.Default.Dispose(); + await FinalizeApplication(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error occurred on application shutdown finalization."); } - catch { } Process.Start(Application.ResourceAssembly.Location); Environment.Exit(0); @@ -540,7 +543,7 @@ namespace Tango.PPC.UI.PPCApplication /// <summary> /// Runs the updater utility and exits the application. /// </summary> - public void UpdateApplication(String updaterPath, String arguments) + public async void UpdateApplication(String updaterPath, String arguments) { if (IsShuttingDown) return; @@ -566,11 +569,12 @@ namespace Tango.PPC.UI.PPCApplication try { - var frame = InsightsFrame.CreateEmpty(DateTime.UtcNow); - InsightsManager.Default.InsertFrame(frame); - InsightsManager.Default.Dispose(); + await FinalizeApplication(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error occurred on application shutdown finalization."); } - catch { } LogManager.Log($"Executing '{updaterPath}' with arguments '{arguments}'..."); Process.Start(updaterPath, arguments); @@ -655,10 +659,31 @@ namespace Tango.PPC.UI.PPCApplication public void SetWindowState(WindowState state) { - InvokeUI(() => + InvokeUI(() => { MainWindow.Instance.WindowState = state; }); } + + private Task FinalizeApplication() + { + return LimitedTimeTask.StartNew(() => + { + try + { + _eventLogger.Log(EventTypes.APPLICATION_TERMINATED, "User Interface Terminated."); + _eventLogger.FlushAll(); + } + catch { } + + try + { + var frame = InsightsFrame.CreateEmpty(DateTime.UtcNow); + InsightsManager.Default.InsertFrame(frame); + InsightsManager.Default.Dispose(); + } + catch { } + }, TimeSpan.FromSeconds(5)); + } } } |
