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