using Common.Attributes;
using DeviceCommand.Base;
using Model.Models;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Threading;
using UIShare.PubEvent;
namespace UIShare.GlobalVariable
{
///
/// 硬件数据广播器(中间层,全局单例):
/// 直接基于 GlobalInfo.HardwarePool 中的设备指纹字典进行统一采样,
/// 每个物理设备只采样一次,然后向所有引用该设备的作用域分别广播 HardwareDataReportedEvent。
/// 解决多作用域共享同一物理设备时的重复采样问题。
/// DeviceCommand 层无需引用 Prism,完全解耦。
///
public class HardwareDataBroadcaster : IDisposable
{
private readonly IEventAggregator _eventAggregator;
private readonly GlobalInfo _globalInfo;
/// 采样定时器
private readonly DispatcherTimer _sampleTimer;
///
/// 已注册的采样项:(Fingerprint, MethodName, 编译后的委托, DeviceInstance)
/// 委托签名统一为 Func<object, CancellationToken, Task<string>>
/// - 第一个参数 = 设备实例(open delegate 风格,编译时已做类型转换)
/// - 第二个参数 = CancellationToken(无参方法会忽略它)
/// - 返回值 = Task<string>
///
private readonly List<(string Fingerprint, string MethodName, Func