App.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Windows;
  2. using CyberX8_Simulator.Instances;
  3. using MECF.Framework.UI.Core.Applications;
  4. using CyberX8_Core;
  5. using System;
  6. namespace CyberX8_Simulator
  7. {
  8. /// <summary>
  9. /// App.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class App : Application
  12. {
  13. protected override void OnStartup(StartupEventArgs e)
  14. {
  15. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  16. base.OnStartup(e);
  17. SystemConfig.Instance.Initialize();
  18. //SimulatorJetChamber.CurrentPMAChamber = (JetChamber)SystemConfig.Instance.GetValue<int>($"PMA.ChamberType");
  19. //SimulatorJetChamber.CurrentPMBChamber = (JetChamber)SystemConfig.Instance.GetValue<int>($"PMB.ChamberType");
  20. //SimulatorJetChamber.CurrentPMCChamber = (JetChamber)SystemConfig.Instance.GetValue<int>($"PMC.ChamberType");
  21. //SimulatorJetChamber.CurrentPMDChamber = (JetChamber)SystemConfig.Instance.GetValue<int>($"PMD.ChamberType");
  22. UiApplication.Instance.Initialize(new UiInstance());
  23. SimulatorSystem.Instance.Initialize();
  24. }
  25. static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  26. {
  27. ShowMessageDialog((Exception)e.ExceptionObject);
  28. }
  29. static void ShowMessageDialog(Exception ex)
  30. {
  31. string message = string.Format(" UI unknown exception:{0},\n", $"{ex.StackTrace} {DateTime.Now}");
  32. System.Windows.MessageBox.Show(message + ex.Message, "Unexpected exception", System.Windows.MessageBoxButton.YesNo,
  33. System.Windows.MessageBoxImage.Exclamation,
  34. System.Windows.MessageBoxResult.No,
  35. System.Windows.MessageBoxOptions.DefaultDesktopOnly);
  36. //Environment.Exit(0);
  37. }
  38. protected override void OnExit(ExitEventArgs e)
  39. {
  40. UiApplication.Instance.Terminate();
  41. SimulatorSystem.Instance.Terminate();
  42. base.OnExit(e);
  43. }
  44. }
  45. }