public EnqueueAndSendAsyncResult(Message message, TimeSpan timeout, MakeConnectionDispatcher dispatcher, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.dispatcher    = dispatcher;
                this.message       = message;
                this.timeoutHelper = new TimeoutHelper(timeout);

                MessagePendingHeader.AddToMessage(message, this.dispatcher.HasPendingSends);

                if (message.Headers.RelatesTo == null || !this.dispatcher.TryGetContextForMessageId(message.Headers.RelatesTo, out this.context))
                {
                    IAsyncResult result = dispatcher.contexts.BeginDequeue(timeoutHelper.RemainingTime(), onContextDequeueCompleted, this);
                    if (result.CompletedSynchronously)
                    {
                        if (OnContextDequeueCompletedCore(result))
                        {
                            base.Complete(true);
                        }
                    }
                }
                else
                {
                    IAsyncResult result = this.context.BeginTryReply(this.message, this.timeoutHelper.RemainingTime(), onReplyCompleted, this);
                    if (result.CompletedSynchronously)
                    {
                        if (OnReplyCompletedCore(result))
                        {
                            base.Complete(true);
                        }
                    }
                }
            }
Esempio n. 2
0
 public override void EnqueueAndDispatch(Message message, Action dequeuedCallback, bool canDispatchOnThisThread)
 {
     // FindHeader will mark as understood if present,
     // but we do not process this header since we are always polling
     MessagePendingHeader.FindHeader(message);
     base.EnqueueAndDispatch(message, dequeuedCallback, canDispatchOnThisThread);
 }
        public void EnqueueAndSendMessage(Message message, TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            MakeConnectionRequestContext context;

            MessagePendingHeader.AddToMessage(message, this.HasPendingSends);
            do
            {
                if (message.Headers.RelatesTo == null || !TryGetContextForMessageId(message.Headers.RelatesTo, out context))
                {
                    context = contexts.Dequeue(timeoutHelper.RemainingTime());
                }
            } while (!context.TryReply(message, timeoutHelper.RemainingTime()));
        }