comparison Demo/Silverlight/Client/App.xaml.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Net;
5 using System.Windows;
6 using System.Windows.Controls;
7 using System.Windows.Documents;
8 using System.Windows.Input;
9 using System.Windows.Media;
10 using System.Windows.Media.Animation;
11 using System.Windows.Shapes;
12
13 namespace Client
14 {
15 public partial class App : Application
16 {
17
18 public App()
19 {
20 this.Startup += this.Application_Startup;
21 this.Exit += this.Application_Exit;
22 this.UnhandledException += this.Application_UnhandledException;
23
24 InitializeComponent();
25 }
26
27 private void Application_Startup(object sender, StartupEventArgs e)
28 {
29 this.RootVisual = new MainPage();
30 }
31
32 private void Application_Exit(object sender, EventArgs e)
33 {
34
35 }
36
37 private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
38 {
39 // If the app is running outside of the debugger then report the exception using
40 // the browser's exception mechanism. On IE this will display it a yellow alert
41 // icon in the status bar and Firefox will display a script error.
42 if (!System.Diagnostics.Debugger.IsAttached)
43 {
44
45 // NOTE: This will allow the application to continue running after an exception has been thrown
46 // but not handled.
47 // For production applications this error handling should be replaced with something that will
48 // report the error to the website and stop the application.
49 e.Handled = true;
50 Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
51 }
52 }
53
54 private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
55 {
56 try
57 {
58 string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
59 errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
60
61 System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
62 }
63 catch (Exception)
64 {
65 }
66 }
67 }
68 }