using DeviceCommand.Base; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TSMasterCAN; namespace UIShare.GlobalVariable { public class GlobalInfo:BindableBase { public event EventHandler? ScopeChanged; public Dictionary ContextDic { get; set; } public Dictionary StepRunningDic { get; set; } public Dictionary ConfigDic { get; set; } public Dictionary ScopeDic { get; set; } /// 硬件指纹 → 设备实例的并发池,确保同一物理硬件全局只创建一个驱动实例。 public ConcurrentDictionary> HardwarePool { get; set; } /// CAN 硬件指纹 → ZLGCANFD 实例的并发池,确保同一 CAN 卡全局只创建一个驱动实例。 public ConcurrentDictionary> CanPool { get; set; } /// 硬件指纹 → 正在使用该设备的作用域名称列表,用于引用计数与安全销毁。 public ConcurrentDictionary>> DeviceAndScopeDic { get; set; } public String UserName { get; set; } = "Not Logged in"; public bool IsAdmin { get; set; } = true; public string CurrentOpeningScope; private string _currentScope = "default"; public string CurrentScope { get => _currentScope; set { if (_currentScope != value) { _currentScope = value; ScopeChanged?.Invoke(this, EventArgs.Empty); } } } public GlobalInfo() { ContextDic = new(); StepRunningDic = new(); ConfigDic = new(); ScopeDic = new(); HardwarePool = new ConcurrentDictionary>(StringComparer.OrdinalIgnoreCase); CanPool = new ConcurrentDictionary>(StringComparer.OrdinalIgnoreCase); DeviceAndScopeDic = new ConcurrentDictionary>>(StringComparer.OrdinalIgnoreCase); CurrentScope = "default"; } } }