Mercurial > silverbladetech
annotate SilverlightGlimpse/SilverlightGlimpse.Test/App.xaml.cs @ 63:536498832a79
Latest version before changing bindings to Listbox
author | Steven Hollidge <stevenhollidge@hotmail.com> |
---|---|
date | Sun, 22 Apr 2012 13:33:42 +0100 |
parents | 810116cd6b8e |
children | b0e369f1e948 |
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 //using Glimpse; |
63
536498832a79
Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
62
diff
changeset
|
5 using System.Reflection; |
62
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
6 |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
7 namespace SilverlightGlimpse.Test |
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 partial class App : Application |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
10 { |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
11 public App() |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
12 { |
63
536498832a79
Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
62
diff
changeset
|
13 Startup += Application_Startup; |
536498832a79
Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
62
diff
changeset
|
14 Exit += Application_Exit; |
536498832a79
Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
62
diff
changeset
|
15 UnhandledException += Application_UnhandledException; |
62
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
16 |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
17 InitializeComponent(); |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
18 } |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
19 |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
20 private void Application_Startup(object sender, StartupEventArgs e) |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
21 { |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
22 try |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
23 { |
63
536498832a79
Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
62
diff
changeset
|
24 RootVisual = new MainPage(); |
536498832a79
Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
62
diff
changeset
|
25 GlimpseService.CreateInstance.Load(this, Assembly.GetCallingAssembly().FullName); |
62
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
26 } |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
27 catch (Exception ex) |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
28 { |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
29 GlimpseService.CreateInstance.DisplayLoadFailure(this, ex); |
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 |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
33 private void Application_Exit(object sender, EventArgs e) |
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 |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
38 private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
39 { |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
40 // 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
|
41 // 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
|
42 // icon in the status bar and Firefox will display a script error. |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
43 if (!System.Diagnostics.Debugger.IsAttached) |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
44 { |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
45 |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
46 // 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
|
47 // but not handled. |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
48 // For production applications this error handling should be replaced with something that will |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
49 // report the error to the website and stop the application. |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
50 e.Handled = true; |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
51 Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); |
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 |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
55 private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
56 { |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
57 try |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
58 { |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
59 string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
60 errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
61 |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
62 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
|
63 } |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
64 catch (Exception) |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
65 { |
63
536498832a79
Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
62
diff
changeset
|
66 //TODO: log here |
62
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
67 } |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
68 } |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
69 } |
810116cd6b8e
ErrorWindow working
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
70 } |