This class is used to communicate with enlistments.
Inheritance: Enlistment
Exemplo n.º 1
0
		/// <summary>
		/// Prepares the enlisted resource managers for committal.
		/// </summary>
		/// <returns><c>true</c> if all polled participants voted to commit;
		/// <c>false</c> otherwise.</returns>
		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;
		}
			/// <summary>
			/// Used to notify an enlisted resource manager that the transaction is being prepared for commitment.
			/// </summary>
			/// <param name="p_entPreparingEnlistment">The enlistment class used to communicate with the resource manager.</param>
			public void Prepare(PreparingEnlistment p_entPreparingEnlistment)
			{
				p_entPreparingEnlistment.Prepared();
			}
Exemplo n.º 3
0
		/// <summary>
		/// Tells al participanting resource managers to commit their changes.
		/// </summary>
		internal void Commit()
		{
			if (TransactionInformation.Status != TransactionStatus.Active)
				throw new TransactionException("Cannot commit transaction, as it is not active. Trasnaction Status: " + TransactionInformation.Status);

			PreparingEnlistment lpeEnlistment = null;
			IEnlistmentNotification entNotification = null;
			for (Int32 i = m_lstNotifications.Count - 1; i >= 0; i--)
			{
				entNotification = m_lstNotifications[i];
				lpeEnlistment = new PreparingEnlistment();
				entNotification.Commit(lpeEnlistment);
				if (lpeEnlistment.DoneProcessing)
					m_lstNotifications.RemoveAt(i);
			}
			if (m_lstNotifications.Count > 0)
			{
				TransactionInformation.Status = TransactionStatus.InDoubt;
				NotifyInDoubt();
			}
			else
				TransactionInformation.Status = TransactionStatus.Committed;
		}