PageRenderTime 1024ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/QDFeedParser.Silverlight.Tests/App.xaml.cs

#
C# | 58 lines | 44 code | 7 blank | 7 comment | 1 complexity | e09682939cad87edb31bbddb3a387b91 MD5 | raw file
  1. using System;
  2. using System.Windows;
  3. using Microsoft.Silverlight.Testing;
  4. namespace QDFeedParser.Silverlight.Tests
  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. 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(delegate { ReportErrorToDOM(e); });
  35. }
  36. }
  37. private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
  38. {
  39. try
  40. {
  41. string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
  42. errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
  43. System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
  44. }
  45. catch (Exception)
  46. {
  47. }
  48. }
  49. }
  50. }