ValidateIsolationLevel() static private method

This static function throws an ArgumentOutOfRange if the specified IsolationLevel is not within the range of valid values.
static private ValidateIsolationLevel ( IsolationLevel transactionIsolationLevel ) : void
transactionIsolationLevel IsolationLevel /// The IsolationLevel value to validate. ///
return void
        public TransactionScope(TransactionScopeOption scopeOption, TransactionOptions transactionOptions, EnterpriseServicesInteropOption interopOption)
        {
            if (!TransactionManager._platformValidated)
            {
                TransactionManager.ValidatePlatform();
            }
            if (DiagnosticTrace.Verbose)
            {
                MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), "TransactionScope.ctor( TransactionScopeOption, TransactionOptions, EnterpriseServicesInteropOption )");
            }
            this.ValidateScopeTimeout("transactionOptions.Timeout", transactionOptions.Timeout);
            TimeSpan timeout = transactionOptions.Timeout;

            transactionOptions.Timeout = TransactionManager.ValidateTimeout(transactionOptions.Timeout);
            TransactionManager.ValidateIsolationLevel(transactionOptions.IsolationLevel);
            this.ValidateInteropOption(interopOption);
            this.interopModeSpecified = true;
            this.interopOption        = interopOption;
            if (this.NeedToCreateTransaction(scopeOption))
            {
                this.committableTransaction = new CommittableTransaction(transactionOptions);
                this.expectedCurrent        = this.committableTransaction.Clone();
            }
            else if (((null != this.expectedCurrent) && (IsolationLevel.Unspecified != transactionOptions.IsolationLevel)) && (this.expectedCurrent.IsolationLevel != transactionOptions.IsolationLevel))
            {
                throw new ArgumentException(System.Transactions.SR.GetString("TransactionScopeIsolationLevelDifferentFromTransaction"), "transactionOptions.IsolationLevel");
            }
            if (((null != this.expectedCurrent) && (null == this.committableTransaction)) && (TimeSpan.Zero != timeout))
            {
                this.scopeTimer = new Timer(new System.Threading.TimerCallback(TransactionScope.TimerCallback), this, timeout, TimeSpan.Zero);
            }
            if (DiagnosticTrace.Information)
            {
                if (null == this.expectedCurrent)
                {
                    TransactionScopeCreatedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), TransactionTraceIdentifier.Empty, TransactionScopeResult.NoTransaction);
                }
                else
                {
                    TransactionScopeResult usingExistingCurrent;
                    if (null == this.committableTransaction)
                    {
                        usingExistingCurrent = TransactionScopeResult.UsingExistingCurrent;
                    }
                    else
                    {
                        usingExistingCurrent = TransactionScopeResult.CreatedTransaction;
                    }
                    TransactionScopeCreatedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), this.expectedCurrent.TransactionTraceId, usingExistingCurrent);
                }
            }
            this.PushScope();
            if (DiagnosticTrace.Verbose)
            {
                MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), "TransactionScope.ctor( TransactionScopeOption, TransactionOptions, EnterpriseServicesInteropOption )");
            }
        }
 internal Transaction(System.Transactions.IsolationLevel isoLevel, InternalTransaction internalTransaction)
 {
     TransactionManager.ValidateIsolationLevel(isoLevel);
     this.isoLevel = isoLevel;
     if (System.Transactions.IsolationLevel.Unspecified == this.isoLevel)
     {
         this.isoLevel = TransactionManager.DefaultIsolationLevel;
     }
     if (internalTransaction != null)
     {
         this.internalTransaction = internalTransaction;
         this.cloneId             = Interlocked.Increment(ref this.internalTransaction.cloneCount);
     }
 }
 internal Transaction(System.Transactions.IsolationLevel isoLevel, ISimpleTransactionSuperior superior)
 {
     TransactionManager.ValidateIsolationLevel(isoLevel);
     if (superior == null)
     {
         throw new ArgumentNullException("superior");
     }
     this.isoLevel = isoLevel;
     if (System.Transactions.IsolationLevel.Unspecified == this.isoLevel)
     {
         this.isoLevel = TransactionManager.DefaultIsolationLevel;
     }
     this.internalTransaction = new InternalTransaction(this, superior);
     this.cloneId             = 1;
 }
Esempio n. 4
0
        internal Transaction(IsolationLevel isoLevel, ISimpleTransactionSuperior superior)
        {
            TransactionManager.ValidateIsolationLevel(isoLevel);
            ArgumentNullException.ThrowIfNull(superior);

            _isoLevel = isoLevel;

            // Never create a transaction with an IsolationLevel of Unspecified.
            if (IsolationLevel.Unspecified == _isoLevel)
            {
                _isoLevel = TransactionManager.DefaultIsolationLevel;
            }

            _internalTransaction = new InternalTransaction(this, superior);
            // ISimpleTransactionSuperior is defined to also promote to MSDTC.
            _internalTransaction.SetPromoterTypeToMSDTC();
            _cloneId = 1;
        }
Esempio n. 5
0
        // Create a transaction with the given settings
        //
        internal Transaction(IsolationLevel isoLevel, InternalTransaction?internalTransaction)
        {
            TransactionManager.ValidateIsolationLevel(isoLevel);

            _isoLevel = isoLevel;

            // Never create a transaction with an IsolationLevel of Unspecified.
            if (IsolationLevel.Unspecified == _isoLevel)
            {
                _isoLevel = TransactionManager.DefaultIsolationLevel;
            }

            if (internalTransaction != null)
            {
                _internalTransaction = internalTransaction;
                _cloneId             = Interlocked.Increment(ref _internalTransaction._cloneCount);
            }
            else
            {
                // Null is passed from the constructor of a CommittableTransaction.  That
                // constructor will fill in the traceIdentifier because it has allocated the
                // internal transaction.
            }
        }
Esempio n. 6
0
        public TransactionScope(
            TransactionScopeOption scopeOption,
            TransactionOptions transactionOptions,
            EnterpriseServicesInteropOption interopOption)
        {
            TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log;

            if (etwLog.IsEnabled())
            {
                etwLog.MethodEnter(TraceSourceType.TraceSourceBase, this);
            }

            ValidateScopeTimeout("transactionOptions.Timeout", transactionOptions.Timeout);
            TimeSpan scopeTimeout = transactionOptions.Timeout;

            transactionOptions.Timeout = TransactionManager.ValidateTimeout(transactionOptions.Timeout);
            TransactionManager.ValidateIsolationLevel(transactionOptions.IsolationLevel);

            ValidateInteropOption(interopOption);
            _interopModeSpecified = true;
            _interopOption        = interopOption;

            if (NeedToCreateTransaction(scopeOption))
            {
                _committableTransaction = new CommittableTransaction(transactionOptions);
                _expectedCurrent        = _committableTransaction.Clone();
            }
            else
            {
                if (null != _expectedCurrent)
                {
                    // If the requested IsolationLevel is stronger than that of the specified transaction, throw.
                    if ((IsolationLevel.Unspecified != transactionOptions.IsolationLevel) && (_expectedCurrent.IsolationLevel != transactionOptions.IsolationLevel))
                    {
                        throw new ArgumentException(SR.TransactionScopeIsolationLevelDifferentFromTransaction, "transactionOptions.IsolationLevel");
                    }
                }
            }

            if ((null != _expectedCurrent) && (null == _committableTransaction) && (TimeSpan.Zero != scopeTimeout))
            {
                // BUGBUG: Scopes should use a shared timer
                _scopeTimer = new Timer(
                    TimerCallback,
                    this,
                    scopeTimeout,
                    TimeSpan.Zero);
            }

            if (null == _expectedCurrent)
            {
                if (etwLog.IsEnabled())
                {
                    etwLog.TransactionScopeCreated(TransactionTraceIdentifier.Empty, TransactionScopeResult.NoTransaction);
                }
            }
            else
            {
                TransactionScopeResult scopeResult;

                if (null == _committableTransaction)
                {
                    scopeResult = TransactionScopeResult.UsingExistingCurrent;
                }
                else
                {
                    scopeResult = TransactionScopeResult.CreatedTransaction;
                }

                if (etwLog.IsEnabled())
                {
                    etwLog.TransactionScopeCreated(_expectedCurrent.TransactionTraceId, scopeResult);
                }
            }

            PushScope();

            if (etwLog.IsEnabled())
            {
                etwLog.MethodExit(TraceSourceType.TraceSourceBase, this);
            }
        }