blob: 4a9bf08558c88aed7062abaf60da2ad32960ac1b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
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
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
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
/// <summary>
/// Handles the ApplicationCrashed event of the ExceptionTrapper control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ApplicationCrashedEventArgs"/> instance containing the event data.</param>
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
}
}
|