Пример #1
0
            public ReplyAsyncResult(Message message, ContextChannelRequestContext context, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
            {
                this.context       = context;
                this.message       = this.replyMessage = message;
                this.timeoutHelper = new TimeoutHelper(timeout);
                bool flag = true;

                if (message != null)
                {
                    this.context.contextProtocol.OnOutgoingMessage(message, this.context);
                    if (CorrelationCallbackMessageProperty.TryGet(message, out this.correlationCallback))
                    {
                        ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(this.correlationCallback, message, false);
                        if (this.correlationCallback.IsFullyDefined)
                        {
                            IAsyncResult result = this.correlationCallback.BeginFinalizeCorrelation(this.message, this.timeoutHelper.RemainingTime(), onFinalizeCorrelation, this);
                            if (result.CompletedSynchronously && this.OnFinalizeCorrelationCompleted(result))
                            {
                                base.Complete(true);
                            }
                            flag = false;
                        }
                    }
                }
                if (flag)
                {
                    IAsyncResult result2 = this.context.innerContext.BeginReply(this.message, this.timeoutHelper.RemainingTime(), onReply, this);
                    if (result2.CompletedSynchronously)
                    {
                        this.OnReplyCompleted(result2);
                        base.Complete(true);
                    }
                }
            }
            public ReplyAsyncResult(Message message, ContextChannelRequestContext context, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.context = context;
                this.message = this.replyMessage = message;
                this.timeoutHelper = new TimeoutHelper(timeout);
                bool shouldReply = true;

                if (message != null)
                {
                    this.context.contextProtocol.OnOutgoingMessage(message, this.context);

                    if (CorrelationCallbackMessageProperty.TryGet(message, out this.correlationCallback))
                    {
                        ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(this.correlationCallback, message, false);

                        if (this.correlationCallback.IsFullyDefined)
                        {
                            IAsyncResult result = correlationCallback.BeginFinalizeCorrelation(this.message, this.timeoutHelper.RemainingTime(), onFinalizeCorrelation, this);
                            if (result.CompletedSynchronously)
                            {
                                if (OnFinalizeCorrelationCompleted(result))
                                {
                                    base.Complete(true);
                                }
                            }

                            shouldReply = false;
                        }
                    }
                }

                if (shouldReply)
                {
                    IAsyncResult result = this.context.innerContext.BeginReply(this.message, this.timeoutHelper.RemainingTime(), onReply, this);
                    if (result.CompletedSynchronously)
                    {
                        OnReplyCompleted(result);
                        base.Complete(true);
                    }
                }
            }