App.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. namespace InteractiveTests
  9. {
  10. public class App : Application
  11. {
  12. public App()
  13. {
  14. this.Startup += (o, e) =>
  15. {
  16. // TODO: Investigate UnitTestSettings configuration of TestService and LogProviders.
  17. // var settings = new UnitTestSettings { StartRunImmediately = true };
  18. RootVisual = UnitTestSystem.CreateTestPage(/* settings */);
  19. };
  20. this.UnhandledException += (o, e) =>
  21. {
  22. if (!Debugger.IsAttached)
  23. {
  24. e.Handled = true;
  25. Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
  26. }
  27. };
  28. }
  29. private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
  30. {
  31. try
  32. {
  33. string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
  34. errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
  35. HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
  36. }
  37. catch (Exception)
  38. {
  39. }
  40. }
  41. }
  42. }
  43. #endif