Hide
Need a quick chart or graph for your blog? Try our reStructured Text renderer. Join Siafoo Now or Learn More

Web Part Hosted Silverlight Control - App Atom Feed 0

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