App.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. #if SILVERLIGHT && !SILVERLIGHTM7
  5. using System;
  6. using System.Diagnostics;
  7. using System.Windows;
  8. using System.Windows.Browser;
  9. using Microsoft.Silverlight.Testing;
  10. namespace ReactiveTests
  11. {
  12. public class App : Application
  13. {
  14. public App()
  15. {
  16. this.Startup += (o, e) =>
  17. {
  18. // TODO: Investigate UnitTestSettings configuration of TestService and LogProviders.
  19. // var settings = new UnitTestSettings { StartRunImmediately = true };
  20. RootVisual = UnitTestSystem.CreateTestPage(/* settings */);
  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. private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
  32. {
  33. try
  34. {
  35. string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
  36. errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
  37. HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
  38. }
  39. catch (Exception)
  40. {
  41. }
  42. }
  43. }
  44. }
  45. #endif