/// <summary> /// Commits the provided transaction. /// </summary> /// <param name="transaction">The transaction to commit.</param> /// <exception cref="ArgumentNullException"><paramref name="transaction"/> is a <see langword="null"/> reference.</exception> /// <exception cref="ArgumentException">The <see cref="UndoManager"/> does not contain <paramref name="transaction"/>.</exception> void ITransactionManager.CommitTransaction(IInvokableTransaction transaction) { if (transaction == null) { throw new ArgumentNullException("transaction"); } if (!this.openTransactions.Contains(transaction)) { throw new ArgumentException("Cannot find the transaction to commit", "transaction"); } // only switch the state to committing if the undo manager is not doing another task (e.g. undoing). UndoRedoState currentState = this.state == UndoRedoState.Idle ? UndoRedoState.Committing : this.state; using (new StateSwitcher(this, currentState)) { while (this.openTransactions.Contains(transaction)) { IInvokableTransaction toCommit = this.openTransactions.Pop(); if (toCommit.Any()) { if (toCommit.Equals(transaction)) { Stack <IInvokableTransaction> history = this.IsUndoing ? this.redoHistory : this.undoHistory; history.Push(transaction); } else { IInvokableTransaction topMost = this.openTransactions.Peek(); topMost.RegisterInvokation(toCommit); } } } } }