Exemplo n.º 1
0
        /// <summary>
        /// Aborts the current transaction, no matter how many subscribers are part of it.
        /// </summary>
        internal void Rollback(bool suppressErrors)
        {
            PSTransaction currentTransaction = _transactionStack.Peek();

            // Should not be able to roll back a transaction that is not active
            if (currentTransaction == null)
            {
                string error = TransactionStrings.NoTransactionActiveForRollback;
                throw new InvalidOperationException(error);
            }

            // If you are already in a transaction that has been aborted
            if (currentTransaction.IsRolledBack)
            {
                if (!suppressErrors)
                {
                    // Otherwise, you should not be able to roll it back.
                    string error = TransactionStrings.TransactionRolledBackForRollback;
                    throw new TransactionAbortedException(error);
                }
            }

            // See if they've already committed the transaction
            if (currentTransaction.IsCommitted)
            {
                if (!suppressErrors)
                {
                    string error = TransactionStrings.CommittedTransactionForRollback;
                    throw new InvalidOperationException(error);
                }
            }

            // Roll back the transaction if it hasn't been rolled back
            currentTransaction.SubscriberCount = 0;
            currentTransaction.Rollback();

            // Now that we've rolled back, go back to the last available transaction
            while ((_transactionStack.Count > 2) &&
                   (_transactionStack.Peek().IsRolledBack || _transactionStack.Peek().IsCommitted))
            {
                _transactionStack.Pop().Dispose();
            }
        }
Exemplo n.º 2
0
        internal void Rollback(bool suppressErrors)
        {
            PSTransaction transaction = this.transactionStack.Peek();

            if (transaction == null)
            {
                throw new InvalidOperationException(TransactionStrings.NoTransactionActiveForRollback);
            }
            if (transaction.IsRolledBack && !suppressErrors)
            {
                throw new TransactionAbortedException(TransactionStrings.TransactionRolledBackForRollback);
            }
            if (transaction.IsCommitted && !suppressErrors)
            {
                throw new InvalidOperationException(TransactionStrings.CommittedTransactionForRollback);
            }
            transaction.SubscriberCount = 0;
            transaction.Rollback();
            while ((this.transactionStack.Count > 2) && (this.transactionStack.Peek().IsRolledBack || this.transactionStack.Peek().IsCommitted))
            {
                this.transactionStack.Pop().Dispose();
            }
        }