protected override void SerializeToStream(Stream stream, TransportContext context, CancellationToken _)
        {
            var serializeToStreamTask = new TaskCompletionSource <bool>();

            using var wrappedStream = new CompleteTaskOnCloseStream(stream, serializeToStreamTask);
            _onStreamAvailable(_requestData, wrappedStream, this, context);
            //await serializeToStreamTask.Task.ConfigureAwait(false);
        }
        protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            var serializeToStreamTask = new TaskCompletionSource <bool>();
            var wrappedStream         = new CompleteTaskOnCloseStream(stream, serializeToStreamTask);

            await _onStreamAvailable(_requestData, wrappedStream, this, context).ConfigureAwait(false);

            await serializeToStreamTask.Task.ConfigureAwait(false);
        }
        async Task SerializeToStreamAsync(Stream stream, TransportContext context, CancellationToken cancellationToken)
        {
            var source = CancellationTokenSource.CreateLinkedTokenSource(_token, cancellationToken);
            var serializeToStreamTask = new TaskCompletionSource <bool>();
            var wrappedStream         = new CompleteTaskOnCloseStream(stream, serializeToStreamTask);

            await _onStreamAvailableAsync(_requestData, wrappedStream, this, context, source.Token).ConfigureAwait(false);

            await serializeToStreamTask.Task.ConfigureAwait(false);
        }
        /// <summary>
        /// When this method is called, it calls the action provided in the constructor with the output
        /// stream to write to. Once the action has completed its work it closes the stream which will
        /// close this content instance and complete the HTTP request or response.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> to which to write.</param>
        /// <param name="context">The associated <see cref="TransportContext"/>.</param>
        /// <returns>A <see cref="Task"/> instance that is asynchronously serializing the object's content.</returns>
        protected override async Task SerializeToStreamAsync(Stream stream, System.Net.TransportContext context)
        {
            TaskCompletionSource <bool> serializeToStreamTask = new TaskCompletionSource <bool>();

            Stream wrappedStream = new CompleteTaskOnCloseStream(stream, serializeToStreamTask);

            await _onStreamAvailable(wrappedStream, this, context);

            // wait for wrappedStream.Close/Dispose to get called.
            await serializeToStreamTask.Task;
        }
        protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            TaskCompletionSource<bool> serializeToStreamTask = new TaskCompletionSource<bool>();
            try
            {
                Stream wrappedStream = new CompleteTaskOnCloseStream(stream, serializeToStreamTask);
                _onStreamAvailable(wrappedStream, this, context);
            }
            catch (Exception e)
            {
                serializeToStreamTask.TrySetException(e);
            }

            return serializeToStreamTask.Task;
        }
Exemple #6
0
        protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            var serializeToStreamTask = new TaskCompletionSource <bool>();

            Stream wrappedStream = new CompleteTaskOnCloseStream(stream, serializeToStreamTask);

            // We had to create this wrapped stream due to the way the http client is implemented on the .net framework.
            using (TextWriter writer = new StreamWriter(wrappedStream))
            {
                await this.mediaTypeFormatter.WriteAsync(content, writer);
            }

            // Wait for wrappedStream.Close/Dispose to get called.
            await serializeToStreamTask.Task;
        }
Exemple #7
0
        protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            TaskCompletionSource <bool> serializeToStreamTask = new TaskCompletionSource <bool>();

            try
            {
                Stream wrappedStream = new CompleteTaskOnCloseStream(stream, serializeToStreamTask);
                _onStreamAvailable(wrappedStream, this, context);
            }
            catch (Exception e)
            {
                serializeToStreamTask.TrySetException(e);
            }

            return(serializeToStreamTask.Task);
        }
        protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            var data = _requestData.PostData;

            if (data == null)
            {
                return;
            }

            var serializeToStreamTask = new TaskCompletionSource <bool>();

            if (_requestData.HttpCompression)
            {
                stream = new GZipStream(stream, CompressionMode.Compress, false);
            }
            var wrappedStream = new CompleteTaskOnCloseStream(stream, serializeToStreamTask);

            await _onStreamAvailable(data, wrappedStream, this, context).ConfigureAwait(false);

            await serializeToStreamTask.Task.ConfigureAwait(false);
        }
        protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            TaskCompletionSource<bool> serializeToStreamTask = new TaskCompletionSource<bool>();

            Stream wrappedStream = new CompleteTaskOnCloseStream(stream, serializeToStreamTask);
            await _onStreamAvailable(wrappedStream, this, context);

            // wait for wrappedStream.Close/Dispose to get called.
            await serializeToStreamTask.Task;
        }