gyorgy@0: using System; gyorgy@0: using System.Collections.Generic; gyorgy@0: using System.Linq; gyorgy@0: using System.Net; gyorgy@0: using System.Windows; gyorgy@0: using System.Windows.Controls; gyorgy@0: using System.Windows.Documents; gyorgy@0: using System.Windows.Input; gyorgy@0: using System.Windows.Media; gyorgy@0: using System.Windows.Media.Animation; gyorgy@0: using System.Windows.Shapes; gyorgy@0: gyorgy@0: namespace SilverlightMediaElement gyorgy@0: { gyorgy@0: public partial class App : Application gyorgy@0: { gyorgy@0: gyorgy@0: public App() gyorgy@0: { gyorgy@0: this.Startup += this.Application_Startup; gyorgy@0: this.Exit += this.Application_Exit; gyorgy@0: this.UnhandledException += this.Application_UnhandledException; gyorgy@0: gyorgy@0: InitializeComponent(); gyorgy@0: } gyorgy@0: gyorgy@0: private void Application_Startup(object sender, StartupEventArgs e) gyorgy@0: { gyorgy@0: this.RootVisual = new MainPage(e.InitParams); gyorgy@0: } gyorgy@0: gyorgy@0: private void Application_Exit(object sender, EventArgs e) gyorgy@0: { gyorgy@0: gyorgy@0: } gyorgy@0: gyorgy@0: private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) gyorgy@0: { gyorgy@0: // If the app is running outside of the debugger then report the exception using gyorgy@0: // the browser's exception mechanism. On IE this will display it a yellow alert gyorgy@0: // icon in the status bar and Firefox will display a script error. gyorgy@0: if (!System.Diagnostics.Debugger.IsAttached) gyorgy@0: { gyorgy@0: gyorgy@0: // NOTE: This will allow the application to continue running after an exception has been thrown gyorgy@0: // but not handled. gyorgy@0: // For production applications this error handling should be replaced with something that will gyorgy@0: // report the error to the website and stop the application. gyorgy@0: e.Handled = true; gyorgy@0: Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); gyorgy@0: } gyorgy@0: } gyorgy@0: gyorgy@0: private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) gyorgy@0: { gyorgy@0: try gyorgy@0: { gyorgy@0: string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; gyorgy@0: errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); gyorgy@0: gyorgy@0: System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");"); gyorgy@0: } gyorgy@0: catch (Exception) gyorgy@0: { gyorgy@0: } gyorgy@0: } gyorgy@0: } gyorgy@0: }