App.xaml.cs 2.3 KB

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