Beispiel #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);
        }
        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);

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

            try
            {
                IAsyncResult result = innerStream.BeginWrite(buffer, offset, count, _writeCompletedCallback, this);
                if (result.CompletedSynchronously)
                {
                    this.WriteCompleted(result);
                }
            }
            catch (Exception e)
            {
                this.Complete(true, e);
            }
        }
        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);

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

            try
            {
                IAsyncResult result = innerStream.BeginWrite(buffer, offset, count, _writeCompletedCallback, this);
                if (result.CompletedSynchronously)
                {
                    this.WriteCompleted(result);
                }
            }
            catch (Exception e)
            {
                this.Complete(true, e);
            }
        }
 protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
 {
     ProgressStream progressStream = new ProgressStream(stream, this._handler, this._request, response: null);
     return this._innerContent.CopyToAsync(progressStream);
 }
 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;
 }
Beispiel #6
0
        protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            ProgressStream progressStream = new ProgressStream(stream, this._handler, this._request, response: null);

            return(this._innerContent.CopyToAsync(progressStream));
        }