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 {
|
71
|
20 const string appName = "Silverlight Glimpse";
|
69
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
21 try
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
22 {
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
23 this.RootVisual = new Views.UserListView();
|
71
|
24 Glimpse.Service.Load(this, appName, new TimeSpan(0,0,0,10));
|
69
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
25 }
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
26 catch (Exception ex)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
27 {
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
28 Glimpse.Service.DisplayLoadFailure(this, ex, appName);
|
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
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
32 private void Application_Exit(object sender, EventArgs e)
|
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
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
37 private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
38 {
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
39 // If the app is running outside of the debugger then report the exception using
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
40 // the browser's exception mechanism. On IE this will display it a yellow alert
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
41 // icon in the status bar and Firefox will display a script error.
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
42 if (!System.Diagnostics.Debugger.IsAttached)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
43 {
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
44
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
45 // NOTE: This will allow the application to continue running after an exception has been thrown
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
46 // but not handled.
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
47 // For production applications this error handling should be replaced with something that will
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
48 // report the error to the website and stop the application.
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
49 e.Handled = true;
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
50 Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
|
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
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
54 private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
55 {
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
56 try
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
57 {
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
58 string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
59 errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
60
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
61 System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
62 }
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
63 catch (Exception)
|
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 }
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
68 }
|