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