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