Esempio n. 1
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();
                }
            }
        }
 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();
         }
     }
 }
Esempio n. 3
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 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);
 }