PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/Source/Bifrost.Mimir/App.xaml.cs

#
C# | 85 lines | 65 code | 13 blank | 7 comment | 1 complexity | 8d6a2dff9121cf4b13a54983659ee124 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Windows;
  3. using Bifrost.Configuration.Defaults;
  4. using Bifrost.Execution;
  5. using Bifrost.Ninject;
  6. using Bifrost.Notification;
  7. using Microsoft.Practices.ServiceLocation;
  8. using Ninject;
  9. namespace Bifrost.Mimir
  10. {
  11. public partial class App
  12. {
  13. public static IContainer Container;
  14. static App()
  15. {
  16. var dispatcher = new Dispatcher(Deployment.Current.Dispatcher);
  17. DispatcherManager.Current = dispatcher;
  18. }
  19. public App()
  20. {
  21. Startup += Application_Startup;
  22. Exit += Application_Exit;
  23. UnhandledException += Application_UnhandledException;
  24. var kernel = new StandardKernel();
  25. Container = new Container(kernel);
  26. var serviceLocator = new ContainerServiceLocator(Container);
  27. Container.Bind<IServiceLocator>(serviceLocator);
  28. ServiceLocator.SetLocatorProvider(() => serviceLocator);
  29. var bindings = new DefaultBindings();
  30. bindings.Initialize(Container);
  31. var conventions = new DefaultConventions();
  32. conventions.Initialize();
  33. InitializeComponent();
  34. }
  35. private void Application_Startup(object sender, StartupEventArgs e)
  36. {
  37. var path = Application.Current.Host.Source.AbsolutePath;
  38. RootVisual = new MainPage();
  39. }
  40. private void Application_Exit(object sender, EventArgs e)
  41. {
  42. }
  43. private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
  44. {
  45. // If the app is running outside of the debugger then report the exception using
  46. // the browser's exception mechanism. On IE this will display it a yellow alert
  47. // icon in the status bar and Firefox will display a script error.
  48. if (!System.Diagnostics.Debugger.IsAttached)
  49. {
  50. // NOTE: This will allow the application to continue running after an exception has been thrown
  51. // but not handled.
  52. // For production applications this error handling should be replaced with something that will
  53. // report the error to the website and stop the application.
  54. e.Handled = true;
  55. Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
  56. }
  57. }
  58. private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
  59. {
  60. try
  61. {
  62. string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
  63. errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
  64. System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
  65. }
  66. catch (Exception)
  67. {
  68. }
  69. }
  70. }
  71. }