refactor: 插件窗体由 static 单例状态改为实例字段(对齐 TextViewer)
将 10 个 CycleGUI 窗体/管理器从进程级 static 单例状态改为实例字段 + 实例方法, 消除本地端/Web 端共享同一可变状态的隐患(对齐 TextViewer 正例)。 每个类保留一个 private static _instance 单实例持有者;静态入口 Open()/OpenViewer() 与实例 Show() 均转发到该实例,调用方零改动、单实例“置前”行为不变。 涉及:ChargeStationManagementForm、ChargeStrategyConfigForm、CommunicationMonitorForm、 AlarmConfigManagementForm、ButtonBoxManager、DoorManager、DoorMonitor、 LoopViewer、DeliveryViewer、TrafficInterlockViewer。 构建:dotnet build StandardScene.sln --no-incremental → 0 错误,30 警告(与基线一致,无新增)。
This commit is contained in:
@@ -9,39 +9,43 @@ namespace StandardScene.Charge
|
||||
/// </summary>
|
||||
public class ChargeStrategyConfigForm
|
||||
{
|
||||
private static Panel _panel;
|
||||
private static readonly ChargeStrategyConfigService ConfigService = ChargeStrategyConfigService.Instance;
|
||||
private Panel _panel;
|
||||
private readonly ChargeStrategyConfigService ConfigService = ChargeStrategyConfigService.Instance;
|
||||
|
||||
private static ChargeStrategyConfig _config;
|
||||
private static string _status = "";
|
||||
private ChargeStrategyConfig _config;
|
||||
private string _status = "";
|
||||
|
||||
// SOC 参数
|
||||
private static float _mustChargeSoc;
|
||||
private static float _idleChargeSoc;
|
||||
private static float _taskAvailableSoc;
|
||||
private static float _fullChargeSoc;
|
||||
private static float _allowInterruptSoc;
|
||||
private float _mustChargeSoc;
|
||||
private float _idleChargeSoc;
|
||||
private float _taskAvailableSoc;
|
||||
private float _fullChargeSoc;
|
||||
private float _allowInterruptSoc;
|
||||
|
||||
// 时间参数
|
||||
private static float _idleChargeSeconds;
|
||||
private static float _idleSeconds;
|
||||
private static float _mustChargeSeconds;
|
||||
private static float _topUpMinutes;
|
||||
private float _idleChargeSeconds;
|
||||
private float _idleSeconds;
|
||||
private float _mustChargeSeconds;
|
||||
private float _topUpMinutes;
|
||||
|
||||
// 任务参数
|
||||
private static int _minAllowFreeCarToChargeTaskCnt;
|
||||
private int _minAllowFreeCarToChargeTaskCnt;
|
||||
|
||||
// 开关参数
|
||||
private static bool _allowInterruptTask;
|
||||
private static bool _useLowerSocForCharge;
|
||||
private static bool _enableErrorChargeDetection;
|
||||
private static bool _useChargeSiteFilter;
|
||||
private bool _allowInterruptTask;
|
||||
private bool _useLowerSocForCharge;
|
||||
private bool _enableErrorChargeDetection;
|
||||
private bool _useChargeSiteFilter;
|
||||
|
||||
/// <summary>打开(或置前)充电策略配置面板。兼容原 <c>new ChargeStrategyConfigForm().Show()</c> 调用方式。</summary>
|
||||
public void Show() => Open();
|
||||
|
||||
/// <summary>打开(或置前)充电策略配置面板。</summary>
|
||||
public static void Open()
|
||||
public static void Open() => (_instance ??= new ChargeStrategyConfigForm()).OpenCore();
|
||||
|
||||
private static ChargeStrategyConfigForm _instance;
|
||||
|
||||
private void OpenCore()
|
||||
{
|
||||
if (_panel != null)
|
||||
{
|
||||
@@ -120,7 +124,7 @@ namespace StandardScene.Charge
|
||||
});
|
||||
}
|
||||
|
||||
private static bool TryLoadConfig()
|
||||
private bool TryLoadConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -137,7 +141,7 @@ namespace StandardScene.Charge
|
||||
}
|
||||
}
|
||||
|
||||
private static void ApplyConfigToUi(ChargeStrategyConfig config)
|
||||
private void ApplyConfigToUi(ChargeStrategyConfig config)
|
||||
{
|
||||
_mustChargeSoc = (float)config.MustChargeSoc;
|
||||
_idleChargeSoc = (float)config.IdleChargeSoc;
|
||||
@@ -158,7 +162,7 @@ namespace StandardScene.Charge
|
||||
_useChargeSiteFilter = config.UseChargeSiteFilter;
|
||||
}
|
||||
|
||||
private static void ApplyUiToConfig()
|
||||
private void ApplyUiToConfig()
|
||||
{
|
||||
_config.MustChargeSoc = _mustChargeSoc;
|
||||
_config.IdleChargeSoc = _idleChargeSoc;
|
||||
@@ -180,7 +184,7 @@ namespace StandardScene.Charge
|
||||
}
|
||||
|
||||
/// <summary>验证 SOC 阈值之间的逻辑关系(保存前)。</summary>
|
||||
private static bool ValidateSocRanges(out string errorMessage)
|
||||
private bool ValidateSocRanges(out string errorMessage)
|
||||
{
|
||||
if (_mustChargeSoc >= _idleChargeSoc)
|
||||
{
|
||||
@@ -210,7 +214,7 @@ namespace StandardScene.Charge
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void TrySave(bool closeAfterSave)
|
||||
private void TrySave(bool closeAfterSave)
|
||||
{
|
||||
ApplyUiToConfig();
|
||||
|
||||
@@ -245,7 +249,7 @@ namespace StandardScene.Charge
|
||||
}
|
||||
}
|
||||
|
||||
private static void RestoreDefaults()
|
||||
private void RestoreDefaults()
|
||||
{
|
||||
CycleUiHelper.ConfirmThen("确定要恢复默认配置吗?当前配置将被覆盖。", () =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user