PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Visual Studio 2008/CSSL3HTMLBridge/CSSL3HTMLBridge/App.xaml.cs

#
C# | 66 lines | 52 code | 7 blank | 7 comment | 1 complexity | 112bb6ae7a5dd05a0d12f8051fc1c452 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Net;
 5using System.Windows;
 6using System.Windows.Controls;
 7using System.Windows.Documents;
 8using System.Windows.Input;
 9using System.Windows.Media;
10using System.Windows.Media.Animation;
11using System.Windows.Shapes;
12
13namespace CSSL3HTMLBridge
14{
15    public partial class App : Application
16    {
17
18        public App()
19        {
20            this.Startup += this.Application_Startup;
21            this.Exit += this.Application_Exit;
22            this.UnhandledException += this.Application_UnhandledException;
23
24            InitializeComponent();
25        }
26
27        private void Application_Startup(object sender, StartupEventArgs e)
28        {
29            this.RootVisual = new MainPage();
30        }
31
32        private void Application_Exit(object sender, EventArgs e)
33        {
34
35        }
36        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
37        {
38            // If the app is running outside of the debugger then report the exception using
39            // the browser's exception mechanism. On IE this will display it a yellow alert 
40            // icon in the status bar and Firefox will display a script error.
41            if (!System.Diagnostics.Debugger.IsAttached)
42            {
43
44                // NOTE: This will allow the application to continue running after an exception has been thrown
45                // but not handled. 
46                // For production applications this error handling should be replaced with something that will 
47                // report the error to the website and stop the application.
48                e.Handled = true;
49                Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
50            }
51        }
52        private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
53        {
54            try
55            {
56                string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
57                errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
58
59                System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
60            }
61            catch (Exception)
62            {
63            }
64        }
65    }
66}