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:
@@ -25,29 +25,33 @@ namespace LoopViewerApp
|
||||
{
|
||||
private const string TableId = "traffic-area-list";
|
||||
|
||||
private static string JsonPath =>
|
||||
private string JsonPath =>
|
||||
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config", "traffic.json");
|
||||
|
||||
private static readonly object SaveLock = new object();
|
||||
private readonly object SaveLock = new object();
|
||||
|
||||
private static Panel _panel;
|
||||
private static string _editingAreaId = "";
|
||||
private static readonly HashSet<string> _selected = new HashSet<string>(StringComparer.Ordinal);
|
||||
private Panel _panel;
|
||||
private string _editingAreaId = "";
|
||||
private readonly HashSet<string> _selected = new HashSet<string>(StringComparer.Ordinal);
|
||||
|
||||
private static string _areaName = "";
|
||||
private static string _stationIds = "";
|
||||
private static string _controlRight = "";
|
||||
private static bool _isOccupied;
|
||||
private static bool _isEnabled = true;
|
||||
private static string _editingHint = "新增区域";
|
||||
private static string _editErr = "";
|
||||
private static volatile string _status = "";
|
||||
private string _areaName = "";
|
||||
private string _stationIds = "";
|
||||
private string _controlRight = "";
|
||||
private bool _isOccupied;
|
||||
private bool _isEnabled = true;
|
||||
private string _editingHint = "新增区域";
|
||||
private string _editErr = "";
|
||||
private volatile string _status = "";
|
||||
|
||||
/// <summary>打开(或置前)区域管理面板。兼容原 <c>new TrafficInterlockViewer().Show()</c> 调用方式。</summary>
|
||||
public void Show() => Open();
|
||||
|
||||
/// <summary>打开(或置前)区域管理面板。</summary>
|
||||
public static void Open()
|
||||
public static void Open() => (_instance ??= new TrafficInterlockViewer()).OpenCore();
|
||||
|
||||
private static TrafficInterlockViewer _instance;
|
||||
|
||||
private void OpenCore()
|
||||
{
|
||||
if (_panel != null)
|
||||
{
|
||||
@@ -171,7 +175,7 @@ namespace LoopViewerApp
|
||||
});
|
||||
}
|
||||
|
||||
private static void ConfirmDeleteSelected()
|
||||
private void ConfirmDeleteSelected()
|
||||
{
|
||||
if (_selected.Count == 0)
|
||||
{
|
||||
@@ -187,7 +191,7 @@ namespace LoopViewerApp
|
||||
CycleUiHelper.ConfirmThen(prompt, DeleteSelected);
|
||||
}
|
||||
|
||||
private static void DeleteSelected()
|
||||
private void DeleteSelected()
|
||||
{
|
||||
var selectedIds = _selected.ToHashSet(StringComparer.Ordinal);
|
||||
var removed = 0;
|
||||
@@ -203,7 +207,7 @@ namespace LoopViewerApp
|
||||
_panel?.Repaint();
|
||||
}
|
||||
|
||||
private static void SaveArea()
|
||||
private void SaveArea()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -270,7 +274,7 @@ namespace LoopViewerApp
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadAreaToFields(TrafficArea a)
|
||||
private void LoadAreaToFields(TrafficArea a)
|
||||
{
|
||||
if (a == null) return;
|
||||
_editingHint = $"编辑:{a.AreaName}";
|
||||
@@ -284,7 +288,7 @@ namespace LoopViewerApp
|
||||
_editErr = "";
|
||||
}
|
||||
|
||||
private static void ClearPanelInputs()
|
||||
private void ClearPanelInputs()
|
||||
{
|
||||
_editingAreaId = "";
|
||||
_editingHint = "新增区域";
|
||||
@@ -296,7 +300,7 @@ namespace LoopViewerApp
|
||||
_editErr = "";
|
||||
}
|
||||
|
||||
private static void SaveToConfig()
|
||||
private void SaveToConfig()
|
||||
{
|
||||
string json;
|
||||
try
|
||||
@@ -331,7 +335,7 @@ namespace LoopViewerApp
|
||||
}
|
||||
|
||||
/// <summary>解析站点集合字符串,如 "1,2,3" → <see cref="List{T}"/> of int。</summary>
|
||||
private static List<int> ParseStationIds(string text)
|
||||
private List<int> ParseStationIds(string text)
|
||||
{
|
||||
var list = new List<int>();
|
||||
if (string.IsNullOrWhiteSpace(text)) return list;
|
||||
@@ -343,19 +347,19 @@ namespace LoopViewerApp
|
||||
return list;
|
||||
}
|
||||
|
||||
private static void EnsureAreaIdsLocked()
|
||||
private void EnsureAreaIdsLocked()
|
||||
{
|
||||
foreach (var area in TrafficInterlockMission.TrafficAreaList)
|
||||
EnsureAreaId(area);
|
||||
}
|
||||
|
||||
private static string EnsureAreaId(TrafficArea area)
|
||||
private string EnsureAreaId(TrafficArea area)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(area.Id))
|
||||
area.Id = NewAreaId();
|
||||
return area.Id;
|
||||
}
|
||||
|
||||
private static string NewAreaId() => Guid.NewGuid().ToString("N");
|
||||
private string NewAreaId() => Guid.NewGuid().ToString("N");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user