ValidateTimeout() static private method

This static function throws an ArgumentOutOfRange if the specified TimeSpan does not meet requirements of a valid transaction timeout. Timeout values must be positive.
static private ValidateTimeout ( TimeSpan transactionTimeout ) : TimeSpan
transactionTimeout TimeSpan /// The TimeSpan value to validate. ///
return TimeSpan
        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 )");
            }
        }
        public TransactionScope(TransactionScopeOption scopeOption, TimeSpan scopeTimeout)
        {
            if (!TransactionManager._platformValidated)
            {
                TransactionManager.ValidatePlatform();
            }
            if (DiagnosticTrace.Verbose)
            {
                MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), "TransactionScope.ctor( TransactionScopeOption, TimeSpan )");
            }
            this.ValidateScopeTimeout("scopeTimeout", scopeTimeout);
            TimeSpan timeout = TransactionManager.ValidateTimeout(scopeTimeout);

            if (this.NeedToCreateTransaction(scopeOption))
            {
                this.committableTransaction = new CommittableTransaction(timeout);
                this.expectedCurrent        = this.committableTransaction.Clone();
            }
            if (((null != this.expectedCurrent) && (null == this.committableTransaction)) && (TimeSpan.Zero != scopeTimeout))
            {
                this.scopeTimer = new Timer(new System.Threading.TimerCallback(TransactionScope.TimerCallback), this, scopeTimeout, 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, TimeSpan )");
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        public TransactionScope(
            TransactionScopeOption scopeOption,
            TimeSpan scopeTimeout,
            TransactionScopeAsyncFlowOption asyncFlowOption
            )
        {
            TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log;

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

            ValidateScopeTimeout(nameof(scopeTimeout), scopeTimeout);
            TimeSpan txTimeout = TransactionManager.ValidateTimeout(scopeTimeout);

            ValidateAndSetAsyncFlowOption(asyncFlowOption);

            if (NeedToCreateTransaction(scopeOption))
            {
                _committableTransaction = new CommittableTransaction(txTimeout);
                _expectedCurrent        = _committableTransaction.Clone();
            }

            if ((null != _expectedCurrent) && (null == _committableTransaction) && (TimeSpan.Zero != scopeTimeout))
            {
                // BUGBUG: Scopes should not use individual timers
                _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);
            }
        }