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

EnlistPromotableSinglePhase() public method

Create a promotable single phase enlistment that promotes to a distributed transaction manager other than MSDTC.
public EnlistPromotableSinglePhase ( IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Guid promoterType ) : bool
promotableSinglePhaseNotification IPromotableSinglePhaseNotification The object that implements the IPromotableSinglePhaseNotification interface.
promoterType Guid /// The promoter type Guid that identifies the format of the byte[] that is returned by the ITransactionPromoter.Promote /// call that is implemented by the IPromotableSinglePhaseNotificationObject, and thus the promoter of the transaction. ///
return bool
        public bool EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Guid promoterType)
        {
            TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log;
            if (etwLog.IsEnabled())
            {
                etwLog.MethodEnter(TraceSourceType.TraceSourceLtm, this);
            }

            if (Disposed)
            {
                throw new ObjectDisposedException(nameof(Transaction));
            }

            if (promotableSinglePhaseNotification == null)
            {
                throw new ArgumentNullException(nameof(promotableSinglePhaseNotification));
            }

            if (promoterType == Guid.Empty)
            {
                throw new ArgumentException(SR.PromoterTypeInvalid, nameof(promoterType));
            }

            if (_complete)
            {
                throw TransactionException.CreateTransactionCompletedException(DistributedTxId);
            }

            bool succeeded = false;

            lock (_internalTransaction)
            {
                succeeded = _internalTransaction.State.EnlistPromotableSinglePhase(_internalTransaction, promotableSinglePhaseNotification, this, promoterType);
            }

            if (etwLog.IsEnabled())
            {
                etwLog.MethodExit(TraceSourceType.TraceSourceLtm, this);
            }

            return succeeded;
        }

Same methods

Transaction::EnlistPromotableSinglePhase ( IPromotableSinglePhaseNotification promotableSinglePhaseNotification ) : bool
Transaction::EnlistPromotableSinglePhase ( System promotableSinglePhaseNotification ) : bool
Transaction::EnlistPromotableSinglePhase ( System promotableSinglePhaseNotification, System promoterType ) : bool

Usage Example

        private void Enlist(Transaction transaction)
        {
            if (transaction == null)
            {
                // no enlistment as we are not in a TransactionScope
                return;
            }

            // try to enlist as a PSPE
            if (!transaction.EnlistPromotableSinglePhase(this))
            {
                // our enlistmente fail so we need to enlist ourselves as durable.

                // we create a transaction directly instead of using BeginTransaction that GraphClient
                // doesn't store it in its stack of scopes.
                 var localTransaction = new Neo4jTransaction(_client);
                localTransaction.ForceKeepAlive();
                _transactionId = localTransaction.Id;
                var resourceManager = GetResourceManager();
                var propagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
                var transactionExecutionEnvironment = new TransactionExecutionEnvironment(_client.ExecutionConfiguration)
                {
                    TransactionId =  localTransaction.Id,
                    TransactionBaseEndpoint = _client.TransactionEndpoint
                };
                resourceManager.Enlist(transactionExecutionEnvironment, propagationToken);
                localTransaction.Cancel();
            }

            _enlistedInTransactions.Add(transaction);
        }
All Usage Examples Of System.Transactions.Transaction::EnlistPromotableSinglePhase