using Prism.DryIoc; using Prism.Ioc; using ProjectManagementSystem.Common.Extenions; using ProjectManagementSystem.Common.Function; using ProjectManagementSystem.Common.Logger; using ProjectManagementSystem.Language; using ProjectManagementSystemView.Infrastructure; using ProjectManagementSystemView.ViewModels; using ProjectManagementSystemView.Views; using ProjectManagementSystemView.Views.Dialogs; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Threading.Tasks; using System.Windows; namespace ProjectManagementSystemView { /// /// App.xaml 的交互逻辑 /// public partial class App : PrismApplication { private static System.Threading.Mutex mutex; protected override Window CreateShell() { return Container.Resolve(); } protected override void OnStartup(StartupEventArgs e) { try { var cultureInfo = AppSetting.TryGetValue("CultureInfo"); if (!string.IsNullOrWhiteSpace(cultureInfo)) { ResourceService.Current.ChangeCulture(cultureInfo); } var assemblyName = this.GetType().Assembly.GetName().Name; mutex = new System.Threading.Mutex(true, $"Global\\{assemblyName}"); if (mutex.WaitOne(0, false)) { base.OnStartup(e); DispatcherUnhandledException += App_DispatcherUnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; } else { MessageBox.Show(Langs.ProgramIsAlreadyRunning, Langs.Prompt); this.Shutdown(); } } catch (Exception ex) { CLog.Instance.SystemLog.WriteExceptionCaller(ex); MessageBox.Show($"{Langs.ApplicationRunningAbnormally}{ex.Message}"); this.Shutdown(); } } private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) { e.SetObserved(); CLog.Instance.SystemLog.WriteExceptionCaller(e.Exception); MessageBox.Show($"{Langs.TaskScheduler_UnobservedTaskException}{e.Exception.Message}"); } private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { e.Handled = true; CLog.Instance.SystemLog.WriteExceptionCaller(e.Exception); MessageBox.Show($"{Langs.App_DispatcherUnhandledException}{e.Exception.Message}"); } private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Exception exception = e.ExceptionObject as Exception; CLog.Instance.SystemLog.WriteExceptionCaller(exception); MessageBox.Show($"{Langs.CurrentDomain_UnhandledException}{exception.Message}"); } protected override void RegisterTypes(IContainerRegistry containerRegistry) { containerRegistry.Register(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); } } }