/// <summary>
        /// Creates a new Transaction if none are active. Otherwise, increments
        /// the subscriber count for the active transaction.
        /// </summary>
        ///
        internal void CreateOrJoin(RollbackSeverity rollbackPreference, TimeSpan timeout)
        {
            PSTransaction currentTransaction = _transactionStack.Peek();

            // There is a transaction on the stack
            if (currentTransaction != null)
            {
                // If you are already in a transaction that has been aborted, or committed,
                // create it.
                if (currentTransaction.IsRolledBack || currentTransaction.IsCommitted)
                {
                    // Clean up the "used" one
                    _transactionStack.Pop().Dispose();

                    // And add a new one to the stack
                    _transactionStack.Push(new PSTransaction(rollbackPreference, timeout));
                }
                else
                {
                    // This is a usable one. Add a subscriber to it.
                    currentTransaction.SubscriberCount++;
                }
            }
            else
            {
                // Add a new transaction to the stack
                _transactionStack.Push(new PSTransaction(rollbackPreference, timeout));
            }
        }
예제 #2
0
 internal void SetBaseTransaction(CommittableTransaction transaction, RollbackSeverity severity)
 {
     if (this.HasTransaction)
     {
         throw new InvalidOperationException(TransactionStrings.BaseTransactionMustBeFirst);
     }
     this.transactionStack.Peek();
     while ((this.transactionStack.Peek() != null) && (this.transactionStack.Peek().IsRolledBack || this.transactionStack.Peek().IsCommitted))
     {
         this.transactionStack.Pop().Dispose();
     }
     this.baseTransaction = new PSTransaction(transaction, severity);
     this.transactionStack.Push(this.baseTransaction);
 }
        /// <summary>
        /// Sets the base transaction; any transactions created thereafter will be nested to this instance
        /// </summary>
        ///
        internal void SetBaseTransaction(CommittableTransaction transaction, RollbackSeverity severity)
        {
            if (this.HasTransaction)
            {
                throw new InvalidOperationException(TransactionStrings.BaseTransactionMustBeFirst);
            }

            PSTransaction currentTransaction = _transactionStack.Peek();

            // If there is a "used" transaction at the top of the stack, clean it up
            while (_transactionStack.Peek() != null &&
                   (_transactionStack.Peek().IsRolledBack || _transactionStack.Peek().IsCommitted))
            {
                _transactionStack.Pop().Dispose();
            }

            _baseTransaction = new PSTransaction(transaction, severity);
            _transactionStack.Push(_baseTransaction);
        }
예제 #4
0
 internal void CreateOrJoin(RollbackSeverity rollbackPreference, TimeSpan timeout)
 {
     PSTransaction transaction = this.transactionStack.Peek();
     if (transaction != null)
     {
         if (transaction.IsRolledBack || transaction.IsCommitted)
         {
             this.transactionStack.Pop().Dispose();
             this.transactionStack.Push(new PSTransaction(rollbackPreference, timeout));
         }
         else
         {
             transaction.SubscriberCount++;
         }
     }
     else
     {
         this.transactionStack.Push(new PSTransaction(rollbackPreference, timeout));
     }
 }
예제 #5
0
        internal void CreateOrJoin(RollbackSeverity rollbackPreference, TimeSpan timeout)
        {
            PSTransaction transaction = this.transactionStack.Peek();

            if (transaction != null)
            {
                if (transaction.IsRolledBack || transaction.IsCommitted)
                {
                    this.transactionStack.Pop().Dispose();
                    this.transactionStack.Push(new PSTransaction(rollbackPreference, timeout));
                }
                else
                {
                    transaction.SubscriberCount++;
                }
            }
            else
            {
                this.transactionStack.Push(new PSTransaction(rollbackPreference, timeout));
            }
        }
 /// <summary>
 /// Initializes a new instance of the PSTransaction class using a CommittableTransaction
 /// </summary>
 ///
 internal PSTransaction(CommittableTransaction transaction, RollbackSeverity severity)
 {
     _transaction       = transaction;
     RollbackPreference = severity;
     _subscriberCount   = 1;
 }
 /// <summary>
 /// Creates a new Transaction that should be managed independently of
 /// any parent transactions.
 /// </summary>
 ///
 internal void CreateNew(RollbackSeverity rollbackPreference, TimeSpan timeout)
 {
     _transactionStack.Push(new PSTransaction(rollbackPreference, timeout));
 }
 /// <summary>
 /// Initializes a new instance of the PSTransaction class
 /// </summary>
 ///
 internal PSTransaction(RollbackSeverity rollbackPreference, TimeSpan timeout)
 {
     _transaction       = new CommittableTransaction(timeout);
     RollbackPreference = rollbackPreference;
     _subscriberCount   = 1;
 }
예제 #9
0
 /// <summary>
 /// Sets the base transaction for the runspace; any transactions created on this runspace will be nested to this instance
 /// </summary>
 ///<param name="transaction">The base transaction</param>
 ///<param name="severity">The severity of error that causes PowerShell to automatically rollback the transaction</param>
 ///
 public void SetBaseTransaction(System.Transactions.CommittableTransaction transaction, RollbackSeverity severity)
 {
     this.ExecutionContext.TransactionManager.SetBaseTransaction(transaction, severity);
 }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the PSTransaction class using a CommittableTransaction
 /// </summary>
 ///
 internal PSTransaction(CommittableTransaction transaction, RollbackSeverity severity)
 {
     _transaction = transaction;
     RollbackPreference = severity;
     _subscriberCount = 1;
 }
예제 #11
0
        /// <summary>
        /// Sets the base transaction; any transactions created thereafter will be nested to this instance
        /// </summary>
        ///
        internal void SetBaseTransaction(CommittableTransaction transaction, RollbackSeverity severity)
        {
            if (this.HasTransaction)
            {
                throw new InvalidOperationException(TransactionStrings.BaseTransactionMustBeFirst);
            }

            PSTransaction currentTransaction = _transactionStack.Peek();

            // If there is a "used" transaction at the top of the stack, clean it up
            while (_transactionStack.Peek() != null &&
                (_transactionStack.Peek().IsRolledBack || _transactionStack.Peek().IsCommitted))
            {
                _transactionStack.Pop().Dispose();
            }

            _baseTransaction = new PSTransaction(transaction, severity);
            _transactionStack.Push(_baseTransaction);
        }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the PSTransaction class
 /// </summary>
 ///
 internal PSTransaction(RollbackSeverity rollbackPreference, TimeSpan timeout)
 {
     _transaction = new CommittableTransaction(timeout);
     RollbackPreference = rollbackPreference;
     _subscriberCount = 1;
 }
예제 #13
0
 /// <summary>
 /// Creates a new Transaction that should be managed independently of
 /// any parent transactions.
 /// </summary>
 ///
 internal void CreateNew(RollbackSeverity rollbackPreference, TimeSpan timeout)
 {
     _transactionStack.Push(new PSTransaction(rollbackPreference, timeout));
 }
예제 #14
0
        /// <summary>
        /// Creates a new Transaction if none are active. Otherwise, increments
        /// the subscriber count for the active transaction.
        /// </summary>
        ///
        internal void CreateOrJoin(RollbackSeverity rollbackPreference, TimeSpan timeout)
        {
            PSTransaction currentTransaction = _transactionStack.Peek();

            // There is a transaction on the stack
            if (currentTransaction != null)
            {
                // If you are already in a transaction that has been aborted, or committed,
                // create it.
                if (currentTransaction.IsRolledBack || currentTransaction.IsCommitted)
                {
                    // Clean up the "used" one
                    _transactionStack.Pop().Dispose();

                    // And add a new one to the stack
                    _transactionStack.Push(new PSTransaction(rollbackPreference, timeout));
                }
                else
                {
                    // This is a usable one. Add a subscriber to it.
                    currentTransaction.SubscriberCount++;
                }
            }
            else
            {
                // Add a new transaction to the stack
                _transactionStack.Push(new PSTransaction(rollbackPreference, timeout));
            }
        }
예제 #15
0
 internal void SetBaseTransaction(CommittableTransaction transaction, RollbackSeverity severity)
 {
     if (this.HasTransaction)
     {
         throw new InvalidOperationException(TransactionStrings.BaseTransactionMustBeFirst);
     }
     this.transactionStack.Peek();
     while ((this.transactionStack.Peek() != null) && (this.transactionStack.Peek().IsRolledBack || this.transactionStack.Peek().IsCommitted))
     {
         this.transactionStack.Pop().Dispose();
     }
     this.baseTransaction = new PSTransaction(transaction, severity);
     this.transactionStack.Push(this.baseTransaction);
 }
예제 #16
0
 public void SetBaseTransaction(CommittableTransaction transaction, RollbackSeverity severity)
 {
     this.ExecutionContext.TransactionManager.SetBaseTransaction(transaction, severity);
 }