annotate SilverlightValidation/SilverlightValidation.Tests/App.xaml.cs @ 121:8f94475d3146 tip

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