Beispiel #1
0
        void IPromotedEnlistment.EnlistmentDone()
        {
            if (DiagnosticTrace.Verbose)
            {
                MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxEnlistment.EnlistmentDone");
                EnlistmentCallbackPositiveTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), base.InternalTraceIdentifier, EnlistmentCallback.Done);
            }
            OletxVolatileEnlistmentState     active    = OletxVolatileEnlistmentState.Active;
            OletxVolatileEnlistmentContainer container = null;

            lock (this)
            {
                active    = this.state;
                container = this.container;
                if ((((this.state != OletxVolatileEnlistmentState.Active) && (OletxVolatileEnlistmentState.Preparing != this.state)) && ((OletxVolatileEnlistmentState.Aborting != this.state) && (OletxVolatileEnlistmentState.Committing != this.state))) && (OletxVolatileEnlistmentState.InDoubt != this.state))
                {
                    throw TransactionException.CreateEnlistmentStateException(System.Transactions.SR.GetString("TraceSourceOletx"), null);
                }
                this.state = OletxVolatileEnlistmentState.Done;
            }
            if ((OletxVolatileEnlistmentState.Preparing == active) && (container != null))
            {
                container.DecrementOutstandingNotifications(true);
            }
            if (DiagnosticTrace.Verbose)
            {
                MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxEnlistment.EnlistmentDone");
            }
        }
Beispiel #2
0
        internal void Prepare(OletxVolatileEnlistmentContainer container)
        {
            OletxVolatileEnlistmentState    active = OletxVolatileEnlistmentState.Active;
            IEnlistmentNotificationInternal iEnlistmentNotification = null;

            lock (this)
            {
                iEnlistmentNotification = this.iEnlistmentNotification;
                if (this.state == OletxVolatileEnlistmentState.Active)
                {
                    active = this.state = OletxVolatileEnlistmentState.Preparing;
                }
                else
                {
                    active = this.state;
                }
                this.container = container;
            }
            if (OletxVolatileEnlistmentState.Preparing == active)
            {
                if (iEnlistmentNotification != null)
                {
                    if (DiagnosticTrace.Verbose)
                    {
                        EnlistmentNotificationCallTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), base.InternalTraceIdentifier, NotificationCall.Prepare);
                    }
                    iEnlistmentNotification.Prepare(this);
                    return;
                }
                if (DiagnosticTrace.Critical)
                {
                    InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                }
                throw new InvalidOperationException(System.Transactions.SR.GetString("InternalError"));
            }
            if (OletxVolatileEnlistmentState.Done == active)
            {
                container.DecrementOutstandingNotifications(true);
            }
            else if ((OletxVolatileEnlistmentState.Prepared == active) && this.enlistDuringPrepareRequired)
            {
                container.DecrementOutstandingNotifications(true);
            }
            else if ((OletxVolatileEnlistmentState.Aborting == active) || (OletxVolatileEnlistmentState.Aborted == active))
            {
                container.DecrementOutstandingNotifications(false);
            }
            else
            {
                if (DiagnosticTrace.Critical)
                {
                    InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                }
                throw new InvalidOperationException(System.Transactions.SR.GetString("InternalError"));
            }
        }
 internal OletxVolatileEnlistment(IEnlistmentNotificationInternal enlistmentNotification, EnlistmentOptions enlistmentOptions, OletxTransaction oletxTransaction) : base(null, oletxTransaction)
 {
     this.iEnlistmentNotification = enlistmentNotification;
     this.enlistDuringPrepareRequired = (enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != EnlistmentOptions.None;
     this.container = null;
     this.pendingOutcome = TransactionStatus.Active;
     if (DiagnosticTrace.Information)
     {
         EnlistmentTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), base.InternalTraceIdentifier, EnlistmentType.Volatile, enlistmentOptions);
     }
 }
Beispiel #4
0
        void IPromotedEnlistment.Prepared()
        {
            if (DiagnosticTrace.Verbose)
            {
                MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxPreparingEnlistment.Prepared");
                EnlistmentCallbackPositiveTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), base.InternalTraceIdentifier, EnlistmentCallback.Prepared);
            }
            OletxVolatileEnlistmentContainer container = null;
            TransactionStatus active = TransactionStatus.Active;

            lock (this)
            {
                if (OletxVolatileEnlistmentState.Preparing != this.state)
                {
                    throw TransactionException.CreateEnlistmentStateException(System.Transactions.SR.GetString("TraceSourceOletx"), null);
                }
                this.state = OletxVolatileEnlistmentState.Prepared;
                active     = this.pendingOutcome;
                if (this.container == null)
                {
                    if (DiagnosticTrace.Critical)
                    {
                        InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                    }
                    throw new InvalidOperationException(System.Transactions.SR.GetString("InternalError"));
                }
                container = this.container;
            }
            container.DecrementOutstandingNotifications(true);
            switch (active)
            {
            case TransactionStatus.Active:
                break;

            case TransactionStatus.Aborted:
                this.Rollback();
                break;

            case TransactionStatus.InDoubt:
                this.InDoubt();
                break;

            default:
                if (DiagnosticTrace.Critical)
                {
                    InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                }
                throw new InvalidOperationException(System.Transactions.SR.GetString("InternalError"));
            }
            if (DiagnosticTrace.Verbose)
            {
                MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxPreparingEnlistment.Prepared");
            }
        }
Beispiel #5
0
 internal OletxVolatileEnlistment(IEnlistmentNotificationInternal enlistmentNotification, EnlistmentOptions enlistmentOptions, OletxTransaction oletxTransaction) : base(null, oletxTransaction)
 {
     this.iEnlistmentNotification     = enlistmentNotification;
     this.enlistDuringPrepareRequired = (enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != EnlistmentOptions.None;
     this.container      = null;
     this.pendingOutcome = TransactionStatus.Active;
     if (DiagnosticTrace.Information)
     {
         EnlistmentTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), base.InternalTraceIdentifier, EnlistmentType.Volatile, enlistmentOptions);
     }
 }
 internal OletxDependentTransaction(RealOletxTransaction realTransaction, bool delayCommit) : base(realTransaction)
 {
     if (realTransaction == null)
     {
         throw new ArgumentNullException("realTransaction");
     }
     this.volatileEnlistmentContainer = base.realOletxTransaction.AddDependentClone(delayCommit);
     if (DiagnosticTrace.Information)
     {
         DependentCloneCreatedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), base.TransactionTraceId, delayCommit ? DependentCloneOption.BlockCommitUntilComplete : DependentCloneOption.RollbackIfNotComplete);
     }
 }
 internal OletxDependentTransaction(RealOletxTransaction realTransaction, bool delayCommit) : base(realTransaction)
 {
     if (realTransaction == null)
     {
         throw new ArgumentNullException("realTransaction");
     }
     this.volatileEnlistmentContainer = base.realOletxTransaction.AddDependentClone(delayCommit);
     if (DiagnosticTrace.Information)
     {
         DependentCloneCreatedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), base.TransactionTraceId, delayCommit ? DependentCloneOption.BlockCommitUntilComplete : DependentCloneOption.RollbackIfNotComplete);
     }
 }
Beispiel #8
0
        void IPromotedEnlistment.ForceRollback(Exception e)
        {
            if (DiagnosticTrace.Verbose)
            {
                MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxPreparingEnlistment.ForceRollback");
            }
            if (DiagnosticTrace.Warning)
            {
                EnlistmentCallbackNegativeTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), base.InternalTraceIdentifier, EnlistmentCallback.ForceRollback);
            }
            OletxVolatileEnlistmentContainer container = null;

            lock (this)
            {
                if (OletxVolatileEnlistmentState.Preparing != this.state)
                {
                    throw TransactionException.CreateEnlistmentStateException(System.Transactions.SR.GetString("TraceSourceOletx"), null);
                }
                this.state = OletxVolatileEnlistmentState.Done;
                if (this.container == null)
                {
                    if (DiagnosticTrace.Critical)
                    {
                        InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                    }
                    throw new InvalidOperationException(System.Transactions.SR.GetString("InternalError"));
                }
                container = this.container;
            }
            Interlocked.CompareExchange <Exception>(ref base.oletxTransaction.realOletxTransaction.innerException, e, null);
            container.DecrementOutstandingNotifications(false);
            if (DiagnosticTrace.Verbose)
            {
                MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxPreparingEnlistment.ForceRollback");
            }
        }
        void IPromotedEnlistment.Prepared()
        {
            if (DiagnosticTrace.Verbose)
            {
                MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxPreparingEnlistment.Prepared");
                EnlistmentCallbackPositiveTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), base.InternalTraceIdentifier, EnlistmentCallback.Prepared);
            }
            OletxVolatileEnlistmentContainer container = null;
            TransactionStatus active = TransactionStatus.Active;
            lock (this)
            {
                if (OletxVolatileEnlistmentState.Preparing != this.state)
                {
                    throw TransactionException.CreateEnlistmentStateException(System.Transactions.SR.GetString("TraceSourceOletx"), null);
                }
                this.state = OletxVolatileEnlistmentState.Prepared;
                active = this.pendingOutcome;
                if (this.container == null)
                {
                    if (DiagnosticTrace.Critical)
                    {
                        InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                    }
                    throw new InvalidOperationException(System.Transactions.SR.GetString("InternalError"));
                }
                container = this.container;
            }
            container.DecrementOutstandingNotifications(true);
            switch (active)
            {
                case TransactionStatus.Active:
                    break;

                case TransactionStatus.Aborted:
                    this.Rollback();
                    break;

                case TransactionStatus.InDoubt:
                    this.InDoubt();
                    break;

                default:
                    if (DiagnosticTrace.Critical)
                    {
                        InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                    }
                    throw new InvalidOperationException(System.Transactions.SR.GetString("InternalError"));
            }
            if (DiagnosticTrace.Verbose)
            {
                MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxPreparingEnlistment.Prepared");
            }
        }
 void IPromotedEnlistment.ForceRollback(Exception e)
 {
     if (DiagnosticTrace.Verbose)
     {
         MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxPreparingEnlistment.ForceRollback");
     }
     if (DiagnosticTrace.Warning)
     {
         EnlistmentCallbackNegativeTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), base.InternalTraceIdentifier, EnlistmentCallback.ForceRollback);
     }
     OletxVolatileEnlistmentContainer container = null;
     lock (this)
     {
         if (OletxVolatileEnlistmentState.Preparing != this.state)
         {
             throw TransactionException.CreateEnlistmentStateException(System.Transactions.SR.GetString("TraceSourceOletx"), null);
         }
         this.state = OletxVolatileEnlistmentState.Done;
         if (this.container == null)
         {
             if (DiagnosticTrace.Critical)
             {
                 InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
             }
             throw new InvalidOperationException(System.Transactions.SR.GetString("InternalError"));
         }
         container = this.container;
     }
     Interlocked.CompareExchange<Exception>(ref base.oletxTransaction.realOletxTransaction.innerException, e, null);
     container.DecrementOutstandingNotifications(false);
     if (DiagnosticTrace.Verbose)
     {
         MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxPreparingEnlistment.ForceRollback");
     }
 }
 void IPromotedEnlistment.EnlistmentDone()
 {
     if (DiagnosticTrace.Verbose)
     {
         MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxEnlistment.EnlistmentDone");
         EnlistmentCallbackPositiveTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), base.InternalTraceIdentifier, EnlistmentCallback.Done);
     }
     OletxVolatileEnlistmentState active = OletxVolatileEnlistmentState.Active;
     OletxVolatileEnlistmentContainer container = null;
     lock (this)
     {
         active = this.state;
         container = this.container;
         if ((((this.state != OletxVolatileEnlistmentState.Active) && (OletxVolatileEnlistmentState.Preparing != this.state)) && ((OletxVolatileEnlistmentState.Aborting != this.state) && (OletxVolatileEnlistmentState.Committing != this.state))) && (OletxVolatileEnlistmentState.InDoubt != this.state))
         {
             throw TransactionException.CreateEnlistmentStateException(System.Transactions.SR.GetString("TraceSourceOletx"), null);
         }
         this.state = OletxVolatileEnlistmentState.Done;
     }
     if ((OletxVolatileEnlistmentState.Preparing == active) && (container != null))
     {
         container.DecrementOutstandingNotifications(true);
     }
     if (DiagnosticTrace.Verbose)
     {
         MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxEnlistment.EnlistmentDone");
     }
 }
 internal void Prepare(OletxVolatileEnlistmentContainer container)
 {
     OletxVolatileEnlistmentState active = OletxVolatileEnlistmentState.Active;
     IEnlistmentNotificationInternal iEnlistmentNotification = null;
     lock (this)
     {
         iEnlistmentNotification = this.iEnlistmentNotification;
         if (this.state == OletxVolatileEnlistmentState.Active)
         {
             active = this.state = OletxVolatileEnlistmentState.Preparing;
         }
         else
         {
             active = this.state;
         }
         this.container = container;
     }
     if (OletxVolatileEnlistmentState.Preparing == active)
     {
         if (iEnlistmentNotification != null)
         {
             if (DiagnosticTrace.Verbose)
             {
                 EnlistmentNotificationCallTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), base.InternalTraceIdentifier, NotificationCall.Prepare);
             }
             iEnlistmentNotification.Prepare(this);
             return;
         }
         if (DiagnosticTrace.Critical)
         {
             InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
         }
         throw new InvalidOperationException(System.Transactions.SR.GetString("InternalError"));
     }
     if (OletxVolatileEnlistmentState.Done == active)
     {
         container.DecrementOutstandingNotifications(true);
     }
     else if ((OletxVolatileEnlistmentState.Prepared == active) && this.enlistDuringPrepareRequired)
     {
         container.DecrementOutstandingNotifications(true);
     }
     else if ((OletxVolatileEnlistmentState.Aborting == active) || (OletxVolatileEnlistmentState.Aborted == active))
     {
         container.DecrementOutstandingNotifications(false);
     }
     else
     {
         if (DiagnosticTrace.Critical)
         {
             InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
         }
         throw new InvalidOperationException(System.Transactions.SR.GetString("InternalError"));
     }
 }
Beispiel #13
0
        internal void Prepare( OletxVolatileEnlistmentContainer container )
        {
            OletxVolatileEnlistmentState localState = OletxVolatileEnlistmentState.Active;
            IEnlistmentNotificationInternal localEnlistmentNotification = null;

            lock ( this )
            {
                localEnlistmentNotification = iEnlistmentNotification;

                // The app may have already called EnlistmentDone.  If this occurs, don't bother sending
                // the notification to the app.
                if ( OletxVolatileEnlistmentState.Active == state )
                {
                    localState = state = OletxVolatileEnlistmentState.Preparing;
                }
                else
                {
                    localState = state;
                }
                this.container = container;

            }

            // Tell the application to do the work.
            if ( OletxVolatileEnlistmentState.Preparing == localState )
            {
                if ( null != localEnlistmentNotification )
                {
                    if ( DiagnosticTrace.Verbose )
                    {
                        EnlistmentNotificationCallTraceRecord.Trace( SR.GetString( SR.TraceSourceOletx ),
                            this.InternalTraceIdentifier,
                            NotificationCall.Prepare
                            );
                    }

                    localEnlistmentNotification.Prepare( this );
                }
                else
                {
                    if ( DiagnosticTrace.Critical )
                    {
                        InternalErrorTraceRecord.Trace( SR.GetString( SR.TraceSourceOletx ),
                            ""
                            );
                    }

                    Debug.Assert( false, "OletxVolatileEnlistment.Prepare, no enlistmentNotification member." );
                    throw new InvalidOperationException( SR.GetString( SR.InternalError ) );
                }
            }
            else if ( OletxVolatileEnlistmentState.Done == localState )
            {
                // Voting yes because it was an early read-only vote.
                container.DecrementOutstandingNotifications( true );

                // We must have had a ---- between EnlistmentDone and the proxy telling
                // us Phase0Request.  Just return.
                return;
            }
            // It is okay to be in Prepared state if we are edpr=true because we already
            // did our prepare in Phase0.
            else if ( ( OletxVolatileEnlistmentState.Prepared == localState ) &&
                        ( this.enlistDuringPrepareRequired ) )
            {
                container.DecrementOutstandingNotifications( true );
                return;
            }
            else if ( ( OletxVolatileEnlistmentState.Aborting == localState ) ||
                      ( OletxVolatileEnlistmentState.Aborted == localState ) )
            {
                // An abort has ----d with this volatile Prepare
                // decrement the outstanding notifications making sure to vote no.
                container.DecrementOutstandingNotifications( false );
                return;
            }
            else
            {
                if ( DiagnosticTrace.Critical )
                {
                    InternalErrorTraceRecord.Trace( SR.GetString( SR.TraceSourceOletx ),
                        ""
                        );
                }

                Debug.Assert( false, "OletxVolatileEnlistment.Prepare, invalid state." );
                throw new InvalidOperationException( SR.GetString( SR.InternalError ) );
            }

        }
Beispiel #14
0
        internal OletxVolatileEnlistment(
            IEnlistmentNotificationInternal enlistmentNotification,
            EnlistmentOptions enlistmentOptions,
            OletxTransaction oletxTransaction
            ) : base( null, oletxTransaction )
        {
            this.iEnlistmentNotification = enlistmentNotification;
            this.enlistDuringPrepareRequired = (enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != 0;

            // We get a container when we are asked to vote.
            this.container = null;

            pendingOutcome = TransactionStatus.Active;

            if ( DiagnosticTrace.Information )
            {
                EnlistmentTraceRecord.Trace( SR.GetString( SR.TraceSourceOletx ),
                    this.InternalTraceIdentifier,
                    EnlistmentType.Volatile,
                    enlistmentOptions
                    );
            }
        }
        internal OletxVolatileEnlistmentContainer AddDependentClone(bool delayCommit)
        {
            IVoterBallotShim      voterBallotShim = null;
            IPhase0EnlistmentShim shim2           = null;
            bool flag2 = false;
            bool flag  = false;
            OletxVolatileEnlistmentContainer       container3 = null;
            OletxPhase0VolatileEnlistmentContainer container  = null;
            OletxPhase1VolatileEnlistmentContainer target     = null;
            bool   flag3 = false;
            bool   flag5 = false;
            IntPtr zero  = IntPtr.Zero;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                lock (this)
                {
                    if (delayCommit)
                    {
                        if (this.phase0EnlistVolatilementContainerList == null)
                        {
                            this.phase0EnlistVolatilementContainerList = new ArrayList(1);
                        }
                        if (this.phase0EnlistVolatilementContainerList.Count == 0)
                        {
                            container = new OletxPhase0VolatileEnlistmentContainer(this);
                            flag      = true;
                        }
                        else
                        {
                            container = this.phase0EnlistVolatilementContainerList[this.phase0EnlistVolatilementContainerList.Count - 1] as OletxPhase0VolatileEnlistmentContainer;
                            if (container != null)
                            {
                                this.TakeContainerLock(container, ref flag5);
                            }
                            if (!container.NewEnlistmentsAllowed)
                            {
                                this.ReleaseContainerLock(container, ref flag5);
                                container = new OletxPhase0VolatileEnlistmentContainer(this);
                                flag      = true;
                            }
                            else
                            {
                                flag = false;
                            }
                        }
                        if (flag)
                        {
                            zero = HandleTable.AllocHandle(container);
                        }
                    }
                    else if (this.phase1EnlistVolatilementContainer == null)
                    {
                        target             = new OletxPhase1VolatileEnlistmentContainer(this);
                        flag2              = true;
                        target.voterHandle = HandleTable.AllocHandle(target);
                    }
                    else
                    {
                        flag2  = false;
                        target = this.phase1EnlistVolatilementContainer;
                    }
                    try
                    {
                        if (container != null)
                        {
                            this.TakeContainerLock(container, ref flag5);
                        }
                        if (flag)
                        {
                            this.transactionShim.Phase0Enlist(zero, out shim2);
                            container.Phase0EnlistmentShim = shim2;
                        }
                        if (flag2)
                        {
                            this.OletxTransactionManagerInstance.dtcTransactionManagerLock.AcquireReaderLock(-1);
                            try
                            {
                                this.transactionShim.CreateVoter(target.voterHandle, out voterBallotShim);
                                flag3 = true;
                            }
                            finally
                            {
                                this.OletxTransactionManagerInstance.dtcTransactionManagerLock.ReleaseReaderLock();
                            }
                            target.VoterBallotShim = voterBallotShim;
                        }
                        if (delayCommit)
                        {
                            if (flag)
                            {
                                this.phase0EnlistVolatilementContainerList.Add(container);
                            }
                            container.AddDependentClone();
                            return(container);
                        }
                        if (flag2)
                        {
                            this.phase1EnlistVolatilementContainer = target;
                        }
                        target.AddDependentClone();
                        return(target);
                    }
                    catch (COMException exception)
                    {
                        OletxTransactionManager.ProxyException(exception);
                        throw;
                    }
                    return(container3);
                }
            }
            finally
            {
                if (container != null)
                {
                    this.ReleaseContainerLock(container, ref flag5);
                }
                if ((zero != IntPtr.Zero) && (container.Phase0EnlistmentShim == null))
                {
                    HandleTable.FreeHandle(zero);
                }
                if ((!flag3 && (target != null)) && ((target.voterHandle != IntPtr.Zero) && flag2))
                {
                    HandleTable.FreeHandle(target.voterHandle);
                }
            }
            return(container3);
        }