예제 #1
0
        /// <summary>
        /// The send operation used to send a <see cref="PayloadTypes.Response"/>.
        /// </summary>
        /// <param name="id">The ID to assign to the <see cref="ResponseDisassembler"/> used by this operation.</param>
        /// <param name="response">The response to send.</param>
        /// <returns>A task representing the status of the operation.</returns>
        public async Task SendResponseAsync(Guid id, StreamingResponse response)
        {
            var disassembler = new ResponseDisassembler(_payloadSender, id, response);

            await disassembler.DisassembleAsync().ConfigureAwait(false);

            if (response.Streams != null)
            {
                var tasks = new List <Task>(response.Streams.Count);
                foreach (var contentStream in response.Streams)
                {
                    var contentDisassembler = new ResponseMessageStreamDisassembler(_payloadSender, contentStream);

                    tasks.Add(contentDisassembler.DisassembleAsync());
                }

                await Task.WhenAll(tasks).ConfigureAwait(false);
            }
        }
예제 #2
0
        /// <summary>
        /// The send operation used to send a <see cref="StreamingRequest"/>.
        /// </summary>
        /// <param name="id">The ID to assign to the <see cref="RequestDisassembler"/> used by this operation.</param>
        /// <param name="request">The request to send.</param>
        /// <param name="cancellationToken">A cancelation token. Unused.</param>
        /// <returns>A task representing the status of the operation.</returns>
        public async Task SendRequestAsync(Guid id, StreamingRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var disassembler = new RequestDisassembler(_payloadSender, id, request);

            await disassembler.DisassembleAsync(cancellationToken).ConfigureAwait(false);

            if (request.Streams != null)
            {
                var tasks = new List <Task>(request.Streams.Count);
                foreach (var contentStream in request.Streams)
                {
                    var contentDisassembler = new ResponseMessageStreamDisassembler(_payloadSender, contentStream);

                    tasks.Add(contentDisassembler.DisassembleAsync(cancellationToken));
                }

                await Task.WhenAll(tasks).ConfigureAwait(false);
            }
        }