/// <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 List<IEvent> removeRedundantEvents(List<IEvent> events) { List<IEvent> returnList = new List<IEvent>(); ListState finalState = new ListState(); //Load the normal final state of all the events. finalState.LoadList(allPreviousEvents); finalState.LoadList(events); foreach (IEvent @event in events) { if (@event == null) break; returnList.Add(@event); ListState checkState = new ListState(); checkState.LoadList(allPreviousEvents); // Load a stat without the current event. IEnumerable<IEvent> without = events.Where(e => !(e.Equals(@event))); List<IEvent> withoutList = without.ToList(); checkState.LoadList(without.ToList()); // Check if it is the same as the final state. if (checkState.Equals(finalState)) { Debug.WriteLine("Redundant operation found!!!"); returnList.Remove(@event); } } return returnList; }
/// <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); }