using Logger; using System; using System.Windows.Media; namespace UIShare.GlobalVariable { /// /// 作用域日志分发器:根据显式传入的 scope 参数把日志路由到对应 /// ,实现每个台架/作用域拥有独立 LogArea。 /// public class ScopeLogDispatcher : IProgress<(string scope, string message, string color, int depth)> { private readonly GlobalInfo _globalInfo; public ScopeLogDispatcher(GlobalInfo globalInfo) { _globalInfo = globalInfo ?? throw new ArgumentNullException(nameof(globalInfo)); } public void Report((string scope, string message, string color, int depth) value) { var scope = value.scope; if (string.IsNullOrEmpty(scope)) return; if (!_globalInfo.ContextDic.TryGetValue(scope, out var context)) return; if (context?.LogProgress == null) return; Brush? brush = null; try { brush = (Brush)new BrushConverter().ConvertFromString(value.color); } catch { brush = Brushes.Black; } context.LogProgress.Report((value.message, brush, value.depth)); } } }