Exemplo n.º 1
0
    /// <summary>
    /// Prepares the enlited resource managers for committal.
    /// </summary>
    /// <returns><lang langref="true"/> if all polled participants voted to commit;
    /// <lang langref="false"/> otherwise.</returns>
    internal bool Prepare()
    {
      if (TransactionInformation.Status != TransactionStatus.Active)
      {
        throw new TransactionException("Cannot prepare transaction, as it is not active. Transaction Status: " +
                                       TransactionInformation.Status);
      }

      var booVoteToCommit = true;

      for (var i = m_lstNotifications.Count - 1; i >= 0; i--)
      {
        var entNotification = m_lstNotifications[i];
        var 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;
    }
Exemplo n.º 2
0
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
   preparingEnlistment.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);
              }

              for (var i = m_lstNotifications.Count - 1; i >= 0; i--)
              {
            var entNotification = m_lstNotifications[i];
            var 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;
              }
        }