public IReadOnlyCollection <IEvent> ExecuteCommands(IReadOnlyCollection <ICommand> commands) { var aggregateCommands = commands.OfType <IAggregateCommand>() .Where(x => x.AggregateRootType == _aggregateRootActor.EntityType) .ToList(); if (aggregateCommands.Count == 0) { return(Array <IEvent> .Empty); } var aggregateNameParts = _aggregateRootActor.EntityType.FullName.Split('.').Reverse().ToList(); using (Probe.Create("Aggregate", aggregateNameParts[2], aggregateNameParts[0])) { var events = new List <IEvent>(); var recalculateCommands = aggregateCommands.OfType <AggregateCommand.Recalculate>() .SelectMany(next => new ICommand[] { new SyncDataObjectCommand(next.AggregateRootType, next.AggregateRootIds), new ReplaceValueObjectCommand(next.AggregateRootIds) }) .ToList(); events.AddRange(_rootToLeafActor.ExecuteCommands(recalculateCommands)); // TODO: вопрос: надо ли тут схлапывать events по distinct или не надо, проверить!!! return(events); } }
public IReadOnlyCollection <IEvent> ExecuteCommands(IReadOnlyCollection <ICommand> commands) { var aggregateCommands = commands.OfType <IAggregateCommand>() .Where(x => x.AggregateRootType == _aggregateRootActor.EntityType) .Distinct() .ToArray(); IEnumerable <IEvent> events = Array <IEvent> .Empty; if (!aggregateCommands.Any()) { return(Array <IEvent> .Empty); } var aggregateNameParts = _aggregateRootActor.EntityType.FullName.Split('.').Reverse().ToArray(); using (Probe.Create("Aggregate", aggregateNameParts[2], aggregateNameParts[0])) { var recalculateCommands = aggregateCommands.OfType <AggregateCommand.Recalculate>() .SelectMany(next => new ICommand[] { new SyncDataObjectCommand(next.AggregateRootType, next.AggregateRootId), new ReplaceValueObjectCommand(next.AggregateRootId) }) .ToArray(); events = events.Union(_rootToLeafActor.ExecuteCommands(recalculateCommands)); var recalculatePeriodCommands = aggregateCommands.OfType <RecalculatePeriodCommand>() .SelectMany(next => new ICommand[] { new SyncPeriodCommand(next.AggregateRootType, next.Point.Date) }) .ToArray(); events = events.Union(_rootToLeafActor.ExecuteCommands(recalculatePeriodCommands)); return(events.ToArray()); } }