using System; using System.Collections.Generic; using System.Threading; using System.Windows; using Aitex.Core.RT.Log; using Aitex.Core.Util; using Aitex.Core.WCF; using Caliburn.Micro; using Caliburn.Micro.Core; using OpenSEMI.ClientBase; using OpenSEMI.Core.Msg; using SciChart.Charting.Visuals; using Virgo_D.UI.Config; namespace VirgoUI.Client { public class Bootstrapper : BootstrapperBase { private static Mutex _mutex; protected override void OnStartup(object sender, StartupEventArgs e) { try { CheckAnotherInstanceRunning("Virgo.UI"); if (!EventClient.Instance.ConnectRT()) { MessageBox.Show("Can not connect with RT, launch RT first", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); return; } } catch (Exception) { MessageBox.Show("Can not connect with RT, launch RT first", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); return; } SystemConfigManager.Instance.Initialize(); Singleton.Instance.Initialize(); FrameworkCompatibilityPreferences.KeepTextBoxDisplaySynchronizedWithTextProperty = false; BaseApp.Instance = new VirgoUI.Client.ClientApp(); DisplayRootViewFor(); base.OnStartup(sender, e); } protected override void OnExit(object sender, EventArgs e) { base.OnExit(sender, e); Singleton.Instance.Terminate(); MsgPool.TerminateAll(); Application.Current.Shutdown(); } protected override void OnUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { if (e.Exception != null) { LOG.Write(e.Exception); if (e.Exception.InnerException != null) LOG.Write(e.Exception.InnerException); } e.Handled = true; } private SimpleContainer container; public Bootstrapper() { SciChartSurface.SetRuntimeLicenseKey("vwAIyu6FysOMMV/v7pag3WEENpK0hDMQx5zbMKYtlb3PMTsV9R+v2toHl/Z2YJ7t/MDVkKCBsZjBxOUs1djpkyLqgCFMlX5DMrKFdP82QRqZRCOht0hQjW5Omy5z9ZRbalxSx4mlgnL/YXWr2JQrD1dWoTeoDP7xm8JB3+KZ4M5pqxeUCib6VvRpfq3O7HVIyFfcDk0JVByjV+vtgGpOo5RP630lKr9VLS3CPk1aUeul4XQAnJX+IafLnsgSKiDWlZMYU9qJehqA1EdwOnEvvOwhcwckJ5/BoeQ0qDvDaYZ1Jfzkcv5sqOYKd749TJ8wsoTDubT/bLv+BwBiXura1mBZlOIE9zB5XwJVedWWzi6dGDG8LRRKh1XjuyD6V92G596xYsb5b8EJJ8AkgsC/R+fLeN/FIZBlq/Vepg+1dwkLlCCtp8nZWBjsRDQWNrG6Vyk5TF2RzI62WrwKfWfNWXtC5wjkJE5IJzUFlj/B/UhCzB8="); Initialize(); } protected override void Configure() { container = new SimpleContainer(); container.Singleton(); container.Singleton(); //container.Singleton(); container.PerRequest(); } void CheckAnotherInstanceRunning(string appName) { _mutex = new Mutex(true, appName, out bool createNew); if (!createNew) { if (!_mutex.WaitOne(1000)) { string msg = $"{appName} is already running,can not start again"; System.Windows.MessageBox.Show(msg, $"{appName} Launch Failed", System.Windows.MessageBoxButton.OK, MessageBoxImage.Warning, System.Windows.MessageBoxResult.No, System.Windows.MessageBoxOptions.DefaultDesktopOnly); Environment.Exit(0); } } } protected override object GetInstance(Type service, string key) { return container.GetInstance(service, key); } protected override IEnumerable GetAllInstances(Type service) { return container.GetAllInstances(service); } protected override void BuildUp(object instance) { container.BuildUp(instance); } } }