comparison delete me/SilverlightValidation/App.xaml.cs @ 59:3591c26bd63e

MVVMLight added
author Steven Hollidge <stevenhollidge@hotmail.com>
date Sat, 21 Apr 2012 19:20:28 +0100
parents
children
comparison
equal deleted inserted replaced
58:241e2f22ed3c 59:3591c26bd63e
1 using System;
2 using System.Windows;
3 using System.Windows.Controls;
4 using System.Windows.Navigation;
5 using Glimpse;
6 //using SilverlightGlimpse.Services;
7
8 namespace SilverlightValidation
9 {
10 public partial class App : Application
11 {
12 public App()
13 {
14 this.Startup += this.Application_Startup;
15 this.Exit += this.Application_Exit;
16 this.UnhandledException += this.Application_UnhandledException;
17
18 InitializeComponent();
19 }
20
21 private void Application_Startup(object sender, StartupEventArgs e)
22 {
23 try
24 {
25 this.RootVisual = new Views.UserListView();
26 GlimpseService.CreateInstance.Load(this, "Silverlight Glimpse");
27 }
28 catch (Exception ex)
29 {
30 GlimpseService.CreateInstance.DisplayLoadFailure(this, ex, "Glimpse Demo");
31 }
32 }
33
34 private void Application_Exit(object sender, EventArgs e)
35 {
36
37 }
38
39 private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
40 {
41 // If the app is running outside of the debugger then report the exception using
42 // the browser's exception mechanism. On IE this will display it a yellow alert
43 // icon in the status bar and Firefox will display a script error.
44 if (!System.Diagnostics.Debugger.IsAttached)
45 {
46
47 // NOTE: This will allow the application to continue running after an exception has been thrown
48 // but not handled.
49 // For production applications this error handling should be replaced with something that will
50 // report the error to the website and stop the application.
51 e.Handled = true;
52 Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
53 }
54 }
55
56 private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
57 {
58 try
59 {
60 string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
61 errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
62
63 System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
64 }
65 catch (Exception)
66 {
67 }
68 }
69 }
70 }