From 4b95b6c19bdf18e50068285b3b0a8a8ab0a7b4ce Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 24 Apr 2019 19:30:23 +0300 Subject: Machine Studio v4.0.13.0 PPC v1.0.11.0 --- .../Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs | 70 ++++++++++++++++++++++ .../PPC/Tango.PPC.UI/Properties/AssemblyInfo.cs | 2 +- .../Visual_Studio/PPC/Tango.PPC.UI/app.manifest | 2 +- 3 files changed, 72 insertions(+), 2 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 0eb982d08..0bd9f9d1d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs @@ -9,9 +9,12 @@ using System.Threading.Tasks; using System.Windows; using Tango.BL; using Tango.Core; +using Tango.Core.DI; using Tango.Core.Helpers; using Tango.Logging; using Tango.PPC.Common; +using Tango.PPC.Common.EventLogging; +using Tango.PPC.Common.Notifications; using Tango.PPC.Common.WatchDog; using Tango.Settings; @@ -22,6 +25,8 @@ namespace Tango.PPC.UI /// public partial class App : Application { + private WpfGlobalExceptionTrapper exceptionTrapper; + public static String[] StartupArgs { get; private set; } private LogManager LogManager = LogManager.Default; @@ -47,6 +52,10 @@ namespace Tango.PPC.UI base.OnStartup(e); + exceptionTrapper = new WpfGlobalExceptionTrapper(); + exceptionTrapper.Initialize(this); + exceptionTrapper.ApplicationCrashed += ExceptionTrapper_ApplicationCrashed; + LogManager.Categories.Clear(); CoreSettings.DefaultDataSource = new DataSource() @@ -72,5 +81,66 @@ namespace Tango.PPC.UI LogManager.Categories.AddRange(settings.LoggingCategories); } + + #region Global Exception Trapping + + /// + /// Handles the ApplicationCrashed event of the ExceptionTrapper. + /// + /// The source of the event. + /// The instance containing the event data. + private void ExceptionTrapper_ApplicationCrashed(object sender, ApplicationCrashedEventArgs e) + { + e.TryRecover = true; + + try + { + LogManager.Log(e.Exception, "Application Crashed!"); + LogManager.Log("Trying to recover from application crash..."); + + try + { + if (Application.Current == null) + { + new Application { ShutdownMode = ShutdownMode.OnExplicitShutdown }; + } + } + catch { } + + try + { + var eventLogger = TangoIOC.Default.GetInstance(); + if (eventLogger != null) + { + eventLogger.Log(e.Exception, "Application Crashed!"); + } + } + catch { } + + Application.Current.Dispatcher.Invoke(async () => + { + try + { + LogManager.Log("Trying to notify the user about the crash..."); + INotificationProvider notificationProvider = TangoIOC.Default.GetInstance(); + + if (notificationProvider != null) + { + await notificationProvider.ShowError("An unexpected error has occurred. Use the application logs to diagnose and report the problem."); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error using the notification provider."); + } + }); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error in global exception trapper!"); + } + } + + #endregion } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Properties/AssemblyInfo.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Properties/AssemblyInfo.cs index 1f4f36e0b..6244f13fb 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Properties/AssemblyInfo.cs @@ -8,4 +8,4 @@ using System.Windows; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Tango PPC Application")] -[assembly: AssemblyVersion("1.0.10.0")] +[assembly: AssemblyVersion("1.0.11.0")] diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest index efc5f8179..d72e75011 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest @@ -16,7 +16,7 @@ Remove this element if your application requires this virtualization for backwards compatibility. --> - + -- cgit v1.3.1