You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.9 KiB

using System.Configuration;
using System.Data;
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using BrilliantSightClient.Model.Exceptions;
using log4net;
using log4net.Config;
using BrilliantSightClient.Model.Helper;
using BrilliantSightClient.ViewModel.Configuration.SettingsPages;
namespace BrilliantSightClient;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private static readonly ILog Logger = LogManager.GetLogger(typeof(App));
private static Mutex? _mutex = null;
protected override void OnStartup(StartupEventArgs e)
{
const string appName = "BrilliantSight";
bool createdNew;
_mutex = new Mutex(true, $"Global\\{{{appName}}}", out createdNew);
if (!createdNew)
{
MessageBox.Show("An instance of this application is already running.",
"BrilliantSight Is Running",
MessageBoxButton.OK,
MessageBoxImage.Warning);
Shutdown();
return;
}
base.OnStartup(e);
//加载日志配置文件
XmlConfigurator.Configure(new FileInfo("log4net.config"));
Logger.Info("==== ==== ==== ==== ==== ==== ==== ====");
Logger.Info("App Client Start: App Initialize");
Logger.Info("Loaded Logs Config: log4net.config");
//运行是否需要归档
Log4NetHelper.ArchiveOldLogs();
Logger.Info("Check Logs need to be archived");
//打开数据库连接
//读取数据库多语言配置
DataBaseHelper.CreateConnection();
Logger.Info("Create Sqlite Connection...");
Logger.Info("Load Language Set");
string LanguageId = Settings.SelectValueById("LanguageId");
if (LanguageId.Length == 0)
{
LanguageId = "zh-cn";
}
MultilingualHelper.setLanguage(LanguageId);
Logger.Info($"Loaded Language is {LanguageId}");
string runMode = Settings.SelectValueById("RunMode");
Logger.Info($"Load RunMode Set {runMode}");
if (runMode.Length != 0 && int.TryParse(runMode, out int iRunMode))
{
Common.RunMode = iRunMode;
}
else
{
Common.RunMode = 0;
}
Logger.Info($"Load RunMode is {Common.RunMode}");
Logger.Info("App Client Start: App Initialize Succeed !!!");
DispatcherUnhandledException += (s, ex) =>
{
MessageBox.Show($"致命错误: {ex.Exception.Message}");
Logger.Error($"发生致命错误!!!{ex.Exception.Message}{ex.Exception.StackTrace}");
ex.Handled = true;
};
Logger.Info("==== ==== ==== ==== ==== ==== ==== ====");
}
protected override void OnExit(ExitEventArgs e)
{
_mutex?.ReleaseMutex();
base.OnExit(e);
}
}