using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using System.Windows; using Tango.Logging; namespace Tango.Protobuf.UI { /// /// Interaction logic for App.xaml /// public partial class App : Application { private WpfGlobalExceptionTrapper exceptionTrapper; private LogManager LogManager = LogManager.Default; protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); //Register Loggers. LogManager.RegisterLogger(new FileLogger()); LogManager.RegisterLogger(new VSOutputLogger()); LogManager.Log("Application Started!"); exceptionTrapper = new WpfGlobalExceptionTrapper(); exceptionTrapper.Initialize(this); exceptionTrapper.ApplicationCrashed += ExceptionTrapper_ApplicationCrashed; } #region Global Exception Trapping /// /// Handles the ApplicationCrashed event of the ExceptionTrapper control. /// /// The source of the event. /// The instance containing the event data. private void ExceptionTrapper_ApplicationCrashed(object sender, ApplicationCrashedEventArgs e) { if (MessageBox.Show("The system has encountered and unhandled exception and it is recommended that you restart the application. Do you wish to restart the application?", "Twine", MessageBoxButton.YesNo, MessageBoxImage.Error, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly) == MessageBoxResult.Yes) { e.TryRecover = false; LogManager.Log("User selection was to restart the application. Restarting..."); Process.Start(Application.ResourceAssembly.Location); Environment.Exit(0); } else { e.TryRecover = true; } } #endregion } }