private void MapTxExceptionToHR(TransactionException txException, bool isInCommit)
        {
            TransactionAbortedException exception = txException as TransactionAbortedException;

            if (exception != null)
            {
                if (isInCommit)
                {
                    TransactionProxyException.ThrowTransactionProxyException(-2147164158, exception);
                }
                else
                {
                    TransactionProxyException.ThrowTransactionProxyException(-2147164157, exception);
                }
            }
            TransactionManagerCommunicationException exception2 = txException as TransactionManagerCommunicationException;

            if (exception2 != null)
            {
                TransactionProxyException.ThrowTransactionProxyException(-2147164145, exception2);
            }
            COMException baseException = txException.GetBaseException() as COMException;

            if (baseException != null)
            {
                TransactionProxyException.ThrowTransactionProxyException(baseException.ErrorCode, txException);
            }
            else
            {
                TransactionProxyException.ThrowTransactionProxyException(-2147418113, txException);
            }
        }
Esempio n. 2
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;
                 }
             }
         }
     }
 }
Esempio n. 3
0
    private void Initialize()
    {
        if (_whereabouts is not null)
        {
            return;
        }

        OletxInternalResourceManager internalRM = _oletxTm.InternalResourceManager;
        bool nodeNameMatches;

        try
        {
            _proxyShimFactory.ConnectToProxy(
                _nodeName,
                internalRM.Identifier,
                internalRM,
                out nodeNameMatches,
                out _whereabouts,
                out ResourceManagerShim resourceManagerShim);

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

            // Give the IResourceManagerShim to the internalRM and tell it to call ReenlistComplete.
            internalRM.ResourceManagerShim = resourceManagerShim;
            internalRM.CallReenlistComplete();
        }
        catch (COMException ex)
        {
            if (ex.ErrorCode == OletxHelper.XACT_E_NOTSUPPORTED)
            {
                throw new NotSupportedException(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.TransactionManagerCommunicationException, ex);
        }
    }
Esempio n. 4
0
 internal static void ProxyException(COMException comException)
 {
     if ((System.Transactions.Oletx.NativeMethods.XACT_E_CONNECTION_DOWN == comException.ErrorCode) || (System.Transactions.Oletx.NativeMethods.XACT_E_TMNOTAVAILABLE == comException.ErrorCode))
     {
         throw TransactionManagerCommunicationException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("TransactionManagerCommunicationException"), comException);
     }
     if (System.Transactions.Oletx.NativeMethods.XACT_E_NETWORK_TX_DISABLED == comException.ErrorCode)
     {
         throw TransactionManagerCommunicationException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("NetworkTransactionsDisabled"), comException);
     }
     if ((System.Transactions.Oletx.NativeMethods.XACT_E_FIRST <= comException.ErrorCode) && (System.Transactions.Oletx.NativeMethods.XACT_E_LAST >= comException.ErrorCode))
     {
         if (System.Transactions.Oletx.NativeMethods.XACT_E_NOTRANSACTION == comException.ErrorCode)
         {
             throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), System.Transactions.SR.GetString("TransactionAlreadyOver"), comException);
         }
         throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceOletx"), comException.Message, comException);
     }
 }
Esempio n. 5
0
        internal static void ProxyException(
            COMException comException
            )
        {
            if ((NativeMethods.XACT_E_CONNECTION_DOWN == comException.ErrorCode) ||
                (NativeMethods.XACT_E_TMNOTAVAILABLE == comException.ErrorCode)
                )
            {
                throw TransactionManagerCommunicationException.Create(
                          SR.GetString(SR.TraceSourceOletx),
                          SR.GetString(SR.TransactionManagerCommunicationException),
                          comException
                          );
            }
            if ((NativeMethods.XACT_E_NETWORK_TX_DISABLED == comException.ErrorCode))
            {
                throw TransactionManagerCommunicationException.Create(
                          SR.GetString(SR.TraceSourceOletx),
                          SR.GetString(SR.NetworkTransactionsDisabled),
                          comException
                          );
            }
            // Else if the error is a transaction oriented error, throw a TransactionException
            else if ((NativeMethods.XACT_E_FIRST <= comException.ErrorCode) &&
                     (NativeMethods.XACT_E_LAST >= comException.ErrorCode))
            {
                // Special casing XACT_E_NOTRANSACTION
                if (NativeMethods.XACT_E_NOTRANSACTION == comException.ErrorCode)
                {
                    throw TransactionException.Create(
                              SR.GetString(SR.TraceSourceOletx),
                              SR.GetString(SR.TransactionAlreadyOver),
                              comException
                              );
                }

                throw TransactionException.Create(
                          SR.GetString(SR.TraceSourceOletx),
                          comException.Message,
                          comException
                          );
            }
        }
        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;
                    }
                }
            }
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
    internal OletxEnlistment EnlistDurable(
        OletxTransaction oletxTransaction,
        bool canDoSinglePhase,
        IEnlistmentNotificationInternal enlistmentNotification,
        EnlistmentOptions enlistmentOptions)
    {
        ResourceManagerShim?localResourceManagerShim;

        Debug.Assert(oletxTransaction != null, "Argument is null");
        Debug.Assert(enlistmentNotification != null, "Argument is null");

        EnlistmentShim       enlistmentShim;
        Phase0EnlistmentShim phase0Shim;
        Guid txUow = Guid.Empty;
        bool undecidedEnlistmentsIncremented = false;

        // Create our enlistment object.
        OletxEnlistment enlistment = new(
            canDoSinglePhase,
            enlistmentNotification,
            oletxTransaction.RealTransaction.TxGuid,
            enlistmentOptions,
            this,
            oletxTransaction);

        bool enlistmentSucceeded = false;

        try
        {
            if ((enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != 0)
            {
                oletxTransaction.RealTransaction.IncrementUndecidedEnlistments();
                undecidedEnlistmentsIncremented = true;
            }

            // This entire sequence needs to be executed before we can go on.
            lock (enlistment)
            {
                try
                {
                    // Do the enlistment on the proxy.
                    localResourceManagerShim = ResourceManagerShim;
                    if (localResourceManagerShim == null)
                    {
                        // The TM must be down.  Throw the appropriate exception.
                        throw TransactionManagerCommunicationException.Create(SR.TraceSourceOletx, null);
                    }

                    if ((enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != 0)
                    {
                        oletxTransaction.RealTransaction.TransactionShim.Phase0Enlist(enlistment, out phase0Shim);
                        enlistment.Phase0EnlistmentShim = phase0Shim;
                    }

                    localResourceManagerShim.Enlist(oletxTransaction.RealTransaction.TransactionShim, enlistment, out enlistmentShim);

                    enlistment.EnlistmentShim = enlistmentShim;
                }
                catch (COMException comException)
                {
                    // There is no string mapping for XACT_E_TOOMANY_ENLISTMENTS, so we need to do it here.
                    if (comException.ErrorCode == OletxHelper.XACT_E_TOOMANY_ENLISTMENTS)
                    {
                        throw TransactionException.Create(
                                  SR.OletxTooManyEnlistments,
                                  comException,
                                  enlistment == null ? Guid.Empty : enlistment.DistributedTxId);
                    }

                    OletxTransactionManager.ProxyException(comException);

                    throw;
                }
            }

            enlistmentSucceeded = true;
        }
        finally
        {
            if (!enlistmentSucceeded &&
                (enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != 0 &&
                undecidedEnlistmentsIncremented)
            {
                oletxTransaction.RealTransaction.DecrementUndecidedEnlistments();
            }
        }

        return(enlistment);
    }