internal void Commit() { PSTransaction transaction = this.transactionStack.Peek(); if (transaction == null) { throw new InvalidOperationException(TransactionStrings.NoTransactionActiveForCommit); } if (transaction.IsRolledBack) { throw new TransactionAbortedException(TransactionStrings.TransactionRolledBackForCommit); } if (transaction.IsCommitted) { throw new InvalidOperationException(TransactionStrings.CommittedTransactionForCommit); } if (transaction.SubscriberCount == 1) { transaction.Commit(); transaction.SubscriberCount = 0; } else { transaction.SubscriberCount--; } while ((this.transactionStack.Count > 2) && (this.transactionStack.Peek().IsRolledBack || this.transactionStack.Peek().IsCommitted)) { this.transactionStack.Pop().Dispose(); } }
/// <summary> /// Completes the current transaction. If only one subscriber is active, this /// commits the transaction. Otherwise, it reduces the subscriber count by one. /// </summary> /// internal void Commit() { PSTransaction currentTransaction = _transactionStack.Peek(); // Should not be able to commit a transaction that is not active if (currentTransaction == null) { string error = TransactionStrings.NoTransactionActiveForCommit; throw new InvalidOperationException(error); } // If you are already in a transaction that has been aborted if (currentTransaction.IsRolledBack) { string error = TransactionStrings.TransactionRolledBackForCommit; throw new TransactionAbortedException(error); } // If you are already in a transaction that has been committed if (currentTransaction.IsCommitted) { string error = TransactionStrings.CommittedTransactionForCommit; throw new InvalidOperationException(error); } if (currentTransaction.SubscriberCount == 1) { currentTransaction.Commit(); currentTransaction.SubscriberCount = 0; } else { currentTransaction.SubscriberCount--; } // Now that we've committed, go back to the last available transaction while ((_transactionStack.Count > 2) && (_transactionStack.Peek().IsRolledBack || _transactionStack.Peek().IsCommitted)) { _transactionStack.Pop().Dispose(); } }