App.xaml.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Threading;
  3. using System.Windows;
  4. using CommonServiceLocator;
  5. using GSG.NET.Logging;
  6. using GSG.NET.Quartz;
  7. using GSG.NET.Utils;
  8. using OHV.Common.Events;
  9. using OHV.Common.Interfaces;
  10. using OHV.SqliteDAL;
  11. using OHV.Vehicle.Concept;
  12. using Prism.Events;
  13. using Prism.Ioc;
  14. using Prism.Modularity;
  15. using Prism.Mvvm;
  16. using Prism.Unity;
  17. using VehicleControlSystem;
  18. namespace OHV.Vehicle
  19. {
  20. /// <summary>
  21. /// App.xaml에 대한 상호 작용 논리
  22. /// </summary>
  23. public partial class App : PrismApplication
  24. {
  25. static Logger logger = Logger.GetLogger();
  26. public static ISplashScreen splashScreen;
  27. private ManualResetEvent resetSplashCreated;
  28. private Thread splashThread;
  29. private void Application_Startup(object sender, StartupEventArgs e)
  30. {
  31. LogUtils.Configure("CONFIG/log4net.xml");
  32. AppUtils.LogGlobalException();
  33. if (!ProcessUtils.IsOnlyOneInstance)
  34. {
  35. MessageBox.Show("Program is already running.");
  36. this.Shutdown();
  37. return;
  38. }
  39. try
  40. {
  41. QuartzUtils.Init(10);
  42. logger.I(string.Format(string.Empty.PadRight(40, '+') + $" Ver. {AssemblyUtils.GetVersion()} " + string.Empty.PadRight(40, '+')));
  43. //var mainView = new MainWindow();
  44. //mainView.Show();
  45. //this.MainWindow = mainView;
  46. //this.ShutdownMode = ShutdownMode.OnMainWindowClose;
  47. #region Splash
  48. resetSplashCreated = new ManualResetEvent( false );
  49. splashThread = new Thread( ShowSplash );
  50. splashThread.SetApartmentState( ApartmentState.STA );
  51. splashThread.IsBackground = true;
  52. splashThread.Name = "Splash Screen";
  53. splashThread.Start();
  54. resetSplashCreated.WaitOne();
  55. #endregion
  56. }
  57. catch (Exception ex)
  58. {
  59. logger.E(ex);
  60. this.Shutdown();
  61. }
  62. }
  63. private void ShowSplash( )
  64. {
  65. // Create the window
  66. AnimatedSplashScreenWindow animatedSplashScreenWindow = new AnimatedSplashScreenWindow();
  67. splashScreen = animatedSplashScreenWindow;
  68. // Show it
  69. animatedSplashScreenWindow.Show();
  70. // Now that the window is created, allow the rest of the startup to run
  71. resetSplashCreated.Set();
  72. System.Windows.Threading.Dispatcher.Run();
  73. }
  74. private void Application_Exit(object sender, ExitEventArgs e)
  75. {
  76. var ea = Container.Resolve<IEventAggregator>();
  77. if (ea != null) ea.GetEvent<ApplicationExitEvent>().Publish("");
  78. logger.I(string.Empty.PadRight(100, '-'));
  79. }
  80. protected override Window CreateShell()
  81. {
  82. //return Container.Resolve<MainWindow>();
  83. return Container.Resolve<D_MainWindow>();
  84. //return ServiceLocator.Current.GetInstance<MainWindow>();
  85. }
  86. protected override void RegisterTypes(IContainerRegistry containerRegistry)
  87. {
  88. if ( !containerRegistry.IsRegistered<VCSystem>() )
  89. containerRegistry.RegisterSingleton<VCSystem>();
  90. if (!containerRegistry.IsRegistered<SqliteManager>())
  91. containerRegistry.RegisterSingleton<SqliteManager>();
  92. }
  93. protected override void ConfigureViewModelLocator()
  94. {
  95. base.ConfigureViewModelLocator();
  96. //ViewModelLocationProvider.Register<MainWindow, MainWindowViewModel>();
  97. }
  98. protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
  99. {
  100. base.ConfigureModuleCatalog(moduleCatalog);
  101. moduleCatalog.AddModule(typeof(VCSystem));
  102. moduleCatalog.AddModule(typeof(SqliteManager));
  103. moduleCatalog.AddModule(typeof(OHV.Module.Monitoring.MonitoringModules));
  104. moduleCatalog.AddModule(typeof(OHV.Module.MainViews.MainViewModules));
  105. moduleCatalog.AddModule(typeof(OHV.Module.Interactivity.MessageController));
  106. moduleCatalog.AddModule(typeof(OHV.Module.ListViews.ListViewController));
  107. moduleCatalog.AddModule( typeof( OHV.Module.Status.StatusViewModules ) );
  108. }
  109. }
  110. }