System.Transactions.TransactionStatePhase0.EnlistPromotableSinglePhase C# (CSharp) Method

EnlistPromotableSinglePhase() private method

private EnlistPromotableSinglePhase ( InternalTransaction tx, IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Transaction atomicTransaction, System.Guid promoterType ) : bool
tx InternalTransaction
promotableSinglePhaseNotification IPromotableSinglePhaseNotification
atomicTransaction Transaction
promoterType System.Guid
return bool
        internal override bool EnlistPromotableSinglePhase(
            InternalTransaction tx,
            IPromotableSinglePhaseNotification promotableSinglePhaseNotification,
            Transaction atomicTransaction,
            Guid promoterType
            )
        {
            // Delegation will fail if there is a durable enlistment
            if (tx._durableEnlistment != null)
            {
                return false;
            }

            // Initialize PSPE Operation and call initialize on IPromotableSinglePhaseNotification
            TransactionStatePSPEOperation.Phase0PSPEInitialize(tx, promotableSinglePhaseNotification, promoterType);

            // Create a durable enlistment.
            Enlistment en = new Enlistment(tx, promotableSinglePhaseNotification, atomicTransaction);
            tx._durableEnlistment = en.InternalEnlistment;
            TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log;
            if (etwLog.IsEnabled())
            {
                etwLog.TransactionstateEnlist(tx._durableEnlistment.EnlistmentTraceId, EnlistmentType.PromotableSinglePhase, EnlistmentOptions.None);
            }

            // Specify the promoter for the transaction.
            tx._promoter = promotableSinglePhaseNotification;

            // Change the state that the transaction will promote to.  Normally this would be simply
            // be TransactionStatePromoted.  However it now needs to promote to a delegated state.
            // If the PromoterType is NOT TransactionInterop.PromoterTypeDtc, then the promoteState needs
            // to be TransactionStateDelegatedNonMSDTC.
            // tx.PromoterType was set in Phase0PSPEInitialize.
            Debug.Assert(tx._promoterType != Guid.Empty, "InternalTransaction.PromoterType was not set in Phase0PSPEInitialize");
            if (tx._promoterType == TransactionInterop.PromoterTypeDtc)
            {
                tx._promoteState = TransactionStateDelegated;
            }
            else
            {
                tx._promoteState = TransactionStateDelegatedNonMSDTC;
            }

            // Put the enlistment in an active state
            DurableEnlistmentState.DurableEnlistmentActive.EnterState(tx._durableEnlistment);

            // Hand back the enlistment.
            return true;
        }