Example #1
0
 private void Initialize()
 {
     if (!this.initialized)
     {
         OletxInternalResourceManager internalResourceManager = this.oletxTm.internalResourceManager;
         IntPtr zero = IntPtr.Zero;
         IResourceManagerShim resourceManagerShim = null;
         bool            nodeNameMatches          = false;
         CoTaskMemHandle whereaboutsBuffer        = null;
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
             zero = HandleTable.AllocHandle(internalResourceManager);
             this.proxyShimFactory.ConnectToProxy(this.nodeName, internalResourceManager.Identifier, zero, out nodeNameMatches, out this.whereaboutsSize, out whereaboutsBuffer, out resourceManagerShim);
             if (!nodeNameMatches)
             {
                 throw new NotSupportedException(System.Transactions.SR.GetString("ProxyCannotSupportMultipleNodeNames"));
             }
             if ((whereaboutsBuffer != null) && (this.whereaboutsSize != 0))
             {
                 this.whereabouts = new byte[this.whereaboutsSize];
                 Marshal.Copy(whereaboutsBuffer.DangerousGetHandle(), this.whereabouts, 0, Convert.ToInt32(this.whereaboutsSize));
             }
             internalResourceManager.resourceManagerShim = resourceManagerShim;
             internalResourceManager.CallReenlistComplete();
             this.initialized = true;
         }
         catch (COMException exception)
         {
             if (System.Transactions.Oletx.NativeMethods.XACT_E_NOTSUPPORTED == exception.ErrorCode)
             {
                 throw new NotSupportedException(System.Transactions.SR.GetString("CannotSupportNodeNameSpecification"));
             }
             OletxTransactionManager.ProxyException(exception);
             throw TransactionManagerCommunicationException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("TransactionManagerCommunicationException"), exception);
         }
         finally
         {
             if (whereaboutsBuffer != null)
             {
                 whereaboutsBuffer.Close();
             }
             if (!this.initialized)
             {
                 if ((zero != IntPtr.Zero) && (resourceManagerShim == null))
                 {
                     HandleTable.FreeHandle(zero);
                 }
                 if (this.whereabouts != null)
                 {
                     this.whereabouts     = null;
                     this.whereaboutsSize = 0;
                 }
             }
         }
     }
 }
Example #2
0
        internal bool CallProxyReenlistComplete()
        {
            bool flag = false;

            if (this.RecoveryCompleteCalledByApplication)
            {
                IResourceManagerShim resourceManagerShim = null;
                try
                {
                    try
                    {
                        resourceManagerShim = this.ResourceManagerShim;
                        if (resourceManagerShim != null)
                        {
                            resourceManagerShim.ReenlistComplete();
                            flag = true;
                        }
                    }
                    catch (COMException exception)
                    {
                        if ((System.Transactions.Oletx.NativeMethods.XACT_E_CONNECTION_DOWN == exception.ErrorCode) || (System.Transactions.Oletx.NativeMethods.XACT_E_TMNOTAVAILABLE == exception.ErrorCode))
                        {
                            flag = false;
                            if (DiagnosticTrace.Verbose)
                            {
                                ExceptionConsumedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), exception);
                            }
                            return(flag);
                        }
                        if (System.Transactions.Oletx.NativeMethods.XACT_E_RECOVERYALREADYDONE != exception.ErrorCode)
                        {
                            OletxTransactionManager.ProxyException(exception);
                            throw;
                        }
                        return(true);
                    }
                    return(flag);
                }
                finally
                {
                    resourceManagerShim = null;
                }
            }
            return(true);
        }
 internal bool CallProxyReenlistComplete()
 {
     bool flag = false;
     if (this.RecoveryCompleteCalledByApplication)
     {
         IResourceManagerShim resourceManagerShim = null;
         try
         {
             try
             {
                 resourceManagerShim = this.ResourceManagerShim;
                 if (resourceManagerShim != null)
                 {
                     resourceManagerShim.ReenlistComplete();
                     flag = true;
                 }
             }
             catch (COMException exception)
             {
                 if ((System.Transactions.Oletx.NativeMethods.XACT_E_CONNECTION_DOWN == exception.ErrorCode) || (System.Transactions.Oletx.NativeMethods.XACT_E_TMNOTAVAILABLE == exception.ErrorCode))
                 {
                     flag = false;
                     if (DiagnosticTrace.Verbose)
                     {
                         ExceptionConsumedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), exception);
                     }
                     return flag;
                 }
                 if (System.Transactions.Oletx.NativeMethods.XACT_E_RECOVERYALREADYDONE != exception.ErrorCode)
                 {
                     OletxTransactionManager.ProxyException(exception);
                     throw;
                 }
                 return true;
             }
             return flag;
         }
         finally
         {
             resourceManagerShim = null;
         }
     }
     return true;
 }
Example #4
0
        internal OletxResourceManager(
            OletxTransactionManager transactionManager,
            Guid resourceManagerIdentifier
            )
        {
            Debug.Assert( null != transactionManager, "Argument is null" );

            // This will get set later, after the resource manager is created with the proxy.
            this.resourceManagerShim = null;
            this.oletxTransactionManager = transactionManager;
            this.resourceManagerIdentifier = resourceManagerIdentifier;

            this.enlistmentHashtable = new Hashtable();
            this.reenlistList = new ArrayList();
            this.reenlistPendingList = new ArrayList();

            reenlistThreadTimer = null;
            reenlistThread = null;
            recoveryCompleteCalledByApplication = false;
        }
Example #5
0
        public void TMDown()
        {
            this.resourceManagerShim = null;
            Transaction           target = null;
            RealOletxTransaction  realOletxTransaction = null;
            IDictionaryEnumerator enumerator           = null;

            if (DiagnosticTrace.Verbose)
            {
                MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxInternalResourceManager.TMDown");
            }
            Hashtable hashtable2 = null;

            lock (TransactionManager.PromotedTransactionTable.SyncRoot)
            {
                hashtable2 = (Hashtable)TransactionManager.PromotedTransactionTable.Clone();
            }
            enumerator = hashtable2.GetEnumerator();
            while (enumerator.MoveNext())
            {
                WeakReference reference = (WeakReference)enumerator.Value;
                if (reference != null)
                {
                    target = (Transaction)reference.Target;
                    if (null != target)
                    {
                        realOletxTransaction = target.internalTransaction.PromotedTransaction.realOletxTransaction;
                        if (realOletxTransaction.OletxTransactionManagerInstance == this.oletxTm)
                        {
                            realOletxTransaction.TMDown();
                        }
                    }
                }
            }
            Hashtable hashtable = null;

            if (OletxTransactionManager.resourceManagerHashTable != null)
            {
                OletxTransactionManager.resourceManagerHashTableLock.AcquireReaderLock(-1);
                try
                {
                    hashtable = (Hashtable)OletxTransactionManager.resourceManagerHashTable.Clone();
                }
                finally
                {
                    OletxTransactionManager.resourceManagerHashTableLock.ReleaseReaderLock();
                }
            }
            if (hashtable != null)
            {
                enumerator = hashtable.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    OletxResourceManager manager = (OletxResourceManager)enumerator.Value;
                    if (manager != null)
                    {
                        manager.TMDownFromInternalRM(this.oletxTm);
                    }
                }
            }
            this.oletxTm.dtcTransactionManagerLock.AcquireWriterLock(-1);
            try
            {
                this.oletxTm.ReinitializeProxy();
            }
            finally
            {
                this.oletxTm.dtcTransactionManagerLock.ReleaseWriterLock();
            }
            if (DiagnosticTrace.Verbose)
            {
                MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxInternalResourceManager.TMDown");
            }
        }
 public void TMDown()
 {
     this.resourceManagerShim = null;
     Transaction target = null;
     RealOletxTransaction realOletxTransaction = null;
     IDictionaryEnumerator enumerator = null;
     if (DiagnosticTrace.Verbose)
     {
         MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxInternalResourceManager.TMDown");
     }
     Hashtable hashtable2 = null;
     lock (TransactionManager.PromotedTransactionTable.SyncRoot)
     {
         hashtable2 = (Hashtable) TransactionManager.PromotedTransactionTable.Clone();
     }
     enumerator = hashtable2.GetEnumerator();
     while (enumerator.MoveNext())
     {
         WeakReference reference = (WeakReference) enumerator.Value;
         if (reference != null)
         {
             target = (Transaction) reference.Target;
             if (null != target)
             {
                 realOletxTransaction = target.internalTransaction.PromotedTransaction.realOletxTransaction;
                 if (realOletxTransaction.OletxTransactionManagerInstance == this.oletxTm)
                 {
                     realOletxTransaction.TMDown();
                 }
             }
         }
     }
     Hashtable hashtable = null;
     if (OletxTransactionManager.resourceManagerHashTable != null)
     {
         OletxTransactionManager.resourceManagerHashTableLock.AcquireReaderLock(-1);
         try
         {
             hashtable = (Hashtable) OletxTransactionManager.resourceManagerHashTable.Clone();
         }
         finally
         {
             OletxTransactionManager.resourceManagerHashTableLock.ReleaseReaderLock();
         }
     }
     if (hashtable != null)
     {
         enumerator = hashtable.GetEnumerator();
         while (enumerator.MoveNext())
         {
             OletxResourceManager manager = (OletxResourceManager) enumerator.Value;
             if (manager != null)
             {
                 manager.TMDownFromInternalRM(this.oletxTm);
             }
         }
     }
     this.oletxTm.dtcTransactionManagerLock.AcquireWriterLock(-1);
     try
     {
         this.oletxTm.ReinitializeProxy();
     }
     finally
     {
         this.oletxTm.dtcTransactionManagerLock.ReleaseWriterLock();
     }
     if (DiagnosticTrace.Verbose)
     {
         MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxInternalResourceManager.TMDown");
     }
 }
Example #7
0
        public void TMDown()
        {
            // Let's set ourselves up for reinitialization with the proxy by releasing our
            // reference to the resource manager shim, which will release its reference
            // to the proxy when it destructs.
            this.resourceManagerShim = null;

            // We need to look through all the transactions and tell them about
            // the TMDown so they can tell their Phase0VolatileEnlistmentContainers.
            Transaction           tx        = null;
            RealOletxTransaction  realTx    = null;
            IDictionaryEnumerator tableEnum = null;

            if (DiagnosticTrace.Verbose)
            {
                MethodEnteredTraceRecord.Trace(SR.GetString(SR.TraceSourceOletx),
                                               "OletxInternalResourceManager.TMDown"
                                               );
            }

            // make a local copy of the hash table to avoid possible deadlocks when we lock both the global hash table
            // and the transaction object.
            Hashtable txHashTable = null;

            lock (TransactionManager.PromotedTransactionTable.SyncRoot)
            {
                txHashTable = (Hashtable)TransactionManager.PromotedTransactionTable.Clone();
            }

            // No need to lock my hashtable, nobody is going to change it.
            tableEnum = txHashTable.GetEnumerator();
            while (tableEnum.MoveNext())
            {
                WeakReference txWeakRef = (WeakReference)tableEnum.Value;
                if (null != txWeakRef)
                {
                    tx = (Transaction)txWeakRef.Target;
                    if (null != tx)
                    {
                        realTx = tx.internalTransaction.PromotedTransaction.realOletxTransaction;
                        // Only deal with transactions owned by my OletxTm.
                        if (realTx.OletxTransactionManagerInstance == this.oletxTm)
                        {
                            realTx.TMDown();
                        }
                    }
                }
            }

            // Now make a local copy of the hash table of resource managers and tell each of them.  This is to
            // deal with Durable EDPR=true (phase0) enlistments.  Each RM will also get a TMDown, but it will
            // come AFTER the "buggy" Phase0Request with abortHint=true - COMPlus
            Hashtable rmHashTable = null;

            if (null != OletxTransactionManager.resourceManagerHashTable)
            {
                OletxTransactionManager.resourceManagerHashTableLock.AcquireReaderLock(Timeout.Infinite);
                try
                {
                    rmHashTable = (Hashtable)OletxTransactionManager.resourceManagerHashTable.Clone();
                }
                finally
                {
                    OletxTransactionManager.resourceManagerHashTableLock.ReleaseReaderLock();
                }
            }

            if (null != rmHashTable)
            {
                // No need to lock my hashtable, nobody is going to change it.
                tableEnum = rmHashTable.GetEnumerator();
                while (tableEnum.MoveNext())
                {
                    OletxResourceManager oletxRM = (OletxResourceManager)tableEnum.Value;
                    if (null != oletxRM)
                    {
                        // When the RM spins through its enlistments, it will need to make sure that
                        // the enlistment is for this particular TM.
                        oletxRM.TMDownFromInternalRM(this.oletxTm);
                    }
                }
            }

            // Now let's reinitialize the shim.
            this.oletxTm.dtcTransactionManagerLock.AcquireWriterLock(-1);
            try
            {
                this.oletxTm.ReinitializeProxy();
            }
            finally
            {
                this.oletxTm.dtcTransactionManagerLock.ReleaseWriterLock();
            }

            if (DiagnosticTrace.Verbose)
            {
                MethodExitedTraceRecord.Trace(SR.GetString(SR.TraceSourceOletx),
                                              "OletxInternalResourceManager.TMDown"
                                              );
            }
        }
Example #8
0
        public void TMDown()
        {
            // Let's set ourselves up for reinitialization with the proxy by releasing our
            // reference to the resource manager shim, which will release its reference
            // to the proxy when it destructs.
            this.resourceManagerShim = null;

            // We need to look through all the transactions and tell them about
            // the TMDown so they can tell their Phase0VolatileEnlistmentContainers.
            Transaction tx = null;
            RealOletxTransaction realTx = null;
            IDictionaryEnumerator tableEnum = null;

            if ( DiagnosticTrace.Verbose )
            {
                MethodEnteredTraceRecord.Trace( SR.GetString( SR.TraceSourceOletx ),
                    "OletxInternalResourceManager.TMDown"
                    );
            }

            // make a local copy of the hash table to avoid possible deadlocks when we lock both the global hash table
            // and the transaction object.
            Hashtable txHashTable = null;
            lock ( TransactionManager.PromotedTransactionTable.SyncRoot )
            {
                txHashTable = (Hashtable) TransactionManager.PromotedTransactionTable.Clone();
            }

            // No need to lock my hashtable, nobody is going to change it.
            tableEnum = txHashTable.GetEnumerator();
            while ( tableEnum.MoveNext() )
            {
                WeakReference txWeakRef = (WeakReference) tableEnum.Value;
                if ( null != txWeakRef )
                {
                    tx = (Transaction)txWeakRef.Target;
                    if ( null != tx )
                    {
                        realTx = tx.internalTransaction.PromotedTransaction.realOletxTransaction;
                        // Only deal with transactions owned by my OletxTm.
                        if ( realTx.OletxTransactionManagerInstance == this.oletxTm )
                        {
                            realTx.TMDown();
                        }
                    }
                }
            }

            // Now make a local copy of the hash table of resource managers and tell each of them.  This is to
            // deal with Durable EDPR=true (phase0) enlistments.  Each RM will also get a TMDown, but it will
            // come AFTER the "buggy" Phase0Request with abortHint=true - COMPlus bug 36760/36758.
            Hashtable rmHashTable = null;
            if ( null != OletxTransactionManager.resourceManagerHashTable )
            {
                OletxTransactionManager.resourceManagerHashTableLock.AcquireReaderLock( Timeout.Infinite );
                try
                {
                    rmHashTable = (Hashtable) OletxTransactionManager.resourceManagerHashTable.Clone();
                }
                finally
                {
                    OletxTransactionManager.resourceManagerHashTableLock.ReleaseReaderLock();
                }
            }

            if ( null != rmHashTable )
            {
                // No need to lock my hashtable, nobody is going to change it.
                tableEnum = rmHashTable.GetEnumerator();
                while ( tableEnum.MoveNext() )
                {
                    OletxResourceManager oletxRM = (OletxResourceManager) tableEnum.Value;
                    if ( null != oletxRM )
                    {
                        // When the RM spins through its enlistments, it will need to make sure that
                        // the enlistment is for this particular TM.
                        oletxRM.TMDownFromInternalRM( this.oletxTm );
                    }
                }
            }

            // Now let's reinitialize the shim.
            this.oletxTm.dtcTransactionManagerLock.AcquireWriterLock( -1 );
            try
            {
                this.oletxTm.ReinitializeProxy();
            }
            finally
            {
                this.oletxTm.dtcTransactionManagerLock.ReleaseWriterLock();
            }

            if ( DiagnosticTrace.Verbose )
            {
                MethodExitedTraceRecord.Trace( SR.GetString( SR.TraceSourceOletx ),
                    "OletxInternalResourceManager.TMDown"
                    );
            }

        }
        void Initialize()
        {
            if (this.initialized)
            {
                return;
            }

            OletxInternalResourceManager internalRM = this.oletxTm.internalResourceManager;
            IntPtr handle = IntPtr.Zero;
            IResourceManagerShim resourceManagerShim = null;
            bool nodeNameMatches = false;

            CoTaskMemHandle whereaboutsBuffer = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                handle = HandleTable.AllocHandle(internalRM);

                this.proxyShimFactory.ConnectToProxy(
                    this.nodeName,
                    internalRM.Identifier,
                    handle,
                    out nodeNameMatches,
                    out this.whereaboutsSize,
                    out whereaboutsBuffer,
                    out resourceManagerShim
                    );

                // If the node name does not match, throw.
                if (!nodeNameMatches)
                {
                    throw new NotSupportedException(SR.GetString(SR.ProxyCannotSupportMultipleNodeNames));
                }

                // Make a managed copy of the whereabouts.
                if ((null != whereaboutsBuffer) && (0 != this.whereaboutsSize))
                {
                    this.whereabouts = new byte[this.whereaboutsSize];
                    Marshal.Copy(whereaboutsBuffer.DangerousGetHandle(), this.whereabouts, 0, Convert.ToInt32(this.whereaboutsSize));
                }

                // Give the IResourceManagerShim to the internalRM and tell it to call ReenlistComplete.
                internalRM.resourceManagerShim = resourceManagerShim;
                internalRM.CallReenlistComplete();


                this.initialized = true;
            }
            catch (COMException ex)
            {
                if (NativeMethods.XACT_E_NOTSUPPORTED == ex.ErrorCode)
                {
                    throw new NotSupportedException(SR.GetString(SR.CannotSupportNodeNameSpecification));
                }

                OletxTransactionManager.ProxyException(ex);

                // Unfortunately MSDTCPRX may return unknown error codes when attempting to connect to MSDTC
                // that error should be propagated back as a TransactionManagerCommunicationException.
                throw TransactionManagerCommunicationException.Create(
                          SR.GetString(SR.TraceSourceOletx),
                          SR.GetString(SR.TransactionManagerCommunicationException),
                          ex
                          );
            }
            finally
            {
                if (null != whereaboutsBuffer)
                {
                    whereaboutsBuffer.Close();
                }

                // If we weren't successful at initializing ourself, clear things out
                // for next time around.
                if (!this.initialized)
                {
                    if (handle != IntPtr.Zero && null == resourceManagerShim)
                    {
                        HandleTable.FreeHandle(handle);
                    }

                    if (null != this.whereabouts)
                    {
                        this.whereabouts     = null;
                        this.whereaboutsSize = 0;
                    }
                }
            }
        }
Example #10
0
        internal OletxEnlistment EnlistDurable(OletxTransaction oletxTransaction, bool canDoSinglePhase, IEnlistmentNotificationInternal enlistmentNotification, EnlistmentOptions enlistmentOptions)
        {
            IResourceManagerShim  resourceManagerShim = null;
            IPhase0EnlistmentShim shim2          = null;
            IEnlistmentShim       enlistmentShim = null;
            IntPtr          zero   = IntPtr.Zero;
            bool            flag3  = false;
            bool            flag2  = false;
            OletxEnlistment target = new OletxEnlistment(canDoSinglePhase, enlistmentNotification, oletxTransaction.RealTransaction.TxGuid, enlistmentOptions, this, oletxTransaction);
            bool            flag   = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                if ((enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != EnlistmentOptions.None)
                {
                    RuntimeHelpers.PrepareConstrainedRegions();
                    try
                    {
                    }
                    finally
                    {
                        oletxTransaction.RealTransaction.IncrementUndecidedEnlistments();
                        flag2 = true;
                    }
                }
                lock (target)
                {
                    RuntimeHelpers.PrepareConstrainedRegions();
                    try
                    {
                        resourceManagerShim = this.ResourceManagerShim;
                        if (resourceManagerShim == null)
                        {
                            throw TransactionManagerCommunicationException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), null);
                        }
                        if ((enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != EnlistmentOptions.None)
                        {
                            zero = HandleTable.AllocHandle(target);
                            RuntimeHelpers.PrepareConstrainedRegions();
                            try
                            {
                            }
                            finally
                            {
                                oletxTransaction.RealTransaction.TransactionShim.Phase0Enlist(zero, out shim2);
                                flag3 = true;
                            }
                            target.Phase0EnlistmentShim = shim2;
                        }
                        target.phase1Handle = HandleTable.AllocHandle(target);
                        resourceManagerShim.Enlist(oletxTransaction.RealTransaction.TransactionShim, target.phase1Handle, out enlistmentShim);
                        target.EnlistmentShim = enlistmentShim;
                    }
                    catch (COMException exception)
                    {
                        if (System.Transactions.Oletx.NativeMethods.XACT_E_TOOMANY_ENLISTMENTS == exception.ErrorCode)
                        {
                            throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("OletxTooManyEnlistments"), exception);
                        }
                        OletxTransactionManager.ProxyException(exception);
                        throw;
                    }
                    finally
                    {
                        if (target.EnlistmentShim == null)
                        {
                            if ((zero != IntPtr.Zero) && !flag3)
                            {
                                HandleTable.FreeHandle(zero);
                            }
                            if (target.phase1Handle != IntPtr.Zero)
                            {
                                HandleTable.FreeHandle(target.phase1Handle);
                            }
                        }
                    }
                }
                flag = true;
            }
            finally
            {
                if ((!flag && ((enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != EnlistmentOptions.None)) && flag2)
                {
                    oletxTransaction.RealTransaction.DecrementUndecidedEnlistments();
                }
            }
            return(target);
        }
Example #11
0
        internal void ReenlistThread(object state)
        {
            int                  count               = 0;
            bool                 flag                = false;
            OletxEnlistment      enlistment          = null;
            IResourceManagerShim resourceManagerShim = null;
            Timer                reenlistThreadTimer = null;
            bool                 flag2               = false;
            OletxResourceManager manager             = (OletxResourceManager)state;

            try
            {
                if (DiagnosticTrace.Information)
                {
                    MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxResourceManager.ReenlistThread");
                }
                lock (manager)
                {
                    resourceManagerShim         = manager.ResourceManagerShim;
                    reenlistThreadTimer         = manager.reenlistThreadTimer;
                    manager.reenlistThreadTimer = null;
                    manager.reenlistThread      = Thread.CurrentThread;
                }
                if (resourceManagerShim != null)
                {
                    lock (manager.reenlistList)
                    {
                        count = manager.reenlistList.Count;
                    }
                    flag = false;
                    while ((!flag && (count > 0)) && (resourceManagerShim != null))
                    {
                        lock (manager.reenlistList)
                        {
                            enlistment = null;
                            count--;
                            if (manager.reenlistList.Count == 0)
                            {
                                flag = true;
                            }
                            else
                            {
                                enlistment = manager.reenlistList[0] as OletxEnlistment;
                                if (enlistment == null)
                                {
                                    if (DiagnosticTrace.Critical)
                                    {
                                        InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                                    }
                                    throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("InternalError"), null);
                                }
                                manager.reenlistList.RemoveAt(0);
                                object obj7 = enlistment;
                                lock (obj7)
                                {
                                    if (OletxEnlistment.OletxEnlistmentState.Done == enlistment.State)
                                    {
                                        enlistment = null;
                                    }
                                    else if (OletxEnlistment.OletxEnlistmentState.Prepared != enlistment.State)
                                    {
                                        manager.reenlistList.Add(enlistment);
                                        enlistment = null;
                                    }
                                }
                            }
                        }
                        if (enlistment != null)
                        {
                            OletxTransactionOutcome notKnownYet = OletxTransactionOutcome.NotKnownYet;
                            try
                            {
                                if (enlistment.ProxyPrepareInfoByteArray == null)
                                {
                                    if (DiagnosticTrace.Critical)
                                    {
                                        InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                                    }
                                    throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("InternalError"), null);
                                }
                                resourceManagerShim.Reenlist((uint)enlistment.ProxyPrepareInfoByteArray.Length, enlistment.ProxyPrepareInfoByteArray, out notKnownYet);
                                if (notKnownYet == OletxTransactionOutcome.NotKnownYet)
                                {
                                    object obj5 = enlistment;
                                    lock (obj5)
                                    {
                                        if (OletxEnlistment.OletxEnlistmentState.Done == enlistment.State)
                                        {
                                            enlistment = null;
                                        }
                                        else
                                        {
                                            lock (manager.reenlistList)
                                            {
                                                manager.reenlistList.Add(enlistment);
                                                enlistment = null;
                                            }
                                        }
                                    }
                                }
                            }
                            catch (COMException exception)
                            {
                                if (System.Transactions.Oletx.NativeMethods.XACT_E_CONNECTION_DOWN != exception.ErrorCode)
                                {
                                    throw;
                                }
                                if (DiagnosticTrace.Verbose)
                                {
                                    ExceptionConsumedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), exception);
                                }
                                if (System.Transactions.Oletx.NativeMethods.XACT_E_CONNECTION_DOWN == exception.ErrorCode)
                                {
                                    manager.ResourceManagerShim = null;
                                    resourceManagerShim         = manager.ResourceManagerShim;
                                }
                            }
                            if (enlistment != null)
                            {
                                object obj3 = enlistment;
                                lock (obj3)
                                {
                                    if (OletxEnlistment.OletxEnlistmentState.Done != enlistment.State)
                                    {
                                        lock (manager.reenlistList)
                                        {
                                            manager.reenlistPendingList.Add(enlistment);
                                        }
                                        if (OletxTransactionOutcome.Committed != notKnownYet)
                                        {
                                            if (OletxTransactionOutcome.Aborted != notKnownYet)
                                            {
                                                if (DiagnosticTrace.Critical)
                                                {
                                                    InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                                                }
                                                throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("InternalError"), null);
                                            }
                                            enlistment.State = OletxEnlistment.OletxEnlistmentState.Aborting;
                                            if (DiagnosticTrace.Verbose)
                                            {
                                                EnlistmentNotificationCallTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), enlistment.EnlistmentTraceId, NotificationCall.Rollback);
                                            }
                                            enlistment.EnlistmentNotification.Rollback(enlistment);
                                        }
                                        else
                                        {
                                            enlistment.State = OletxEnlistment.OletxEnlistmentState.Committing;
                                            if (DiagnosticTrace.Verbose)
                                            {
                                                EnlistmentNotificationCallTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), enlistment.EnlistmentTraceId, NotificationCall.Commit);
                                            }
                                            enlistment.EnlistmentNotification.Commit(enlistment);
                                        }
                                    }
                                    else
                                    {
                                        enlistment = null;
                                    }
                                    continue;
                                }
                            }
                        }
                    }
                }
                resourceManagerShim = null;
                lock (manager.reenlistList)
                {
                    lock (manager)
                    {
                        count = manager.reenlistList.Count;
                        if ((0 >= count) && (0 >= manager.reenlistPendingList.Count))
                        {
                            if (!manager.CallProxyReenlistComplete())
                            {
                                manager.reenlistThreadTimer = reenlistThreadTimer;
                                if (!reenlistThreadTimer.Change(0x2710, -1))
                                {
                                    throw TransactionException.CreateInvalidOperationException(System.Transactions.SR.GetString("TraceSourceLtm"), System.Transactions.SR.GetString("UnexpectedTimerFailure"), null);
                                }
                            }
                            else
                            {
                                flag2 = true;
                            }
                        }
                        else
                        {
                            manager.reenlistThreadTimer = reenlistThreadTimer;
                            if (!reenlistThreadTimer.Change(0x2710, -1))
                            {
                                throw TransactionException.CreateInvalidOperationException(System.Transactions.SR.GetString("TraceSourceLtm"), System.Transactions.SR.GetString("UnexpectedTimerFailure"), null);
                            }
                        }
                        manager.reenlistThread = null;
                    }
                    if (DiagnosticTrace.Information)
                    {
                        MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxResourceManager.ReenlistThread");
                    }
                }
            }
            finally
            {
                resourceManagerShim = null;
                if (flag2 && (reenlistThreadTimer != null))
                {
                    reenlistThreadTimer.Dispose();
                }
            }
        }
Example #12
0
        internal OletxEnlistment Reenlist(int prepareInfoLength, byte[] prepareInfo, IEnlistmentNotificationInternal enlistmentNotification)
        {
            OletxRecoveryInformation information;
            OletxTransactionOutcome  notKnownYet         = OletxTransactionOutcome.NotKnownYet;
            OletxTransactionStatus   xactStatus          = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_NONE;
            MemoryStream             serializationStream = new MemoryStream(prepareInfo);
            IFormatter formatter = new BinaryFormatter();

            try
            {
                information = formatter.Deserialize(serializationStream) as OletxRecoveryInformation;
            }
            catch (SerializationException exception2)
            {
                throw new ArgumentException(System.Transactions.SR.GetString("InvalidArgument"), "prepareInfo", exception2);
            }
            if (information == null)
            {
                throw new ArgumentException(System.Transactions.SR.GetString("InvalidArgument"), "prepareInfo");
            }
            byte[] b = new byte[0x10];
            for (int i = 0; i < 0x10; i++)
            {
                b[i] = information.proxyRecoveryInformation[i + 0x10];
            }
            Guid guid = new Guid(b);

            if (guid != this.resourceManagerIdentifier)
            {
                throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("ResourceManagerIdDoesNotMatchRecoveryInformation"), null);
            }
            IResourceManagerShim resourceManagerShim = null;

            try
            {
                resourceManagerShim = this.ResourceManagerShim;
                if (resourceManagerShim == null)
                {
                    throw new COMException(System.Transactions.SR.GetString("DtcTransactionManagerUnavailable"), System.Transactions.Oletx.NativeMethods.XACT_E_CONNECTION_DOWN);
                }
                resourceManagerShim.Reenlist(Convert.ToUInt32(information.proxyRecoveryInformation.Length, CultureInfo.InvariantCulture), information.proxyRecoveryInformation, out notKnownYet);
                if (OletxTransactionOutcome.Committed == notKnownYet)
                {
                    xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_COMMITTED;
                }
                else if (OletxTransactionOutcome.Aborted == notKnownYet)
                {
                    xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_ABORTED;
                }
                else
                {
                    xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_PREPARED;
                    this.StartReenlistThread();
                }
            }
            catch (COMException exception)
            {
                if (System.Transactions.Oletx.NativeMethods.XACT_E_CONNECTION_DOWN != exception.ErrorCode)
                {
                    throw;
                }
                xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_PREPARED;
                this.ResourceManagerShim = null;
                this.StartReenlistThread();
                if (DiagnosticTrace.Verbose)
                {
                    ExceptionConsumedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), exception);
                }
            }
            finally
            {
                resourceManagerShim = null;
            }
            return(new OletxEnlistment(enlistmentNotification, xactStatus, information.proxyRecoveryInformation, this));
        }
 internal OletxEnlistment EnlistDurable(OletxTransaction oletxTransaction, bool canDoSinglePhase, IEnlistmentNotificationInternal enlistmentNotification, EnlistmentOptions enlistmentOptions)
 {
     IResourceManagerShim resourceManagerShim = null;
     IPhase0EnlistmentShim shim2 = null;
     IEnlistmentShim enlistmentShim = null;
     IntPtr zero = IntPtr.Zero;
     bool flag3 = false;
     bool flag2 = false;
     OletxEnlistment target = new OletxEnlistment(canDoSinglePhase, enlistmentNotification, oletxTransaction.RealTransaction.TxGuid, enlistmentOptions, this, oletxTransaction);
     bool flag = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         if ((enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != EnlistmentOptions.None)
         {
             RuntimeHelpers.PrepareConstrainedRegions();
             try
             {
             }
             finally
             {
                 oletxTransaction.RealTransaction.IncrementUndecidedEnlistments();
                 flag2 = true;
             }
         }
         lock (target)
         {
             RuntimeHelpers.PrepareConstrainedRegions();
             try
             {
                 resourceManagerShim = this.ResourceManagerShim;
                 if (resourceManagerShim == null)
                 {
                     throw TransactionManagerCommunicationException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), null);
                 }
                 if ((enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != EnlistmentOptions.None)
                 {
                     zero = HandleTable.AllocHandle(target);
                     RuntimeHelpers.PrepareConstrainedRegions();
                     try
                     {
                     }
                     finally
                     {
                         oletxTransaction.RealTransaction.TransactionShim.Phase0Enlist(zero, out shim2);
                         flag3 = true;
                     }
                     target.Phase0EnlistmentShim = shim2;
                 }
                 target.phase1Handle = HandleTable.AllocHandle(target);
                 resourceManagerShim.Enlist(oletxTransaction.RealTransaction.TransactionShim, target.phase1Handle, out enlistmentShim);
                 target.EnlistmentShim = enlistmentShim;
             }
             catch (COMException exception)
             {
                 if (System.Transactions.Oletx.NativeMethods.XACT_E_TOOMANY_ENLISTMENTS == exception.ErrorCode)
                 {
                     throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("OletxTooManyEnlistments"), exception);
                 }
                 OletxTransactionManager.ProxyException(exception);
                 throw;
             }
             finally
             {
                 if (target.EnlistmentShim == null)
                 {
                     if ((zero != IntPtr.Zero) && !flag3)
                     {
                         HandleTable.FreeHandle(zero);
                     }
                     if (target.phase1Handle != IntPtr.Zero)
                     {
                         HandleTable.FreeHandle(target.phase1Handle);
                     }
                 }
             }
         }
         flag = true;
     }
     finally
     {
         if ((!flag && ((enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != EnlistmentOptions.None)) && flag2)
         {
             oletxTransaction.RealTransaction.DecrementUndecidedEnlistments();
         }
     }
     return target;
 }
 internal void ReenlistThread(object state)
 {
     int count = 0;
     bool flag = false;
     OletxEnlistment enlistment = null;
     IResourceManagerShim resourceManagerShim = null;
     Timer reenlistThreadTimer = null;
     bool flag2 = false;
     OletxResourceManager manager = (OletxResourceManager) state;
     try
     {
         if (DiagnosticTrace.Information)
         {
             MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxResourceManager.ReenlistThread");
         }
         lock (manager)
         {
             resourceManagerShim = manager.ResourceManagerShim;
             reenlistThreadTimer = manager.reenlistThreadTimer;
             manager.reenlistThreadTimer = null;
             manager.reenlistThread = Thread.CurrentThread;
         }
         if (resourceManagerShim != null)
         {
             lock (manager.reenlistList)
             {
                 count = manager.reenlistList.Count;
             }
             flag = false;
             while ((!flag && (count > 0)) && (resourceManagerShim != null))
             {
                 lock (manager.reenlistList)
                 {
                     enlistment = null;
                     count--;
                     if (manager.reenlistList.Count == 0)
                     {
                         flag = true;
                     }
                     else
                     {
                         enlistment = manager.reenlistList[0] as OletxEnlistment;
                         if (enlistment == null)
                         {
                             if (DiagnosticTrace.Critical)
                             {
                                 InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                             }
                             throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("InternalError"), null);
                         }
                         manager.reenlistList.RemoveAt(0);
                         object obj7 = enlistment;
                         lock (obj7)
                         {
                             if (OletxEnlistment.OletxEnlistmentState.Done == enlistment.State)
                             {
                                 enlistment = null;
                             }
                             else if (OletxEnlistment.OletxEnlistmentState.Prepared != enlistment.State)
                             {
                                 manager.reenlistList.Add(enlistment);
                                 enlistment = null;
                             }
                         }
                     }
                 }
                 if (enlistment != null)
                 {
                     OletxTransactionOutcome notKnownYet = OletxTransactionOutcome.NotKnownYet;
                     try
                     {
                         if (enlistment.ProxyPrepareInfoByteArray == null)
                         {
                             if (DiagnosticTrace.Critical)
                             {
                                 InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                             }
                             throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("InternalError"), null);
                         }
                         resourceManagerShim.Reenlist((uint) enlistment.ProxyPrepareInfoByteArray.Length, enlistment.ProxyPrepareInfoByteArray, out notKnownYet);
                         if (notKnownYet == OletxTransactionOutcome.NotKnownYet)
                         {
                             object obj5 = enlistment;
                             lock (obj5)
                             {
                                 if (OletxEnlistment.OletxEnlistmentState.Done == enlistment.State)
                                 {
                                     enlistment = null;
                                 }
                                 else
                                 {
                                     lock (manager.reenlistList)
                                     {
                                         manager.reenlistList.Add(enlistment);
                                         enlistment = null;
                                     }
                                 }
                             }
                         }
                     }
                     catch (COMException exception)
                     {
                         if (System.Transactions.Oletx.NativeMethods.XACT_E_CONNECTION_DOWN != exception.ErrorCode)
                         {
                             throw;
                         }
                         if (DiagnosticTrace.Verbose)
                         {
                             ExceptionConsumedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), exception);
                         }
                         if (System.Transactions.Oletx.NativeMethods.XACT_E_CONNECTION_DOWN == exception.ErrorCode)
                         {
                             manager.ResourceManagerShim = null;
                             resourceManagerShim = manager.ResourceManagerShim;
                         }
                     }
                     if (enlistment != null)
                     {
                         object obj3 = enlistment;
                         lock (obj3)
                         {
                             if (OletxEnlistment.OletxEnlistmentState.Done != enlistment.State)
                             {
                                 lock (manager.reenlistList)
                                 {
                                     manager.reenlistPendingList.Add(enlistment);
                                 }
                                 if (OletxTransactionOutcome.Committed != notKnownYet)
                                 {
                                     if (OletxTransactionOutcome.Aborted != notKnownYet)
                                     {
                                         if (DiagnosticTrace.Critical)
                                         {
                                             InternalErrorTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "");
                                         }
                                         throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("InternalError"), null);
                                     }
                                     enlistment.State = OletxEnlistment.OletxEnlistmentState.Aborting;
                                     if (DiagnosticTrace.Verbose)
                                     {
                                         EnlistmentNotificationCallTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), enlistment.EnlistmentTraceId, NotificationCall.Rollback);
                                     }
                                     enlistment.EnlistmentNotification.Rollback(enlistment);
                                 }
                                 else
                                 {
                                     enlistment.State = OletxEnlistment.OletxEnlistmentState.Committing;
                                     if (DiagnosticTrace.Verbose)
                                     {
                                         EnlistmentNotificationCallTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), enlistment.EnlistmentTraceId, NotificationCall.Commit);
                                     }
                                     enlistment.EnlistmentNotification.Commit(enlistment);
                                 }
                             }
                             else
                             {
                                 enlistment = null;
                             }
                             continue;
                         }
                     }
                 }
             }
         }
         resourceManagerShim = null;
         lock (manager.reenlistList)
         {
             lock (manager)
             {
                 count = manager.reenlistList.Count;
                 if ((0 >= count) && (0 >= manager.reenlistPendingList.Count))
                 {
                     if (!manager.CallProxyReenlistComplete())
                     {
                         manager.reenlistThreadTimer = reenlistThreadTimer;
                         if (!reenlistThreadTimer.Change(0x2710, -1))
                         {
                             throw TransactionException.CreateInvalidOperationException(System.Transactions.SR.GetString("TraceSourceLtm"), System.Transactions.SR.GetString("UnexpectedTimerFailure"), null);
                         }
                     }
                     else
                     {
                         flag2 = true;
                     }
                 }
                 else
                 {
                     manager.reenlistThreadTimer = reenlistThreadTimer;
                     if (!reenlistThreadTimer.Change(0x2710, -1))
                     {
                         throw TransactionException.CreateInvalidOperationException(System.Transactions.SR.GetString("TraceSourceLtm"), System.Transactions.SR.GetString("UnexpectedTimerFailure"), null);
                     }
                 }
                 manager.reenlistThread = null;
             }
             if (DiagnosticTrace.Information)
             {
                 MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "OletxResourceManager.ReenlistThread");
             }
         }
     }
     finally
     {
         resourceManagerShim = null;
         if (flag2 && (reenlistThreadTimer != null))
         {
             reenlistThreadTimer.Dispose();
         }
     }
 }
 internal OletxEnlistment Reenlist(int prepareInfoLength, byte[] prepareInfo, IEnlistmentNotificationInternal enlistmentNotification)
 {
     OletxRecoveryInformation information;
     OletxTransactionOutcome notKnownYet = OletxTransactionOutcome.NotKnownYet;
     OletxTransactionStatus xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_NONE;
     MemoryStream serializationStream = new MemoryStream(prepareInfo);
     IFormatter formatter = new BinaryFormatter();
     try
     {
         information = formatter.Deserialize(serializationStream) as OletxRecoveryInformation;
     }
     catch (SerializationException exception2)
     {
         throw new ArgumentException(System.Transactions.SR.GetString("InvalidArgument"), "prepareInfo", exception2);
     }
     if (information == null)
     {
         throw new ArgumentException(System.Transactions.SR.GetString("InvalidArgument"), "prepareInfo");
     }
     byte[] b = new byte[0x10];
     for (int i = 0; i < 0x10; i++)
     {
         b[i] = information.proxyRecoveryInformation[i + 0x10];
     }
     Guid guid = new Guid(b);
     if (guid != this.resourceManagerIdentifier)
     {
         throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("ResourceManagerIdDoesNotMatchRecoveryInformation"), null);
     }
     IResourceManagerShim resourceManagerShim = null;
     try
     {
         resourceManagerShim = this.ResourceManagerShim;
         if (resourceManagerShim == null)
         {
             throw new COMException(System.Transactions.SR.GetString("DtcTransactionManagerUnavailable"), System.Transactions.Oletx.NativeMethods.XACT_E_CONNECTION_DOWN);
         }
         resourceManagerShim.Reenlist(Convert.ToUInt32(information.proxyRecoveryInformation.Length, CultureInfo.InvariantCulture), information.proxyRecoveryInformation, out notKnownYet);
         if (OletxTransactionOutcome.Committed == notKnownYet)
         {
             xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_COMMITTED;
         }
         else if (OletxTransactionOutcome.Aborted == notKnownYet)
         {
             xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_ABORTED;
         }
         else
         {
             xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_PREPARED;
             this.StartReenlistThread();
         }
     }
     catch (COMException exception)
     {
         if (System.Transactions.Oletx.NativeMethods.XACT_E_CONNECTION_DOWN != exception.ErrorCode)
         {
             throw;
         }
         xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_PREPARED;
         this.ResourceManagerShim = null;
         this.StartReenlistThread();
         if (DiagnosticTrace.Verbose)
         {
             ExceptionConsumedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), exception);
         }
     }
     finally
     {
         resourceManagerShim = null;
     }
     return new OletxEnlistment(enlistmentNotification, xactStatus, information.proxyRecoveryInformation, this);
 }