123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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
- {
- /// <summary>
- /// App.xaml 的交互逻辑
- /// </summary>
- public partial class App : PrismApplication
- {
- private static System.Threading.Mutex mutex;
- protected override Window CreateShell()
- {
- return Container.Resolve<MainView>();
- }
- protected override void OnStartup(StartupEventArgs e)
- {
- try
- {
- var cultureInfo = AppSetting.TryGetValue<string>("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<IDialogHostService, DialogHostService>();
- containerRegistry.RegisterForNavigation<LogView>();
- containerRegistry.RegisterForNavigation<CallTaskView>();
- containerRegistry.RegisterForNavigation<CurrentTaskView>();
- containerRegistry.RegisterForNavigation<DebugAgvView>();
- containerRegistry.RegisterForNavigation<DebugView>();
- containerRegistry.RegisterForNavigation<DebugPackRgvView>();
- containerRegistry.RegisterForNavigation<DebugPackView>();
- containerRegistry.RegisterForNavigation<DebugPackV2View>();
- containerRegistry.RegisterForNavigation<DebugIOView>();
- containerRegistry.RegisterForNavigation<DebugPlcView>();
- containerRegistry.RegisterForNavigation<DebugRailAgvView>();
- containerRegistry.RegisterForNavigation<DebugRollerHxView>();
- containerRegistry.RegisterForNavigation<PmsTaskInfoView>();
- containerRegistry.RegisterForNavigation<WmsQueryView>();
- containerRegistry.RegisterForNavigation<Wms2DView>();
- containerRegistry.RegisterForNavigation<Wms3DView>();
- containerRegistry.RegisterForNavigation<ModifyWmsView>();
- containerRegistry.RegisterForNavigation<SimpleTaskView>();
- }
- }
- }
|