forked from ac87/GoogleAssistantWindows
-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.xaml.cs
73 lines (63 loc) · 2.19 KB
/
App.xaml.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
using Autofac;
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 System.Windows.Threading;
namespace GoogleAssistantWindows
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public static IContainer Container { get; private set; }
protected override void OnStartup(StartupEventArgs e)
{
Application.Current.DispatcherUnhandledException += OnUnhandledException;
var builder = new ContainerBuilder();
builder.RegisterType<MainWindow>();
builder.RegisterType<SettingsWindow>();
builder.RegisterType<WelcomeWindow>();
builder.RegisterType<Assistant>()
.SingleInstance();
builder.RegisterType<UserManager>()
.SingleInstance();
builder.RegisterType<DeviceRegistration>();
builder.RegisterType<Settings>()
.OnActivating(settings =>
{
settings.Instance.Load();
})
.SingleInstance();
Container = builder.Build();
MainWindow mainWindow = Container.Resolve<MainWindow>();
mainWindow.Show();
}
void OnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
string typeName = GetTypeName(e.Exception);
if(typeName != null)
logger.Error("Unhandled Exception at \"{0}\": {1}", typeName, e.Exception.Message);
else
logger.Error("Unhandled Exception: {0}", e.Exception.Message);
}
private string GetTypeName(Exception ex)
{
try
{
StackTrace stackTrace = new StackTrace(ex);
return stackTrace.GetFrame(0).GetMethod().DeclaringType.FullName;
}
catch
{
return null;
}
}
}
}