This commit is contained in:
fuenmao
2026-10-09 16:46:30 +08:00
parent 4a634ef4c2
commit e6b90a06ab
63 changed files with 4170 additions and 1518 deletions
@@ -0,0 +1,25 @@
namespace Evergreen.Health.Application.Health.Scenes;
public interface ILightOffHandler
{
Task HandleAsync(CancellationToken cancellationToken);
}
/// <summary>跨设备联动由场景层分发;灯具不需要知道其他家具实体。</summary>
public sealed class LightOffDispatcher
{
private readonly IReadOnlyList<ILightOffHandler> _handlers;
public LightOffDispatcher(IEnumerable<ILightOffHandler> handlers) => _handlers = handlers.ToArray();
public async Task NotifyAsync(CancellationToken cancellationToken)
{
var failures = new List<Exception>();
foreach (var handler in _handlers)
{
cancellationToken.ThrowIfCancellationRequested();
try { await handler.HandleAsync(cancellationToken); }
catch (Exception exception) when (exception is not OperationCanceledException) { failures.Add(exception); }
}
if (failures.Count > 0)
throw new AggregateException("灯光已关闭,但部分安全联动未完成", failures);
}
}