Files
FATrace/FATrace.OEMApp/Program.cs
2025-09-11 20:29:17 +08:00

103 lines
3.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Threading;
using System.Windows.Forms;
using NLog;
namespace FATrace.OEMApp
{
internal static class Program
{
//日志的实例化
private static Logger logger = LogManager.GetCurrentClassLogger();
public static bool IsActive { get; private set; }
public static DateTime StartTime = DateTime.Now;
public static string SystemName = "";
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
bool isAppRunning = false;
Mutex mutex = new Mutex(true, System.Diagnostics.Process.GetCurrentProcess().ProcessName, out isAppRunning);
if (!isAppRunning)
{
MessageBox.Show("程序已运行,不能再次打开!");
Environment.Exit(1);
}
// 授权 12.3
//V12.3.0: d8868ab9 - 4494 - 4056 - 98c6 - b669e2434e25
//V12.2.0: fe49cdb6 - b388 - 4c05 - 9b66 - 0e3f1ad3627f
//V12.1.3: 2fb771c7 - 4c29 - 445d - bddd - a7b8a75de397
//V12.1.2: b23b00e2 - ce46 - 4bfc - b33c - 71c47c2c11c2
//V12.1.1: 95057912 - 579c - 42d1 - ad31 - eb598f73706f
//V11.8.2: b980977c - 3323 - 4876 - b633 - c0bef93d75c1
if (!HslCommunication.Authorization.SetAuthorizationCode("d8868ab9-4494-4056-98c6-b669e2434e25"))
{
//active failed
MessageBox.Show("授权失败当前程序只能使用8小时");
// return;
}
else
{
IsActive = true;
}
// 可选系统名
try
{
SystemName = FATrace.Com.ConfigHelper.GetStringOrDefault("SystemName", "FATrace OEM");
}
catch (Exception ex)
{
logger.Warn(ex, "读取 SystemName 失败,采用默认值。");
SystemName = "FATrace OEM";
}
// 数据库连通性自检
try
{
var db = FSqlContext.FDb;
var ok = db.Ado.ExecuteScalar("SELECT 1");
logger.Info($"数据库连通性检查成功,返回: {ok}");
}
catch (Exception ex)
{
logger.Error(ex, "数据库连通性检查失败,请检查 App.config 中的连接字符串 connecting 以及数据库服务状态。");
// 不强制退出,让 UI 仍可启动,但在 UI 中提示
}
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new MainApp());
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
var ex = e.ExceptionObject as Exception;
if (ex != null)
{
logger.Error(ex, $"未处理异常,是否终止: {e.IsTerminating}");
}
else
{
logger.Error($"未处理异常(非 Exception 对象),是否终止: {e.IsTerminating}. 对象: {e.ExceptionObject}");
}
}
catch
{
// 忽略日志失败,避免再次引发异常
}
}
}
}