PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/V4/StockTrader RI/Silverlight/StockTraderRI/App.xaml.cs

#
C# | 89 lines | 59 code | 6 blank | 24 comment | 1 complexity | 1519656cf0ffe6d7d4ae14ab0c6c44aa MD5 | raw file
  1. //===================================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4. //===================================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===================================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===================================================================================
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Diagnostics;
  20. using System.Linq;
  21. using System.Net;
  22. using System.Windows;
  23. using System.Windows.Controls;
  24. using System.Windows.Documents;
  25. using System.Windows.Input;
  26. using System.Windows.Media;
  27. using System.Windows.Media.Animation;
  28. using System.Windows.Shapes;
  29. namespace StockTraderRI
  30. {
  31. public partial class App : Application
  32. {
  33. public App()
  34. {
  35. this.Startup += this.Application_Startup;
  36. this.Exit += this.Application_Exit;
  37. this.UnhandledException += this.Application_UnhandledException;
  38. InitializeComponent();
  39. }
  40. private void Application_Startup(object sender, StartupEventArgs e)
  41. {
  42. //this.RootVisual = new Shell();
  43. var bootstrapper = new StockTraderRIBootstrapper();
  44. bootstrapper.Run();
  45. }
  46. private void Application_Exit(object sender, EventArgs e)
  47. {
  48. }
  49. private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
  50. {
  51. // If the app is running outside of the debugger then report the exception using
  52. // the browser's exception mechanism. On IE this will display it a yellow alert
  53. // icon in the status bar and Firefox will display a script error.
  54. if (!Debugger.IsAttached)
  55. {
  56. // NOTE: This will allow the application to continue running after an exception has been thrown
  57. // but not handled.
  58. // For production applications this error handling should be replaced with something that will
  59. // report the error to the website and stop the application.
  60. e.Handled = true;
  61. Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
  62. }
  63. else
  64. {
  65. Exception exception = e.ExceptionObject;
  66. Debugger.Break();
  67. }
  68. }
  69. private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
  70. {
  71. try
  72. {
  73. string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
  74. errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
  75. System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");");
  76. }
  77. catch (Exception)
  78. {
  79. }
  80. }
  81. }
  82. }