PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 4ms 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
 1using System;
 2using System.Windows;
 3using Microsoft.Silverlight.Testing;
 4
 5namespace QDFeedParser.Silverlight.Tests
 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            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(delegate { ReportErrorToDOM(e); });
42            }
43        }
44        private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
45        {
46            try
47            {
48                string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
49                errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
50
51                System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
52            }
53            catch (Exception)
54            {
55            }
56        }
57    }
58}