PageRenderTime 26ms CodeModel.GetById 18ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/V4/Quickstarts/MultiTargeting/Silverlight/RealEstateListingViewer.Tests/App.xaml.cs

#
C# | 94 lines | 49 code | 6 blank | 39 comment | 1 complexity | 02e725ecc18ac4b500ce4f5400211b24 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//===================================================================================
18// Microsoft patterns & practices
19// Composite Application Guidance for Windows Presentation Foundation and Silverlight
20//===================================================================================
21// Copyright (c) Microsoft Corporation.  All rights reserved.
22// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
23// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
24// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
25// FITNESS FOR A PARTICULAR PURPOSE.
26//===================================================================================
27// The example companies, organizations, products, domain names,
28// e-mail addresses, logos, people, places, and events depicted
29// herein are fictitious.  No association with any real company,
30// organization, product, domain name, email address, logo, person,
31// places, or events is intended or should be inferred.
32//===================================================================================
33using System;
34using System.Collections.Generic;
35using System.Linq;
36using System.Net;
37using System.Windows;
38using System.Windows.Controls;
39using System.Windows.Documents;
40using System.Windows.Input;
41using System.Windows.Media;
42using System.Windows.Media.Animation;
43using System.Windows.Shapes;
44using Microsoft.Silverlight.Testing;
45
46namespace RealEstateListingViewer.Tests
47{
48    public partial class App : Application
49    {
50        public App()
51        {
52            this.Startup += this.Application_Startup;
53            this.Exit += this.Application_Exit;
54            this.UnhandledException += this.Application_UnhandledException;
55
56            InitializeComponent();
57        }
58
59        private void Application_Startup(object sender, StartupEventArgs e)
60        {
61            this.RootVisual = UnitTestSystem.CreateTestPage();
62        }
63
64        private void Application_Exit(object sender, EventArgs e)
65        {
66        }
67
68        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
69        {
70            // If the app is running outside of the debugger then report the exception using
71            // the browser's exception mechanism. On IE this will display it a yellow alert 
72            // icon in the status bar and Firefox will display a script error.
73            if (!System.Diagnostics.Debugger.IsAttached)
74            {
75                // NOTE: This will allow the application to continue running after an exception has been thrown
76                // but not handled. 
77                // For production applications this error handling should be replaced with something that will 
78                // report the error to the website and stop the application.
79                e.Handled = true;
80
81                try
82                {
83                    string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
84                    errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
85
86                    System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");");
87                }
88                catch (Exception)
89                {
90                }
91            }
92        }
93    }
94}