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