Files
IOT/LAEPS/App.xaml.cs
2025-12-23 10:55:34 +08:00

70 lines
2.6 KiB
C#

using LAEPS.ViewModels;
using LAEPS.ViewModels.Dialogs;
using LAEPS.Views;
using LAEPS.Views.Dialogs;
using Castle.DynamicProxy;
using LAEPS.Views;
using System.Configuration;
using System.Data;
using System.Reflection;
using System.Windows;
using static System.Runtime.InteropServices.JavaScript.JSType;
using LAEPS.PubEvent;
using Notifications.Wpf.Core;
using Logger;
using Common;
namespace LAEPS
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : PrismApplication
{
protected override Window CreateShell()
{
//UI线程未捕获异常处理事件
this.DispatcherUnhandledException += OnDispatcherUnhandledException;
//Task线程内未捕获异常处理事件
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
////多线程异常
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
return Container.Resolve<ShellView>();
}
private void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
//通常全局异常捕捉的都是致命信息
LoggerHelper.Error(e.Exception.Message,e.Exception.StackTrace);
}
private void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
LoggerHelper.Error(e.Exception.Message, e.Exception.StackTrace);
}
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
//记录dump文件
Exception ex = e.ExceptionObject as Exception;
MiniDump.TryDump($"dumps\\Error_{DateTime.Now:yyyy-MM-dd HH-mm-ss-ms}.dmp", MiniDump.Option.WithFullMemory, ex);
}
protected override void OnInitialized()
{
var login=Container.Resolve<LoginView>();
login.Show();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
//注册视图
containerRegistry.RegisterForNavigation<MainView>("MainView");
containerRegistry.RegisterForNavigation<SettingView>("SettingView");
containerRegistry.RegisterForNavigation<UpdateInfoView>("UpdateInfoView");
//注册弹窗
containerRegistry.RegisterDialog<MessageBoxView, MessageBoxViewModel>("MessageBox");
// 注册通知管理器
INotificationManager NotificationManager = new NotificationManager();
containerRegistry.RegisterInstance<INotificationManager>(NotificationManager);
}
}
}