bool TransactedAccept(out Transaction tx)
        {
            tx = null;

            try
            {
                tx = TransactionBehavior.CreateTransaction(this.ChannelDispatcher.TransactionIsolationLevel, this.ChannelDispatcher.TransactionTimeout);

                IChannelBinder binder = null;
                using (TransactionScope scope = new TransactionScope(tx))
                {
                    TimeSpan acceptTimeout = TimeoutHelper.Min(this.ChannelDispatcher.TransactionTimeout, this.ChannelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout);
                    if (!this.acceptor.TryAccept(TransactionBehavior.NormalizeTimeout(acceptTimeout), out binder))
                    {
                        return(false);
                    }
                    scope.Complete();
                }
                if (null != binder)
                {
                    this.channel     = new ListenerChannel(binder);
                    this.idleManager = SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout);
                    return(true);
                }
                else
                {
                    this.AcceptedNull();
                    tx = null;
                    return(false);
                }
            }
            catch (CommunicationException e)
            {
                if (null != tx)
                {
                    try
                    {
                        tx.Rollback();
                    }
                    catch (TransactionException ex)
                    {
                        DiagnosticUtility.TraceHandledException(ex, TraceEventType.Information);
                    }
                }
                tx = null;

                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);

                return(false);
            }
            catch (TransactionException e)
            {
                tx = null;

                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);

                return(false);
            }
        }
Exemplo n.º 2
0
 internal SharedTransactedBatchContext(ChannelHandler handler, ChannelDispatcher dispatcher, int maxConcurrentBatches)
 {
     this.handler                     = handler;
     this.maxBatchSize                = dispatcher.MaxTransactedBatchSize;
     this.maxConcurrentBatches        = maxConcurrentBatches;
     this.currentBatchSize            = dispatcher.MaxTransactedBatchSize;
     this.currentConcurrentBatches    = 0;
     this.currentConcurrentDispatches = 0;
     this.successfullCommits          = 0;
     this.isBatching                  = true;
     this.isolationLevel              = dispatcher.TransactionIsolationLevel;
     this.txTimeout                   = TransactionBehavior.NormalizeTimeout(dispatcher.TransactionTimeout);
     BatchingStateChanged(this.isBatching);
 }
        internal TransactionBehavior(DispatchRuntime dispatch)
        {
            this.isConcurrent = (dispatch.ConcurrencyMode == ConcurrencyMode.Multiple ||
                                 dispatch.ConcurrencyMode == ConcurrencyMode.Reentrant);

            this.dispatch = dispatch;
            this.isTransactedReceiveChannelDispatcher = dispatch.ChannelDispatcher.IsTransactedReceive;

            // Don't pull in System.Transactions.dll if we don't need it
            if (dispatch.ChannelDispatcher.TransactionIsolationLevelSet)
            {
                this.InitializeIsolationLevel(dispatch);
            }

            this.timeout = TransactionBehavior.NormalizeTimeout(dispatch.ChannelDispatcher.TransactionTimeout);
        }