1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. 2 #if SILVERLIGHT && !SILVERLIGHTM7 3 using System; 4 using System.Diagnostics; 5 using System.Windows; 6 using System.Windows.Browser; 7 using Microsoft.Silverlight.Testing; 8 9 namespace InteractiveTests 10 { 11 public class App : Application 12 { App()13 public App() 14 { 15 this.Startup += (o, e) => 16 { 17 // TODO: Investigate UnitTestSettings configuration of TestService and LogProviders. 18 // var settings = new UnitTestSettings { StartRunImmediately = true }; 19 RootVisual = UnitTestSystem.CreateTestPage(/* settings */); 20 }; 21 22 this.UnhandledException += (o, e) => 23 { 24 if (!Debugger.IsAttached) 25 { 26 e.Handled = true; 27 Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); 28 } 29 }; 30 } 31 ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)32 private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) 33 { 34 try 35 { 36 string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; 37 errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); 38 39 HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");"); 40 } 41 catch (Exception) 42 { 43 } 44 } 45 } 46 } 47 #endif