PageRenderTime 13ms CodeModel.GetById 9ms app.highlight 2ms RepoModel.GetById 1ms 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//===================================================================================
17using System;
18using System.Collections.Generic;
19using System.Diagnostics;
20using System.Linq;
21using System.Net;
22using System.Windows;
23using System.Windows.Controls;
24using System.Windows.Documents;
25using System.Windows.Input;
26using System.Windows.Media;
27using System.Windows.Media.Animation;
28using System.Windows.Shapes;
29
30namespace StockTraderRI
31{
32    public partial class App : Application
33    {
34        public App()
35        {
36            this.Startup += this.Application_Startup;
37            this.Exit += this.Application_Exit;
38            this.UnhandledException += this.Application_UnhandledException;
39
40            InitializeComponent();
41        }
42
43        private void Application_Startup(object sender, StartupEventArgs e)
44        {
45            //this.RootVisual = new Shell();
46            var bootstrapper = new StockTraderRIBootstrapper();
47            bootstrapper.Run();
48        }
49
50        private void Application_Exit(object sender, EventArgs e)
51        {
52
53        }
54        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
55        {
56            // If the app is running outside of the debugger then report the exception using
57            // the browser's exception mechanism. On IE this will display it a yellow alert 
58            // icon in the status bar and Firefox will display a script error.
59            if (!Debugger.IsAttached)
60            {
61
62                // NOTE: This will allow the application to continue running after an exception has been thrown
63                // but not handled. 
64                // For production applications this error handling should be replaced with something that will 
65                // report the error to the website and stop the application.
66                e.Handled = true;
67                Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
68            }
69            else
70            {
71                Exception exception = e.ExceptionObject;
72                Debugger.Break();
73            }
74        }
75        private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
76        {
77            try
78            {
79                string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
80                errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
81
82                System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");");
83            }
84            catch (Exception)
85            {
86            }
87        }
88    }
89}