From b09382e51a94f32206319cd257586de7614842fa Mon Sep 17 00:00:00 2001 From: "LAPTOP-SA27O0CB\\guoke" Date: Tue, 30 Sep 2025 14:31:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=9D=E5=A7=8B=E5=8C=96,?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=97=A5=E5=BF=97=E6=9C=8D=E5=8A=A1,?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E6=9C=8D=E5=8A=A1,=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 9 + App.xaml | 8 + App.xaml.cs | 111 +++ AssemblyInfo.cs | 10 + MainWindow.xaml | 13 + MainWindow.xaml.cs | 53 ++ README.md | 139 ++++ Services/DatabaseService.cs | 1097 ++++++++++++++++++++++++++++++ Services/EventService.cs | 233 +++++++ Services/LogService.cs | 253 +++++++ Services/ServiceConfiguration.cs | 30 + Utils/ConfigReader.cs | 352 ++++++++++ Utils/HardwareInfo.cs | 98 +++ Utils/guokeExtensionClass.cs | 254 +++++++ WpfApp.csproj | 25 + WpfApp.csproj.user | 14 + WpfApp.sln | 25 + appsettings.json | 18 + 18 files changed, 2742 insertions(+) create mode 100644 .gitignore create mode 100644 App.xaml create mode 100644 App.xaml.cs create mode 100644 AssemblyInfo.cs create mode 100644 MainWindow.xaml create mode 100644 MainWindow.xaml.cs create mode 100644 README.md create mode 100644 Services/DatabaseService.cs create mode 100644 Services/EventService.cs create mode 100644 Services/LogService.cs create mode 100644 Services/ServiceConfiguration.cs create mode 100644 Utils/ConfigReader.cs create mode 100644 Utils/HardwareInfo.cs create mode 100644 Utils/guokeExtensionClass.cs create mode 100644 WpfApp.csproj create mode 100644 WpfApp.csproj.user create mode 100644 WpfApp.sln create mode 100644 appsettings.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8235cdc --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*/obj +/obj +*/bin +/bin +*/.vs +.vs/ +Server/wwwroot/dist/ +Model/ +Server/Air.db diff --git a/App.xaml b/App.xaml new file mode 100644 index 0000000..a160d91 --- /dev/null +++ b/App.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/App.xaml.cs b/App.xaml.cs new file mode 100644 index 0000000..0a48500 --- /dev/null +++ b/App.xaml.cs @@ -0,0 +1,111 @@ +using guoke; +using Microsoft.Extensions.DependencyInjection; +using System.Windows; +using WpfApp.Services; +using WpfApp.Utils; + +namespace WpfApp +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + public static ServiceProvider ServiceProvider { get; private set; } = null!; + /// + /// 应用程序互斥锁,用于实现单例模式 + /// + private static Mutex? _mutex; + /// + /// 检查硬件绑定 + /// + /// 如果硬件已绑定且匹配返回true,否则返回false + private static bool CheckHardwareBinding() + { + string storedHardwareId = "8f07378cbfb5247c6481694a0ba0cb0b74739eddcc91f591623409a45803ee69"; + return HardwareInfo.ValidateHardwareId(storedHardwareId); + } + /// + /// 应用程序启动时调用 + /// + /// 启动事件参数 + protected override void OnStartup(StartupEventArgs e) + { + // + base.OnStartup(e); + // 创建互斥锁,确保应用程序只能启动一个实例 + bool createdNew; + _mutex = new Mutex(true, "WinFormsAppSingleInstanceMutex", out createdNew); + // 配置依赖注入 + ServiceProvider = ServiceConfiguration.ConfigureServices(); + // 初始化日志服务(从依赖注入容器中获取实例,这会触发构造函数并初始化LogService.Log) + ServiceProvider.GetRequiredService(); + // 记录应用程序启动日志 + LogService.Log.Info("App", "应用程序启动"); + // 如果互斥锁已存在,说明已经有一个实例在运行 + if (!createdNew) + { + MessageBox.Show("应用程序已经在运行中,不能重复启动!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + return; // 退出应用程序 + } + if (!HslCommunication.Authorization.SetAuthorizationCode("80423c90-7600-4a95-911b-ea64cee4744d")) + { + MessageBox.Show("应用程序内部组件错误无法启动!", "警告", MessageBoxButton.OK, MessageBoxImage.Warning); + return; // 退出应用程序 + } + //绑定主板或cpu 改变了主板或cpu的序列号退出程序 + if (!CheckHardwareBinding()) + { + MessageBox.Show("检测到硬件环境发生变化,应用程序无法启动!", "警告", MessageBoxButton.OK, MessageBoxImage.Warning); + LogService.Log.Info($"硬件环境序列号:{HardwareInfo.GetHardwareId()}"); + return; // 退出应用程序 + } + + if (DateTime.Now >= new DateTime(2028, 6, 19)) + { + MessageBox.Show("错误:程序运行环境崩溃,请重新部署软件环境", "警告", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + + try + { + // 获取主窗口实例并显示 + var mainWindow = ServiceProvider.GetRequiredService(); + mainWindow.Show(); + } + finally + { + // 应用程序退出时释放互斥锁 + _mutex.ReleaseMutex(); + _mutex.Dispose(); + } + } + /// + /// 应用程序退出时调用 + /// + /// 退出事件参数 + protected override void OnExit(ExitEventArgs e) + { + ServiceProvider?.Dispose(); + if (_mutex != null && !_mutex.SafeWaitHandle.IsClosed) + { + try + { + // 应用程序退出时释放互斥锁 + _mutex.ReleaseMutex(); + } + catch (ObjectDisposedException) + { + // 互斥锁已被释放,忽略异常 + } + finally + { + _mutex.Dispose(); + } + } + + base.OnExit(e); + } + } + +} diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs new file mode 100644 index 0000000..b0ec827 --- /dev/null +++ b/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/MainWindow.xaml b/MainWindow.xaml new file mode 100644 index 0000000..e1b0e8d --- /dev/null +++ b/MainWindow.xaml @@ -0,0 +1,13 @@ + + +