// SetCurrent
        //
        // Place the given value in current by whatever means necessary for interop mode.
        private void SetCurrent(Transaction newCurrent)
        {
            // Keep a dependent clone of current if we don't have one and we are not committable
            if (_dependentTransaction == null && _committableTransaction == null)
            {
                if (newCurrent != null)
                {
                    _dependentTransaction = newCurrent.DependentClone(DependentCloneOption.RollbackIfNotComplete);
                }
            }

            switch (_interopOption)
            {
            case EnterpriseServicesInteropOption.None:
                _threadContextData.CurrentTransaction = newCurrent;
                break;

            case EnterpriseServicesInteropOption.Automatic:
                EnterpriseServices.VerifyEnterpriseServicesOk();
                if (EnterpriseServices.UseServiceDomainForCurrent())
                {
                    EnterpriseServices.PushServiceDomain(newCurrent);
                }
                else
                {
                    _threadContextData.CurrentTransaction = newCurrent;
                }
                break;

            case EnterpriseServicesInteropOption.Full:
                EnterpriseServices.VerifyEnterpriseServicesOk();
                EnterpriseServices.PushServiceDomain(newCurrent);
                break;
            }
        }
        // RestoreCurrent
        //
        // Restore current to it's previous value depending on how it was changed for this scope.
        private void RestoreCurrent()
        {
            if (EnterpriseServices.CreatedServiceDomain)
            {
                EnterpriseServices.LeaveServiceDomain();
            }

            // Only restore the value that was actually in the context.
            _threadContextData.CurrentTransaction = _contextTransaction;
        }
Esempio n. 3
0
        internal static Transaction FastGetTransaction(TransactionScope currentScope, ContextData contextData, out Transaction contextTransaction)
        {
            Transaction current = null;

            contextTransaction = null;

            contextTransaction = contextData.CurrentTransaction;

            switch (InteropMode(currentScope))
            {
            case EnterpriseServicesInteropOption.None:

                current = contextTransaction;

                // If there is a transaction in the execution context or if there is a current transaction scope
                // then honer the transaction context.
                if (current == null && currentScope == null)
                {
                    // Otherwise check for an external current.
                    if (TransactionManager.s_currentDelegateSet)
                    {
                        current = TransactionManager.s_currentDelegate();
                    }
                    else
                    {
                        current = EnterpriseServices.GetContextTransaction(contextData);
                    }
                }
                break;

            case EnterpriseServicesInteropOption.Full:
                current = EnterpriseServices.GetContextTransaction(contextData);
                break;

            case EnterpriseServicesInteropOption.Automatic:
                if (EnterpriseServices.UseServiceDomainForCurrent())
                {
                    current = EnterpriseServices.GetContextTransaction(contextData);
                }
                else
                {
                    current = contextData.CurrentTransaction;
                }
                break;
            }

            return(current);
        }