-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
97 lines (77 loc) · 3.36 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using TEFL_App.DataLayer;
using TEFL_App.Models;
using static TEFL_App.Helpers.Enums;
namespace TEFL_App
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
#region Public Fields
public static readonly HttpClient client = new HttpClient();
public static readonly int VersionNumber = 1;
public static Employer ManagerProfile = new Employer();
public static TEFLProfile StudentProfile = new TEFLProfile();
#endregion Public Fields
#region Public Constructors
public App()
{
DbContext.Initialise();
RememberMeData = DbContext.GetAllRememberMeData();
Settings = DbContext.GetAppSettings();
CultureInfo = new CultureInfo(Settings.CultureInfo);
CultureInfo.DefaultThreadCurrentCulture = CultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo;
InitializeComponent();
}
protected override void OnStartup(StartupEventArgs e)
{
SetupExceptionHandling();
}
private void SetupExceptionHandling()
{
AppDomain.CurrentDomain.UnhandledException += (s, e) => LogUnhandledException((Exception)e.ExceptionObject, "AppDomain.CurrentDomain.UnhandledException");
DispatcherUnhandledException += (s, e) => LogUnhandledException(e.Exception, "Application.Current.DispatcherUnhandledException");
TaskScheduler.UnobservedTaskException += (s, e) => LogUnhandledException(e.Exception, "TaskScheduler.UnobservedTaskException");
}
private void LogUnhandledException(Exception exception, string source)
{
string message = $"Unhandled exception ({source})";
//var file = System.IO.File.CreateText("newFile.txt");
try
{
AssemblyName assemblyName = Assembly.GetExecutingAssembly().GetName();
message = $"Unhandled exception in {assemblyName.Name} v{assemblyName.Version} ({source})";
}
catch (Exception ex)
{
// file.WriteLine(ex.Message);
//_Logger.Fatal(ex, "Exception in LogUnhandledException");
}
finally
{
// file.WriteLine(exception.Message + "\n" + message);
//_Logger.Fatal(exception, message);
MessageBox.Show($"An unexpected error occurred. Please contact Support if the error persists. \n\n {exception.Message} \n\n {exception.StackTrace}", "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
#endregion Public Constructors
#region Public Properties
public static CultureInfo CultureInfo { get; set; }
public static List<DbRememberMe> RememberMeData { get; set; }
public static DbAppSettings Settings { get; set; }
public static List<TEFLProfile> TEFLProfiles { get; set; }
public static string UserLogin { get; set; } = "";
public static string UserPassword { get; set; } = "";
public static UserType UserType { get; set; }
#endregion Public Properties
}
}