private IInvokableTransaction InnerCreateTransaction(string undoActionName) { IInvokableTransaction transaction = this.transactionFactory.CreateTransaction(this); transaction.ActionName = undoActionName; this.openTransactions.Push(transaction); return(transaction); }
/// <summary> /// Rollbacks the open transaction and invokes the regsitered undo operations. /// </summary> /// <exception cref="ActionInvokationException">An error occured while invoking the undo operations within the open transaction.</exception> public void RollbackTransactions() { if (!this.openTransactions.Any()) { throw new InvalidOperationException("There is no open transaction available to roll back."); } IInvokableTransaction transaction = this.openTransactions.First(); transaction.Rollback(); }
/// <summary> /// Commits the open transactions and records the registered undo operations in the <see cref="IUndoManager"/>. /// </summary> /// <exception cref="InvalidOperationException">No open <see cref="ITransaction"/> to commit available.</exception> public void CommitTransactions() { if (!this.openTransactions.Any()) { throw new InvalidOperationException("There is no open transaction available to commit."); } IInvokableTransaction transaction = this.openTransactions.First(); transaction.Commit(); }
/// <summary> /// Invokes the last recorded redo operation or transaction. /// </summary> /// <exception cref="ActionInvokationException">An error occured while invoking the registered redo operation.</exception> public void Redo() { if (!this.redoHistory.Any()) { throw new InvalidOperationException("No redo operations recorded."); } using (new StateSwitcher(this, UndoRedoState.Redoing)) { IInvokableTransaction invocableToRedo = this.redoHistory.Pop(); using (this.InnerCreateTransaction(invocableToRedo.ActionName)) { InvokeInvocation(invocableToRedo); } } }
/// <summary> /// Rollbacks the provided transaction. /// </summary> /// <param name="transaction">The transaction to roll back.</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> /// <exception cref="ActionInvokationException">An error occured while invoking the undo operations within the transaction.</exception> void ITransactionManager.RollbackTransaction(IInvokableTransaction transaction) { if (transaction == null) { throw new ArgumentNullException("transaction"); } if (!this.openTransactions.Contains(transaction)) { throw new ArgumentException("Can not find the transaction to roll back", "transaction"); } while (this.openTransactions.Contains(transaction)) { IInvokableTransaction toRollback = this.openTransactions.Pop(); toRollback.Rollback(); } }
/// <summary> /// Registers an <see cref="IInvokable"/> implementation to the <see cref="ITransaction"/>. /// </summary> /// <param name="invokation">The invokation to register.</param> /// <exception cref="ArgumentNullException"><paramref name="invokation"/> is a <see langword="null"/> reference.</exception> public void RegisterInvokation(IInvokable invokation) { if (invokation == null) { throw new ArgumentNullException("invokation"); } if (this.state != UndoRedoState.RollingBack) { IInvokableTransaction recordingTransaction = this.FetchRecordingTransaction(); if (recordingTransaction != null) { recordingTransaction.RegisterInvokation(invokation); } else { using (IInvokableTransaction transaction = this.InnerCreateTransaction(string.Empty)) { transaction.RegisterInvokation(invokation); } } } }
/// <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); } } } } }
public void RollbackTransaction(IInvokableTransaction transaction) { Assert.NotNull(transaction); this.RollbackCalled = true; }
public void CommitTransaction(IInvokableTransaction transaction) { Assert.NotNull(transaction); this.CommitCalled = true; }