|
1 using System; |
|
2 using System.Collections.Generic; |
|
3 using System.Linq; |
|
4 using System.Net; |
|
5 using System.Windows; |
|
6 using System.Windows.Controls; |
|
7 using System.Windows.Documents; |
|
8 using System.Windows.Input; |
|
9 using System.Windows.Media; |
|
10 using System.Windows.Media.Animation; |
|
11 using System.Windows.Shapes; |
|
12 |
|
13 namespace Iri.Modernisation.Test.MainInterface |
|
14 { |
|
15 public partial class App : Application |
|
16 { |
|
17 |
|
18 public App() |
|
19 { |
|
20 this.Startup += this.Application_Startup; |
|
21 this.Exit += this.Application_Exit; |
|
22 this.UnhandledException += this.Application_UnhandledException; |
|
23 |
|
24 InitializeComponent(); |
|
25 } |
|
26 |
|
27 private void Application_Startup(object sender, StartupEventArgs e) |
|
28 { |
|
29 this.RootVisual = new MainPage(); |
|
30 } |
|
31 |
|
32 private void Application_Exit(object sender, EventArgs e) |
|
33 { |
|
34 |
|
35 } |
|
36 private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) |
|
37 { |
|
38 // If the app is running outside of the debugger then report the exception using |
|
39 // the browser's exception mechanism. On IE this will display it a yellow alert |
|
40 // icon in the status bar and Firefox will display a script error. |
|
41 if (!System.Diagnostics.Debugger.IsAttached) |
|
42 { |
|
43 |
|
44 // NOTE: This will allow the application to continue running after an exception has been thrown |
|
45 // but not handled. |
|
46 // For production applications this error handling should be replaced with something that will |
|
47 // report the error to the website and stop the application. |
|
48 e.Handled = true; |
|
49 Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); |
|
50 } |
|
51 } |
|
52 private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) |
|
53 { |
|
54 try |
|
55 { |
|
56 string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; |
|
57 errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); |
|
58 |
|
59 System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");"); |
|
60 } |
|
61 catch (Exception) |
|
62 { |
|
63 } |
|
64 } |
|
65 } |
|
66 } |