using DeviceCommand.Base;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZLGUSBCANFD;
namespace UIShare.GlobalVariable
{
public class GlobalInfo:BindableBase
{
public event EventHandler? ScopeChanged;
/// 作用域名 → 作用域上下文(线程安全:可能被多个作用域并发创建/销毁)
public ConcurrentDictionary ContextDic { get; set; }
/// 作用域名 → 测试运行器(线程安全:可能被多个作用域并发创建/销毁)
public ConcurrentDictionary StepRunningDic { get; set; }
/// 作用域名 → 系统配置(线程安全:可能被多个作用域并发创建/销毁)
public ConcurrentDictionary ConfigDic { get; set; }
/// 作用域名 → 作用域容器(线程安全:可能被多个作用域并发创建/销毁)
public ConcurrentDictionary 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";
}
}
}