public AggregateDependency PickDefinitions(IDictionary <Type, Sequence> sequences, params Type[] types) { var allEvents = types.SelectMany(t => t.GetMethods().Where(m => m.Name == "When")).Select( m => m.GetParameters()[0].ParameterType).ToArray(); var dependency = new AggregateDependency { Aggregates = types.Select(t => t.Name.TrimStart('I').Replace("AggregateState", "")).ToArray(), Events = allEvents.Select(e => e.Name).ToArray(), }; var discoveredCommands = new HashSet <Type>(); foreach (var sequence in sequences.Values) { foreach (var eventType in allEvents) { if (sequence.EventTypes.Contains(eventType.Name)) { // intersection discoveredCommands.Add(sequence.Command); } } } foreach (var type in discoveredCommands) { var discoveredSequence = new DiscoveredSequence { WhenCommand = type.Name, ThenEvents = sequences[type].EventTypes.ToArray(), Cases = sequences[type].Specs }; dependency.Sequence.Add(discoveredSequence); sequences.Remove(type); } return(dependency); }
public AggregateDependency PickDefinitions(IDictionary<Type, Sequence> sequences, params Type[] types) { var allEvents = types.SelectMany(t => t.GetMethods().Where(m => m.Name == "When")).Select( m => m.GetParameters()[0].ParameterType).ToArray(); var dependency = new AggregateDependency { Aggregates = types.Select(t => t.Name.TrimStart('I').Replace("AggregateState", "")).ToArray(), Events = allEvents.Select(e => e.Name).ToArray(), }; var discoveredCommands = new HashSet<Type>(); foreach (var sequence in sequences.Values) { foreach (var eventType in allEvents) { if (sequence.Events.Contains(eventType)) { // intersection discoveredCommands.Add(sequence.Command); } } } foreach (var type in discoveredCommands) { var discoveredSequence = new DiscoveredSequence { WhenCommand = type.Name, ThenEvents = sequences[type].Events.Select(t => t.Name).ToArray(), Cases = sequences[type].Specs }; dependency.Sequence.Add(discoveredSequence); sequences.Remove(type); } return dependency; }