annotate SilverlightGlimpse/SilverlightGlimpse.Test/App.xaml.cs @ 69:a0bcd783e612

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