/// <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));
            }
        }
        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();
            }
        }
 internal void ClearBaseTransaction()
 {
     if (this.baseTransaction == null)
     {
         throw new InvalidOperationException(TransactionStrings.BaseTransactionNotSet);
     }
     if (this.transactionStack.Peek() != this.baseTransaction)
     {
         throw new InvalidOperationException(TransactionStrings.BaseTransactionNotActive);
     }
     this.transactionStack.Pop().Dispose();
     this.baseTransaction = null;
 }
 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);
 }
 public void Dispose(bool disposing)
 {
     if (disposing)
     {
         this.ResetActive();
         while (this.transactionStack.Peek() != null)
         {
             PSTransaction transaction = this.transactionStack.Pop();
             if (transaction != this.baseTransaction)
             {
                 transaction.Dispose();
             }
         }
     }
 }
        internal void SetActive()
        {
            EnableEngineProtection();
            PSTransaction transaction = this.transactionStack.Peek();

            if (transaction == null)
            {
                throw new InvalidOperationException(TransactionStrings.NoTransactionForActivation);
            }
            if (transaction.IsRolledBack)
            {
                throw new TransactionAbortedException(TransactionStrings.NoTransactionForActivationBecauseRollback);
            }
            this.previousActiveTransaction = Transaction.Current;
            transaction.Activate();
        }
        public void Dispose(bool disposing)
        {
            if (disposing)
            {
                ResetActive();

                while (_transactionStack.Peek() != null)
                {
                    PSTransaction currentTransaction = _transactionStack.Pop();

                    if (currentTransaction != _baseTransaction)
                    {
                        currentTransaction.Dispose();
                    }
                }
            }
        }
        /// <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);
        }
        /// <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();
            }
        }
        /// <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();
            }
        }
示例#11
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));
            }
        }
示例#12
0
        public List <PSTransaction> GetPSTransactions(int PastDays)
        {
            List <PSTransaction> olist = new List <PSTransaction>();

            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select v1.SALE_DATE ");
                sb.Append(", v2.SERIAL_NO as TransactionID ");
                sb.Append(", v2.STOCK_CODE, v2.DESCRIPT ");
                sb.Append(", v2.AMOUNT ");
                sb.Append(" from SALEHEAD v1 ");
                sb.Append(" inner join SALELINE v2 on v1.SALE_NO=v2.SALE_NO ");
                sb.Append(" where DATEDIFF(DAY,v1.SD, GETDATE())<=" + PastDays);
                sb.Append(" and v2.SERIAL_NO<>''");

                DataTable dt = GetRecords(sb.ToString(), DataSource.CSCTills);
                if (dt.Rows.Count == 0)
                {
                    return(null);
                }
                PSTransaction pt;

                foreach (DataRow dr in dt.Rows)
                {
                    pt = new PSTransaction();
                    pt.TransactionID = dr["TransactionID"].ToString();
                    pt.SALE_DATE     = string.Format("{0:MM-dd-yyyy}", (DateTime)dr["SALE_DATE"]);
                    pt.STOCK_CODE    = dr["STOCK_CODE"].ToString();
                    pt.DESCRIPT      = dr["DESCRIPT"].ToString();
                    pt.Amount        = string.Format("{0:0.00}", (Single)dr["AMOUNT"]);
                    olist.Add(pt);
                }
            }
            catch (Exception ex)
            {
                _performancelog.Error("PaymentSourceService.GetPSTransactions(): " + ex.Message);
            }
            return(olist);
        }
示例#13
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();
            }
        }
        /// <summary>
        /// Activates the current transaction, both in the engine, and in the Ambient.
        /// </summary>
        ///
        internal void SetActive()
        {
            PSTransactionManager.EnableEngineProtection();

            PSTransaction currentTransaction = _transactionStack.Peek();

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

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

            _previousActiveTransaction = Transaction.Current;
            currentTransaction.Activate();
        }
示例#15
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);
        }