Beispiel #1
0
            protected override IEnumerator <AsyncStep> GetAsyncSteps()
            {
                if (this.owner.initializeTask.IsFaulted)
                {
                    throw this.owner.initializeTask.Exception.GetBaseException();
                }

                if (!this.owner.initializeTask.IsCompleted)
                {
                    yield return(this.CallAsync(
                                     (thisPtr, t, c, s) => new TaskAsyncResult(this.owner.initializeTask, c, s),
                                     (thisPtr, r) => TaskAsyncResult.End(r),
                                     ExceptionPolicy.Transfer));
                }

                foreach (Message message in this.messages)
                {
                    int partitionId = GetPartitionId(message);

                    List <Message> messageList;
                    if (!this.partitionedMessages.TryGetValue(partitionId, out messageList))
                    {
                        messageList = new List <Message>();
                        this.partitionedMessages.Add(partitionId, messageList);
                    }

                    messageList.Add(message);
                }

                yield return(this.CallParallelAsync(
                                 partitionedMessages,
                                 (thisPtr, i, t, c, s) => thisPtr.owner.senders[i.Key].BeginSend(MessageConverter.ToBrokeredMessages(i.Value), c, s),
                                 (thisPtr, i, r) => thisPtr.owner.senders[i.Key].EndSend(r),
                                 ExceptionPolicy.Transfer));
            }
            protected override IEnumerator <AsyncStep> GetAsyncSteps()
            {
                this.shouldContinue = true;

                while (this.shouldContinue)
                {
                    this.internalMessage = null;

                    yield return(this.CallAsync(
                                     (thisPtr, t, c, s) => thisPtr.owner.inputQueue.BeginDequeue(TimeSpan.MaxValue, c, s),
                                     (thisPtr, r) => thisPtr.internalMessage = thisPtr.owner.inputQueue.EndDequeue(r),
                                     ExceptionPolicy.Continue));

                    if (this.LastAsyncStepException != null)
                    {
                        Log.MessageDispatcherDequeueException(this.LastAsyncStepException);
                    }

                    if (this.internalMessage == null)
                    {
                        break;
                    }

                    yield return(this.CallAsync(
                                     (thisPtr, t, c, s) =>
                    {
                        Task task = this.owner.onReceivedAsync(internalMessage.Stream, internalMessage.Id, internalMessage.Messages);
                        return new TaskAsyncResult(task, c, s);
                    },
                                     (thisPtr, r) => TaskAsyncResult.End(r),
                                     ExceptionPolicy.Continue));

                    if (this.LastAsyncStepException != null)
                    {
                        Log.MessageDispatcherErrorInCallback(this.LastAsyncStepException);
                    }
                }
            }