PageRenderTime 27ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

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

#
C# | 100 lines | 53 code | 8 blank | 39 comment | 1 complexity | 46c24c8070dcc73aa399ae9fc71eff48 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 RealEstateListingViewer.Models;
 45using RealEstateListingViewer.Services;
 46using RealEstateListingViewer.Views;
 47
 48namespace RealEstateListingViewer
 49{
 50    public partial class App : Application
 51    {
 52
 53        public App()
 54        {
 55            this.Startup += this.Application_Startup;
 56            this.Exit += this.Application_Exit;
 57            this.UnhandledException += this.Application_UnhandledException;
 58
 59            InitializeComponent();
 60        }
 61
 62        private void Application_Startup(object sender, StartupEventArgs e)
 63        {
 64            RealEstateListingPresentationModel model = new RealEstateListingPresentationModel();
 65
 66            this.RootVisual = model.View as UIElement;
 67        }
 68
 69        private void Application_Exit(object sender, EventArgs e)
 70        {
 71        }
 72
 73        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
 74        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
 75        {
 76            // If the app is running outside of the debugger then report the exception using
 77            // the browser's exception mechanism. On IE this will display it a yellow alert 
 78            // icon in the status bar and Firefox will display a script error.
 79            if (!System.Diagnostics.Debugger.IsAttached)
 80            {
 81                // NOTE: This will allow the application to continue running after an exception has been thrown
 82                // but not handled. 
 83                // For production applications this error handling should be replaced with something that will 
 84                // report the error to the website and stop the application.
 85                e.Handled = true;
 86
 87                try
 88                {
 89                    string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
 90                    errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
 91
 92                    System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");");
 93                }
 94                catch (Exception)
 95                {
 96                }
 97            }
 98        }
 99    }
100}