Exemplo n.º 1
0
        private async Task <HttpResponseMessage> AddResponseProgressAsync(HttpRequestMessage request, HttpResponseMessage response)
        {
            Stream stream = await response.Content.ReadAsStreamAsync();

            ProgressStream progressStream  = new ProgressStream(stream, this, request, response);
            HttpContent    progressContent = new StreamContent(progressStream);

            //response.Content.Headers.CopyTo(progressContent.Headers);
            response.Content = progressContent;
            return(response);
        }
Exemplo n.º 2
0
        public ProgressWriteAsyncResult(Stream innerStream, ProgressStream progressStream, byte[] buffer, int offset, int count, AsyncCallback callback, object state)
            : base(callback, state)
        {
            Contract.Assert(innerStream != null);
            Contract.Assert(progressStream != null);
            Contract.Assert(buffer != null);

            _innerStream    = innerStream;
            _progressStream = progressStream;
            _count          = count;

            try
            {
                IAsyncResult result = innerStream.BeginWrite(buffer, offset, count, _writeCompletedCallback, this);
                if (result.CompletedSynchronously)
                {
                    WriteCompleted(result);
                }
            }
            catch (Exception e)
            {
                Complete(true, e);
            }
        }
Exemplo n.º 3
0
        protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            ProgressStream progressStream = new ProgressStream(stream, _handler, _request, response: null);

            return(_innerContent.CopyToAsync(progressStream));
        }