PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/V2.2/trunk/RI/Silverlight/StockTraderRI.Modules.Market.Silverlight.Tests/App.xaml.cs

#
C# | 83 lines | 53 code | 7 blank | 23 comment | 1 complexity | 3ee9c651a2e7e050f50894ca760add6d 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.Linq;
20using System.Net;
21using System.Windows;
22using System.Windows.Controls;
23using System.Windows.Documents;
24using System.Windows.Input;
25using System.Windows.Media;
26using System.Windows.Media.Animation;
27using System.Windows.Shapes;
28using Microsoft.Silverlight.Testing;
29
30namespace StockTraderRI.Modules.Market.Tests
31{
32    public partial class App : Application
33    {
34
35        public App()
36        {
37            this.Startup += this.Application_Startup;
38            this.Exit += this.Application_Exit;
39            this.UnhandledException += this.Application_UnhandledException;
40
41            InitializeComponent();
42        }
43
44        private void Application_Startup(object sender, StartupEventArgs e)
45        {
46            this.RootVisual = UnitTestSystem.CreateTestPage();
47        }
48
49        private void Application_Exit(object sender, EventArgs e)
50        {
51
52        }
53        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
54        {
55            // If the app is running outside of the debugger then report the exception using
56            // the browser's exception mechanism. On IE this will display it a yellow alert 
57            // icon in the status bar and Firefox will display a script error.
58            if (!System.Diagnostics.Debugger.IsAttached)
59            {
60
61                // NOTE: This will allow the application to continue running after an exception has been thrown
62                // but not handled. 
63                // For production applications this error handling should be replaced with something that will 
64                // report the error to the website and stop the application.
65                e.Handled = true;
66                Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
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
76                System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");");
77            }
78            catch (Exception)
79            {
80            }
81        }
82    }
83}