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