Nexus.Transactions.Transaction.Prepare C# (CSharp) Method

Prepare() private method

Prepares the enlisted resource managers for committal.
private Prepare ( ) : bool
return bool
		internal bool Prepare()
		{
			/*if (TransactionInformation.Status == TransactionStatus.Aborted)
				return false;

			if (TransactionInformation.Status != TransactionStatus.Active)
				throw new TransactionException("Cannot prepare transaction, as it is not active. Trasnaction Status: " + TransactionInformation.Status);
			*/
			bool booVoteToCommit = true;

			PreparingEnlistment lpeEnlistment = null;
			IEnlistmentNotification entNotification = null;
			for (Int32 i = m_lstNotifications.Count - 1; i >= 0; i--)
			{
				entNotification = m_lstNotifications[i];
				lpeEnlistment = new PreparingEnlistment();
				entNotification.Prepare(lpeEnlistment);
				if (lpeEnlistment.VoteToCommit.HasValue)
				{
					booVoteToCommit &= lpeEnlistment.VoteToCommit.Value;
					if (lpeEnlistment.DoneProcessing)
						m_lstNotifications.RemoveAt(i);
				}
				else
				{
					booVoteToCommit = false;
					TransactionInformation.Status = TransactionStatus.InDoubt;
				}
			}
			if (TransactionInformation.Status == TransactionStatus.InDoubt)
				NotifyInDoubt();
			return booVoteToCommit;
		}

Usage Example

Example #1
0
        /// <summary>
        /// Completes the transaction.
        /// </summary>
        /// <remarks>
        /// This method gets votes from all the participants on whether or not the transaction should be committed.
        /// </remarks>
        public void Complete()
        {
            if (m_booCompleted)
            {
                throw new TransactionException("Complete has already been called.");
            }

            if (m_trnTransaction.TransactionInformation.Status == TransactionStatus.Aborted)
            {
                throw new TransactionAbortedException("Cannot complete a transaction scope when transaction has already been aborted.");
            }

            if (m_booOwnsTransaction)
            {
                bool booVotedToCommit = false;
                booVotedToCommit = m_trnTransaction.Prepare();
                if (booVotedToCommit && (m_trnTransaction.TransactionInformation.Status == TransactionStatus.Active))
                {
                    m_trnTransaction.Commit();
                }
            }
            m_booCompleted = true;
        }