OSDN Git Service

test
[psychlops/silverlight.git] / test5 / App.xaml.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Linq;\r
4 using System.Net;\r
5 using System.Windows;\r
6 using System.Windows.Controls;\r
7 using System.Windows.Documents;\r
8 using System.Windows.Input;\r
9 using System.Windows.Media;\r
10 using System.Windows.Media.Animation;\r
11 using System.Windows.Shapes;\r
12 \r
13 namespace PsychlopsSilverlight4test\r
14 {\r
15         public partial class App : Application\r
16         {\r
17 \r
18                 public App()\r
19                 {\r
20                         this.Startup += this.Application_Startup;\r
21                         this.Exit += this.Application_Exit;\r
22                         this.UnhandledException += this.Application_UnhandledException;\r
23 \r
24                         InitializeComponent();\r
25                 }\r
26 \r
27                 private void Application_Startup(object sender, StartupEventArgs e)\r
28                 {\r
29                         this.RootVisual = new MainPage();\r
30                 }\r
31 \r
32                 private void Application_Exit(object sender, EventArgs e)\r
33                 {\r
34 \r
35                 }\r
36                 private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)\r
37                 {\r
38                         // アプリケーションがデバッガーの外側で実行されている場合、ブラウザーの\r
39                         // 例外メカニズムによって例外が報告されます。これにより、IE ではステータス バーに\r
40                         // 黄色の通知アイコンが表示され、Firefox にはスクリプト エラーが表示されます。\r
41                         if (!System.Diagnostics.Debugger.IsAttached)\r
42                         {\r
43 \r
44                                 // メモ : これにより、アプリケーションは例外がスローされた後も実行され続け、例外は\r
45                                 // ハンドルされません。 \r
46                                 // 実稼動アプリケーションでは、このエラー処理は、Web サイトにエラーを報告し、\r
47                                 // アプリケーションを停止させるものに置換される必要があります。\r
48                                 e.Handled = true;\r
49                                 Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });\r
50                         }\r
51                 }\r
52                 private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)\r
53                 {\r
54                         try\r
55                         {\r
56                                 string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;\r
57                                 errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");\r
58 \r
59                                 System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");\r
60                         }\r
61                         catch (Exception)\r
62                         {\r
63                         }\r
64                 }\r
65         }\r
66 }\r