private bool loadIfPossible(ListState currentState, object @event) { IEvent currentEvent = (IEvent) @event; if (currentState.currentList.id == currentEvent.aggregateId) { currentState.Load(currentEvent); return true; } if (currentState.currentList.todoItems.Any(e => e.id == currentEvent.aggregateId)) { currentState.Load(currentEvent); return true; } return false; }
/// <summary> /// Checks if two arrays of events(Transformations) commute locally. /// </summary> /// <returns> Boolean saying they commute locally. </returns> private bool commuteLocally(List<IEvent> leftEvents, List<IEvent> rightEvents, List<IEvent> previousEvents) { ListState currentState = new ListState(); ListState firstCheckState = new ListState(); ListState secondCheckState = new ListState(); // Load all current events to the states. foreach (IEvent @event in previousEvents) { currentState.Load(@event); firstCheckState.Load(@event); secondCheckState.Load(@event); } // Load all left side events on first check. foreach (IEvent message in leftEvents) { //firstCheckState.Load(message.Body); loadIfPossible(firstCheckState, message); } //Load all right side events on first check. foreach (IEvent @event in rightEvents) { loadIfPossible(firstCheckState, @event); //firstCheckState.Load(@event); } // Do it the other way around for the second check. foreach (IEvent @event in rightEvents) { //secondCheckState.Load(@event); loadIfPossible(secondCheckState, @event); } foreach (IEvent message in leftEvents) { //secondCheckState.Load(message.Body); loadIfPossible(secondCheckState, message); } // Now check if the two states are the same. return firstCheckState.Equals(secondCheckState); }
/// <summary> /// Checks if two of events(Transformations) commute locally. /// </summary> /// <returns> Boolean saying they commute locally. </returns> private bool commuteLocally(IEvent leftSideEvent, IEvent rightSideEvent, List<IEvent> previousEvents) { ListState currentState = new ListState(); ListState checkState = new ListState(); // Load all current events to the states. foreach (IEvent @event in previousEvents) { currentState.Load(@event); checkState.Load(@event); } // Load one way currentState.Load(leftSideEvent); currentState.Load(rightSideEvent); // Load other way around. checkState.Load(rightSideEvent); checkState.Load(leftSideEvent); // Now check if the two states are the same. return currentState.Equals(checkState); }
private ListState calculateOnlineListState() { ListState currState = new ListState(); foreach (IEvent @event in generatedEvents) { currState.Load(@event); } return currState; }