Bootstrapper.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Threading;
  5. using System.Windows;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.Util;
  8. using Aitex.Core.WCF;
  9. using Caliburn.Micro;
  10. using Caliburn.Micro.Core;
  11. using EfemDualUI.Config;
  12. using MECF.Framework.UI.Client.ClientBase;
  13. using SciChart.Charting.Visuals;
  14. namespace EfemDualUI
  15. {
  16. public class Bootstrapper : BootstrapperBase
  17. {
  18. //static Mutex mutex;
  19. //bool isNewMutex;
  20. protected override void OnStartup(object sender, StartupEventArgs e)
  21. {
  22. try
  23. {
  24. System.Collections.ArrayList procList = new System.Collections.ArrayList();
  25. foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())
  26. {
  27. procList.Add(thisProc.ProcessName);
  28. }
  29. if (!procList.Contains("EfemDualRT"))
  30. {
  31. var exeFilePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
  32. if (!Debugger.IsAttached)
  33. {
  34. exeFilePath = exeFilePath.Replace("EfemDualUI", "EfemDualRT");
  35. System.Diagnostics.Process.Start(exeFilePath);
  36. Thread.Sleep(50);
  37. }
  38. }
  39. if (!EventClient.Instance.ConnectRT())
  40. {
  41. MessageBox.Show("Can not connect with RT, launch RT first", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  42. Environment.Exit(0);
  43. return;
  44. }
  45. }
  46. catch (Exception)
  47. {
  48. MessageBox.Show("Can not connect with RT, launch RT first", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  49. Environment.Exit(0);
  50. return;
  51. }
  52. SystemConfigManager.Instance.Initialize();
  53. Singleton<Aitex.Core.RT.Log.LogManager>.Instance.Initialize();
  54. BaseApp.Instance = new ClientApp();
  55. DisplayRootViewFor<MainViewModel>();
  56. base.OnStartup(sender, e);
  57. }
  58. protected override void OnExit(object sender, EventArgs e)
  59. {
  60. base.OnExit(sender, e);
  61. Singleton<Aitex.Core.RT.Log.LogManager>.Instance.Terminate();
  62. Application.Current.Shutdown();
  63. }
  64. protected override void OnUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  65. {
  66. if (e.Exception != null)
  67. {
  68. LOG.Write(e.Exception);
  69. if (e.Exception.InnerException != null)
  70. LOG.Write(e.Exception.InnerException);
  71. }
  72. e.Handled = true;
  73. }
  74. private SimpleContainer container;
  75. public Bootstrapper()
  76. {
  77. SciChartSurface.SetRuntimeLicenseKey("vwAIyu6FysOMMV/v7pag3WEENpK0hDMQx5zbMKYtlb3PMTsV9R+v2toHl/Z2YJ7t/MDVkKCBsZjBxOUs1djpkyLqgCFMlX5DMrKFdP82QRqZRCOht0hQjW5Omy5z9ZRbalxSx4mlgnL/YXWr2JQrD1dWoTeoDP7xm8JB3+KZ4M5pqxeUCib6VvRpfq3O7HVIyFfcDk0JVByjV+vtgGpOo5RP630lKr9VLS3CPk1aUeul4XQAnJX+IafLnsgSKiDWlZMYU9qJehqA1EdwOnEvvOwhcwckJ5/BoeQ0qDvDaYZ1Jfzkcv5sqOYKd749TJ8wsoTDubT/bLv+BwBiXura1mBZlOIE9zB5XwJVedWWzi6dGDG8LRRKh1XjuyD6V92G596xYsb5b8EJJ8AkgsC/R+fLeN/FIZBlq/Vepg+1dwkLlCCtp8nZWBjsRDQWNrG6Vyk5TF2RzI62WrwKfWfNWXtC5wjkJE5IJzUFlj/B/UhCzB8=");
  78. Initialize();
  79. }
  80. protected override void Configure()
  81. {
  82. container = new SimpleContainer();
  83. container.Singleton<IEventAggregator, EventAggregator>();
  84. container.Singleton<IWindowManager, WindowManager>();
  85. //container.Singleton<IPublisher, Publisher>();
  86. container.PerRequest<MainViewModel>();
  87. }
  88. protected override object GetInstance(Type service, string key)
  89. {
  90. return container.GetInstance(service, key);
  91. }
  92. protected override IEnumerable<object> GetAllInstances(Type service)
  93. {
  94. return container.GetAllInstances(service);
  95. }
  96. protected override void BuildUp(object instance)
  97. {
  98. container.BuildUp(instance);
  99. }
  100. }
  101. }