comparison SilverlightGlimpse/SilverlightValidation/App.xaml.cs @ 69:a0bcd783e612

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