PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/V1/spikes/AGCompositeApplicationLibrary/AGComposite.Wpf.Tests/App.xaml.cs

#
C# | 76 lines | 41 code | 10 blank | 25 comment | 1 complexity | cb389152ca827879a2b677a0facd1d89 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//===============================================================================
17
18using System;
19using System.Collections.Generic;
20using System.Windows;
21using Microsoft.Silverlight.Testing;
22
23namespace AGComposite.Wpf.Tests
24{
25    public partial class App : Application
26    {
27
28        public App()
29        {
30            this.Startup += this.Application_Startup;
31            this.Exit += this.Application_Exit;
32            this.UnhandledException += this.Application_UnhandledException;
33
34            InitializeComponent();
35        }
36
37        private void Application_Startup(object sender, StartupEventArgs e)
38        {
39            // Hook up and execute this test project
40            // For details: http://www.jeff.wilcox.name/fwlink/?0e0slb2
41            this.RootVisual = (UIElement)UnitTestSystem.CreateTestPage(this);
42        }
43
44        private void Application_Exit(object sender, EventArgs e)
45        {
46
47        }
48
49        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
50        {
51            // If the app is running outside of the debugger then report the exception using
52            // the browser's exception mechanism. On IE this will display it a yellow alert 
53            // icon in the status bar and Firefox will display a script error.
54            if (!System.Diagnostics.Debugger.IsAttached)
55            {
56
57                // NOTE: This will allow the application to continue running after an exception has been thrown
58                // but not handled. 
59                // For production applications this error handling should be replaced with something that will 
60                // report the error to the website and stop the application.
61                e.Handled = true;
62
63                try
64                {
65                    string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
66                    errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
67
68                    System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");");
69                }
70                catch (Exception)
71                {
72                }
73            }
74        }
75    }
76}