Inheritance: System.Transactions.Transaction, System.IAsyncResult, System.IDisposable, System.Runtime.Serialization.ISerializable
コード例 #1
0
ファイル: TransactionScope.cs プロジェクト: mind0n/hive
        public TransactionScope(
            TransactionScopeOption scopeOption,
            TransactionScopeAsyncFlowOption asyncFlowOption
            )
        {
            if ( !TransactionManager._platformValidated ) TransactionManager.ValidatePlatform();

            if ( DiagnosticTrace.Verbose )
            {
                MethodEnteredTraceRecord.Trace( SR.GetString( SR.TraceSourceBase ),
                    "TransactionScope.ctor( TransactionScopeOption )"
                    );
            }

            ValidateAndSetAsyncFlowOption(asyncFlowOption);
            
            if ( NeedToCreateTransaction( scopeOption ) )
            {
                committableTransaction = new CommittableTransaction();
                expectedCurrent = committableTransaction.Clone();
            }

            if ( DiagnosticTrace.Information )
            {
                if ( null == expectedCurrent )
                {
                    TransactionScopeCreatedTraceRecord.Trace( SR.GetString( SR.TraceSourceBase ),
                        TransactionTraceIdentifier.Empty,
                        TransactionScopeResult.NoTransaction
                        );
                }
                else
                {
                    TransactionScopeResult scopeResult;

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

                    TransactionScopeCreatedTraceRecord.Trace( SR.GetString( SR.TraceSourceBase ),
                        expectedCurrent.TransactionTraceId,
                        scopeResult
                        );
                }
            }

            PushScope();
            
            if ( DiagnosticTrace.Verbose )
            {
                MethodExitedTraceRecord.Trace( SR.GetString( SR.TraceSourceBase ),
                    "TransactionScope.ctor( TransactionScopeOption )"
                    );
            }
        }
 public void Commit(Guid guid)
 {
     try
     {
         if (this.committableTx == null)
         {
             Marshal.ThrowExceptionForHR(-2147418113);
         }
         else if (this.owned)
         {
             if (guid == this.ownerGuid)
             {
                 this.committableTx.Commit();
             }
             else
             {
                 Marshal.ThrowExceptionForHR(-2147418113);
             }
         }
         else
         {
             this.committableTx.Commit();
         }
     }
     catch (TransactionException exception)
     {
         this.MapTxExceptionToHR(exception, true);
     }
     finally
     {
         this.committableTx.Dispose();
         this.committableTx = null;
         this.systemTx = null;
     }
 }
コード例 #3
0
        public FatQueueTransaction(
            IsolationLevel isolationLevel, 
            TimeSpan? timeout,
            Func<IDbConnection> connectionFactory,
            TransactionScopeOption transactionScopeOption = TransactionScopeOption.Required, 
            TransactionScopeAsyncFlowOption transactionScopeAsyncFlowOption = TransactionScopeAsyncFlowOption.Enabled)
        {
            _connectionFactory = connectionFactory;

            var transactionOptions = new TransactionOptions
            {
                IsolationLevel = isolationLevel,
            };

            if (timeout != null)
            {
                transactionOptions.Timeout = timeout.Value;
            }

            if (System.Transactions.Transaction.Current == null || transactionScopeOption == TransactionScopeOption.RequiresNew)
            {
                _transaction = new CommittableTransaction(transactionOptions);
                _transactionScope = new TransactionScope(_transaction, transactionScopeAsyncFlowOption);
            }
        }
コード例 #4
0
      internal TransactionControl(CommittableTransaction transaction)
      {
         if ( transaction == null )
            throw new ArgumentNullException("transaction");

         _transaction = transaction;
      }
        public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state()
        {
            var objectContext = new ObjectContext();
            var dbContext = DbContextMockHelper.CreateDbContext(objectContext);

            var interceptionContext = new EnlistTransactionInterceptionContext();
            interceptionContext.SuppressExecution();
            interceptionContext.Exception = new Exception("Cheez Whiz");

            var transaction = new CommittableTransaction();
            interceptionContext = interceptionContext
                .WithDbContext(dbContext)
                .WithObjectContext(objectContext)
                .WithTransaction(transaction)
                .AsAsync();

            Assert.Equal(new[] { objectContext }, interceptionContext.ObjectContexts);
            Assert.Equal(new[] { dbContext }, interceptionContext.DbContexts);
            Assert.True(interceptionContext.IsAsync);
            Assert.Same(transaction, interceptionContext.Transaction);

            Assert.Null(interceptionContext.Exception);
            Assert.Null(interceptionContext.OriginalException);
            Assert.False(interceptionContext.IsExecutionSuppressed);
        }
コード例 #6
0
 internal WorkerRunner(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
 {
     WorkerCard = workerCard;
     WorkAssignment = workAssignment;
     CommittableTransaction = committableTransaction;
     Command = Command.Run;
     quitGracefully = false;
 }
コード例 #7
0
 public byte[] Promote(INpgsqlTransactionCallbacks callbacks)
 {
     CommittableTransaction tx = new CommittableTransaction();
     DurableResourceManager rm = new DurableResourceManager(this, callbacks, tx);
     byte[] token = TransactionInterop.GetTransmitterPropagationToken(tx);
     _transactions.Add(rm.TxName, tx);
     rm.Enlist(tx);
     return token;
 }
コード例 #8
0
        protected override void CommitWorkBatch(CommitWorkBatchCallback commitWorkBatchCallback)
        {
            TraceHelper.Trace();

            Transaction transactionToUse;
            if (Transaction.Current == null)
            {
                transactionToUse = new CommittableTransaction();
                Tracer.Debug("CommitWorkBatch�ύTransactionScope����Transaction.Current==null");
            }
            else
            {
                transactionToUse = Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete);
                Tracer.Debug("CommitWorkBatch�ύTransactionScope����Transaction.Current!=null" );
            }

            TransactionCreated(transactionToUse);

            try
            {
                using (TransactionScope txScope = new TransactionScope(transactionToUse))
                {
                    commitWorkBatchCallback();
                    txScope.Complete();
                    Tracer.Debug("CommitWorkBatch�ύTransactionScope����Complete���......");
                }

                CommittableTransaction committableTransaction = transactionToUse as CommittableTransaction;
                if (committableTransaction != null)
                {
                    committableTransaction.Commit();
                    Tracer.Debug("CommitWorkBatch�ύcommittableTransaction����Complete���......");
                }

                DependentTransaction dependentTransaction = transactionToUse as DependentTransaction;
                if (dependentTransaction != null)
                {
                    dependentTransaction.Complete();
                    Tracer.Debug("CommitWorkBatch�ύdependentTransaction����Complete���......");
                }

                WorkBatchCommitted(transactionToUse);
            }
            catch (Exception e)
            {
                transactionToUse.Rollback(e);

                WorkBatchRolledback(transactionToUse);

                throw;
            }
            finally
            {
                if (transactionToUse != null)
                    transactionToUse.Dispose();
            }
        }
 public TransactionProxy(DtcIsolationLevel isoLevel, int timeout)
 {
     TransactionOptions options = new TransactionOptions {
         Timeout = TimeSpan.FromSeconds((double) timeout),
         IsolationLevel = ConvertIsolationLevelFromDtc(isoLevel)
     };
     this.committableTx = new CommittableTransaction(options);
     this.systemTx = this.committableTx.Clone();
     this.owned = false;
 }
コード例 #10
0
        public byte[] Promote(ITransactionExecutionEnvironment transactionExecutionEnvironment)
        {
            var promotedTx = new CommittableTransaction();
            var neo4jTransactionHandler = new Neo4jTransationSinglePhaseNotification(transactionExecutionEnvironment);
            var token = TransactionInterop.GetTransmitterPropagationToken(promotedTx);
            _transactions[transactionExecutionEnvironment.TransactionId] = promotedTx;
            neo4jTransactionHandler.Enlist(promotedTx);

            return token;
        }
コード例 #11
0
		public FileTransaction(string name, CommittableTransaction inner, uint stackDepth, ITransactionOptions creationOptions,
		                       Action onDispose)
		{
			Contract.Requires(inner != null);
			Contract.Requires(creationOptions != null);

			_Inner = new Transaction(inner, stackDepth, creationOptions, onDispose);

			_Name = name;
			InnerBegin();
		}
コード例 #12
0
ファイル: Server.cs プロジェクト: AlanLiu-AI/Buzz
 public byte[] Promote()
 {
     Log.Info("PSPEDBServer.Promote");
     this.tx = new CommittableTransaction();
     //Debug.Assert(this.internalServerRM == null);
     if (this.internalServerRM != null) Log.Error("this.internalServerRM != null");
     // the following statement will cause the transaction to be promoted to MSDTC
     byte[] txToken = TransactionInterop.GetTransmitterPropagationToken(this.tx);
     Enlist(txToken);
     return txToken;
 }
コード例 #13
0
		public void Dispose_ITransaction_using_IDisposable_should_run_action()
		{
			var actionWasCalled = false;

			var opt = new DefaultTransactionOptions();
			var cmt = new CommittableTransaction();

			using (ITransaction tx = new Transaction(cmt, 1, opt, () => actionWasCalled = true))
				tx.Complete();

			Assert.That(actionWasCalled);
		}
コード例 #14
0
 public static void GoAndRollback(Action action)
 {
     var transaction = new CommittableTransaction(new TransactionOptions
     {
         IsolationLevel = IsolationLevel.ReadCommitted
     });
     using (var scope = new TransactionScope(transaction))
     {
         action();
         scope.Dispose();
     }
 }
 internal InternalTransaction(TimeSpan timeout, CommittableTransaction committableTransaction)
 {
     if (!TransactionManager._platformValidated)
     {
         TransactionManager.ValidatePlatform();
     }
     this.absoluteTimeout = TransactionManager.TransactionTable.TimeoutTicks(timeout);
     TransactionState._TransactionStateActive.EnterState(this);
     this.promoteState = TransactionState._TransactionStatePromoted;
     this.committableTransaction = committableTransaction;
     this.outcomeSource = committableTransaction;
     this.transactionHash = TransactionManager.TransactionTable.Add(this);
 }
コード例 #16
0
 internal TransactedBatchContext(SharedTransactedBatchContext shared)
 {
     this.shared = shared;
     this.transaction = TransactionBehavior.CreateTransaction(shared.IsolationLevel, shared.TransactionTimeout);
     this.transaction.EnlistVolatile(this, EnlistmentOptions.None);
     if (shared.TransactionTimeout <= TimeSpan.Zero)
         this.commitNotLaterThan = DateTime.MaxValue;
     else
         this.commitNotLaterThan = DateTime.UtcNow + TimeSpan.FromMilliseconds(shared.TransactionTimeout.TotalMilliseconds * 4 / 5);
     this.commits = 0;
     this.batchFinished = false;
     this.inDispatch = false;
 }
コード例 #17
0
 public SqlConnection GetConnection(CommittableTransaction transaction = null)
 {
     if (Connection.IsNull())
     {
         Connection = new SqlConnection(Runtime.Context.GetDefaultConnectionString());
         if (transaction.IsInstance())
         {
             Connection.Open();
             Connection.EnlistTransaction(transaction);
         }
     }
     return Connection;
 }
コード例 #18
0
 public WorkflowPersistenceContext(bool transactionRequired, Transaction transactionToUse, TimeSpan transactionTimeout)
 {
     if (transactionToUse != null)
     {
         this.clonedTransaction = transactionToUse;
     }
     else if (transactionRequired)
     {
         this.contextOwnedTransaction = new CommittableTransaction(transactionTimeout);
         // Clone it so that we don't pass a CommittableTransaction to the participants
         this.clonedTransaction = this.contextOwnedTransaction.Clone();
     }
 }
コード例 #19
0
ファイル: Transaction.cs プロジェクト: bittercoder/Windsor
		public Transaction(CommittableTransaction committable, uint stackDepth, ITransactionOptions creationOptions,
		                   Action onDispose)
		{
			Contract.Requires(creationOptions != null);
			Contract.Requires(committable != null);
			Contract.Ensures(_State == TransactionState.Active);
			Contract.Ensures(((ITransaction)this).State == TransactionState.Active);

			_Committable = committable;
			_CreationOptions = creationOptions;
			_OnDispose = onDispose;
			_State = TransactionState.Active;
			_LocalIdentifier = committable.TransactionInformation.LocalIdentifier + ":" + stackDepth;
		}
コード例 #20
0
ファイル: AsyncTest.cs プロジェクト: nlhepler/mono
		public void AsyncFail1 ()
		{
			IntResourceManager irm = new IntResourceManager ( 1 );

			CommittableTransaction ct = new CommittableTransaction ();
			/* Set ambient Tx */
			Transaction.Current = ct;

			/* Enlist */
			irm.Value = 2;

			IAsyncResult ar = ct.BeginCommit ( null, null );
			IAsyncResult ar2 = ct.BeginCommit ( null, null );
		}
コード例 #21
0
		public Transaction(CommittableTransaction inner, uint stackDepth, ITransactionOptions creationOptions,
		                   Action onDispose)
		{
			Contract.Requires(creationOptions != null);
			Contract.Requires(inner != null);
			Contract.Ensures(_Inner != null);
			Contract.Ensures(_State == TransactionState.Active);
			Contract.Ensures(((ITransaction) this).State == TransactionState.Active);
			_Inner = inner;
			_StackDepth = stackDepth;
			_CreationOptions = creationOptions;
			_OnDispose = onDispose;
			_State = TransactionState.Active;
		}
コード例 #22
0
		public FileTransaction(string name, CommittableTransaction inner, uint stackDepth, ITransactionOptions creationOptions,
								Action onDispose, ILogger logger)
		{
			Contract.Requires(inner != null);
			Contract.Requires(creationOptions != null);
			Contract.Requires(!string.IsNullOrEmpty(name));
			Contract.Requires(logger != null);
			Contract.Ensures(_Name != null);

			_Inner = new Transaction(inner, stackDepth, creationOptions, onDispose, logger.CreateChildLogger("Transaction"));

			_Name = name;
			InnerBegin();
		}
コード例 #23
0
ファイル: AsyncTest.cs プロジェクト: nlhepler/mono
		public void AsyncFail2 ()
		{
			IntResourceManager irm = new IntResourceManager ( 1 );

			CommittableTransaction ct = new CommittableTransaction ();
			/* Set ambient Tx */
			Transaction.Current = ct;

			/* Enlist */
			irm.Value = 2;
			irm.FailPrepare = true;

			IAsyncResult ar = ct.BeginCommit ( null, null );

			ct.EndCommit ( ar );
		}
コード例 #24
0
        public void EnlistTransaction_executes_operation_and_dispatches_to_interceptors()
        {
            var mockConnection = new Mock<DbConnection>();
            var mockInterceptor = new Mock<IDbConnectionInterceptor>();
            var dispatcher = new DbConnectionDispatcher();
            var internalDispatcher = dispatcher.InternalDispatcher;
            internalDispatcher.Add(mockInterceptor.Object);

            var transaction = new CommittableTransaction();
            var interceptionContext = new EnlistTransactionInterceptionContext().WithTransaction(transaction);
            dispatcher.EnlistTransaction(mockConnection.Object, interceptionContext);

            mockConnection.Verify(m => m.EnlistTransaction(transaction), Times.Once());
            mockInterceptor.Verify(m => m.EnlistingTransaction(mockConnection.Object, It.IsAny<EnlistTransactionInterceptionContext>()), Times.Once());
            mockInterceptor.Verify(m => m.EnlistedTransaction(mockConnection.Object, It.IsAny<EnlistTransactionInterceptionContext>()), Times.Once());
        }
コード例 #25
0
ファイル: UnitTestBase.cs プロジェクト: viniston/AV
        public void BaseTestInitialize()
        {
            if (Transaction.Current != null)
            {
                Assert.Inconclusive();
            }

            var committableTransaction = _transaction as CommittableTransaction;
            
            if (committableTransaction == null)
            {
                committableTransaction = new CommittableTransaction();
                Transaction.Current = committableTransaction;
            } 

            Logger.Instance.Debug("UnitTestBase", "TestCleanup", "Start Transaction - " + Transaction.Current.TransactionInformation.LocalIdentifier);
        }
コード例 #26
0
		public void AsyncFail1 ()
		{
            ExceptionAssert.Throws<InvalidOperationException>(
		        delegate
		            {
		                IntResourceManager irm = new IntResourceManager(1);

		                CommittableTransaction ct = new CommittableTransaction();
		                /* Set ambient Tx */
		                Transaction.Current = ct;

		                /* Enlist */
		                irm.Value = 2;

		                IAsyncResult ar = ct.BeginCommit(null, null);
		                IAsyncResult ar2 = ct.BeginCommit(null, null);
		            });
		}
コード例 #27
0
 // If the transaction has aborted then we switch over to a new transaction
 // which we will immediately abort after setting Transaction.Current
 public static TransactionScope CreateTransactionScope(Transaction transaction)
 {
     try
     {
         return transaction == null ? null : new TransactionScope(transaction);
     }
     catch (TransactionAbortedException)
     {
         CommittableTransaction tempTransaction = new CommittableTransaction();
         try
         {
             return new TransactionScope(tempTransaction.Clone());
         }
         finally
         {
             tempTransaction.Rollback();
         }
     }
 }
 protected internal virtual void CommitWorkBatch(CommitWorkBatchCallback commitWorkBatchCallback)
 {
     Transaction transactionToUse = null;
     if (null == Transaction.Current)
     {
         transactionToUse = new CommittableTransaction();
     }
     else
     {
         transactionToUse = Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete);
     }
     try
     {
         using (TransactionScope scope = new TransactionScope(transactionToUse))
         {
             commitWorkBatchCallback();
             scope.Complete();
         }
         CommittableTransaction transaction2 = transactionToUse as CommittableTransaction;
         if (transaction2 != null)
         {
             transaction2.Commit();
         }
         DependentTransaction transaction3 = transactionToUse as DependentTransaction;
         if (transaction3 != null)
         {
             transaction3.Complete();
         }
     }
     catch (Exception exception)
     {
         transactionToUse.Rollback(exception);
         throw;
     }
     finally
     {
         if (transactionToUse != null)
         {
             transactionToUse.Dispose();
         }
     }
 }
 public void Abort()
 {
     try
     {
         this.systemTx.Rollback();
     }
     catch (TransactionException exception)
     {
         this.MapTxExceptionToHR(exception);
     }
     finally
     {
         if (this.committableTx != null)
         {
             this.committableTx.Dispose();
             this.committableTx = null;
             this.systemTx = null;
         }
     }
 }
 public TransactionScope(TransactionScopeOption scopeOption)
 {
     if (!TransactionManager._platformValidated)
     {
         TransactionManager.ValidatePlatform();
     }
     if (DiagnosticTrace.Verbose)
     {
         MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), "TransactionScope.ctor( TransactionScopeOption )");
     }
     if (this.NeedToCreateTransaction(scopeOption))
     {
         this.committableTransaction = new CommittableTransaction();
         this.expectedCurrent = this.committableTransaction.Clone();
     }
     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 )");
     }
 }
コード例 #31
0
        /// <summary>
        /// Creates a transaction.
        /// </summary>
        public Transaction()
        {
            // This class is intended to be a thin wrapper around the Framework class.  The transactions have an unlimited
            // lifetime, but that will likely change as the deadlocking scenarios are tested.
            this.committableTransaction = new CommittableTransaction(TimeSpan.Zero);

            // Every transaction can have one or more resources (which is another name for a data store).  Typically there will be
            // one ADO data model in memory and one or more SQL data stores which serve as the non-volatile repository for the
            // data.  The resources are referenced by name once a transaction is started.  A method that implements an operation in
            // the transaction needs to only know the names of the resources, not the details of the connection to them.
            this.resourceTable = new Dictionary <string, ResourceManager>();

            // Every thread has a stack of transactions that allows for nested transactions like their Framework counterparts.  If
            // a transaction is already running in this thread, then that transaction is used.  Otherwise a new stack for the
            // thread is created.
            Stack <Transaction> transactionStack = null;

            if (!Transaction.threadMappings.TryGetValue(Thread.CurrentThread.ManagedThreadId, out transactionStack))
            {
                transactionStack = new Stack <Transaction>();
                Transaction.threadMappings.Add(Thread.CurrentThread.ManagedThreadId, transactionStack);
            }
            transactionStack.Push(this);
        }
コード例 #32
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, nameof(transactionOptions));
                    }
                }
            }

            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);
            }
        }
コード例 #33
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);
            }
        }