Mercurial > silverbladetech
comparison SilverlightValidation/SilverlightValidation.Tests/App.xaml.cs @ 107:572886951353
Working tests under StatLight
author | stevenhollidge <stevenhollidge@hotmail.com> |
---|---|
date | Sun, 06 May 2012 16:09:28 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
106:62477c2e8837 | 107:572886951353 |
---|---|
1 using System; | |
2 using System.Windows; | |
3 using Microsoft.Silverlight.Testing; | |
4 | |
5 namespace SilverlightValidation.Tests | |
6 { | |
7 public partial class App | |
8 { | |
9 | |
10 public App() | |
11 { | |
12 this.Startup += this.Application_Startup; | |
13 this.Exit += this.Application_Exit; | |
14 this.UnhandledException += this.Application_UnhandledException; | |
15 | |
16 InitializeComponent(); | |
17 } | |
18 | |
19 private void Application_Startup(object sender, StartupEventArgs e) | |
20 { | |
21 RootVisual = UnitTestSystem.CreateTestPage(); | |
22 } | |
23 | |
24 private void Application_Exit(object sender, EventArgs e) | |
25 { | |
26 | |
27 } | |
28 private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) | |
29 { | |
30 // If the app is running outside of the debugger then report the exception using | |
31 // the browser's exception mechanism. On IE this will display it a yellow alert | |
32 // icon in the status bar and Firefox will display a script error. | |
33 if (!System.Diagnostics.Debugger.IsAttached) | |
34 { | |
35 | |
36 // NOTE: This will allow the application to continue running after an exception has been thrown | |
37 // but not handled. | |
38 // For production applications this error handling should be replaced with something that will | |
39 // report the error to the website and stop the application. | |
40 e.Handled = true; | |
41 Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); | |
42 } | |
43 } | |
44 private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) | |
45 { | |
46 try | |
47 { | |
48 string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; | |
49 errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); | |
50 | |
51 System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");"); | |
52 } | |
53 catch (Exception) | |
54 { | |
55 } | |
56 } | |
57 } | |
58 } |