Пример #1
0
        public IPipelineWriter CreateWriter(Stream stream)
        {
            if (!stream.CanWrite)
            {
                ThrowHelper.ThrowNotSupportedException();
            }

            var input = new PipelineReaderWriter(_pool);

            input.CopyToAsync(stream).ContinueWith((task, state) =>
            {
                var innerInput = (PipelineReaderWriter)state;
                if (task.IsFaulted)
                {
                    innerInput.CompleteReader(task.Exception.InnerException);
                }
                else
                {
                    innerInput.CompleteReader();
                }
            },
                                                   input, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);

            return(input);
        }
Пример #2
0
        public IPipelineReader CreateReader(IPipelineReader reader, Func <IPipelineReader, IPipelineWriter, Task> produce)
        {
            var newReader = new PipelineReaderWriter(_pool);

            Execute(reader, newReader, produce);
            return(newReader);
        }
Пример #3
0
        public IPipelineWriter CreateWriter(Stream stream)
        {
            if (!stream.CanWrite)
            {
                ThrowHelper.ThrowNotSupportedException();
            }

            var input = new PipelineReaderWriter(_pool);

            input.CopyToAsync(stream).ContinueWith((task, state) =>
            {
                var innerInput = (PipelineReaderWriter)state;
                if (task.IsFaulted)
                {
                    innerInput.CompleteReader(task.Exception.InnerException);
                }
                else
                {
                    innerInput.CompleteReader();
                }
            },
            input, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);

            return input;
        }
Пример #4
0
        public IPipelineWriter CreateWriter(IPipelineWriter writer, Func <IPipelineReader, IPipelineWriter, Task> consume)
        {
            var newWriter = new PipelineReaderWriter(_pool);

            consume(newWriter, writer).ContinueWith(t =>
            {
            });

            return(newWriter);
        }
Пример #5
0
        public IPipelineWriter CreateWriter(IPipelineWriter writer, Func<IPipelineReader, IPipelineWriter, Task> consume)
        {
            var newWriter = new PipelineReaderWriter(_pool);

            consume(newWriter, writer).ContinueWith(t =>
            {
            });

            return newWriter;
        }
Пример #6
0
        public IPipelineReader CreateReader(Stream stream)
        {
            if (!stream.CanRead)
            {
                ThrowHelper.ThrowNotSupportedException();
            }

            var output = new PipelineReaderWriter(_pool);
            ExecuteCopyToAsync(output, stream);
            return output;
        }
Пример #7
0
        public IPipelineReader CreateReader(Stream stream)
        {
            if (!stream.CanRead)
            {
                ThrowHelper.ThrowNotSupportedException();
            }

            var output = new PipelineReaderWriter(_pool);

            ExecuteCopyToAsync(output, stream);
            return(output);
        }
Пример #8
0
        /// <summary>
        /// Adapts a <see cref="Stream"/> into a <see cref="IPipelineWriter"/>.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="pool"></param>
        /// <returns></returns>
        public static IPipelineWriter AsPipelineWriter(this Stream stream, IBufferPool pool)
        {
            var writer = new PipelineReaderWriter(pool);
            writer.CopyToAsync(stream).ContinueWith((task, state) =>
            {
                var innerWriter = (PipelineReaderWriter)state;

                if (task.IsFaulted)
                {
                    innerWriter.CompleteReader(task.Exception.InnerException);
                }
                else
                {
                    innerWriter.CompleteReader();
                }
            }, 
            writer, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);

            return writer;
        }
Пример #9
0
        /// <summary>
        /// Adapts a <see cref="Stream"/> into a <see cref="IPipelineWriter"/>.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="pool"></param>
        /// <returns></returns>
        public static IPipelineWriter AsPipelineWriter(this Stream stream, IBufferPool pool)
        {
            var writer = new PipelineReaderWriter(pool);

            writer.CopyToAsync(stream).ContinueWith((task, state) =>
            {
                var innerWriter = (PipelineReaderWriter)state;

                if (task.IsFaulted)
                {
                    innerWriter.CompleteReader(task.Exception.InnerException);
                }
                else
                {
                    innerWriter.CompleteReader();
                }
            },
                                                    writer, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);

            return(writer);
        }
Пример #10
0
        private async void ExecuteCopyToAsync(PipelineReaderWriter output, Stream stream)
        {
            await output.ReadingStarted;

            await stream.CopyToAsync(output);
        }
Пример #11
0
 internal WritableBuffer(PipelineReaderWriter output)
 {
     _output = output;
 }
Пример #12
0
        private async void Execute(IPipelineReader reader, PipelineReaderWriter writer, Func <IPipelineReader, IPipelineWriter, Task> produce)
        {
            await writer.ReadingStarted;

            await produce(reader, writer);
        }
Пример #13
0
 public IPipelineReader CreateReader(IPipelineReader reader, Func<IPipelineReader, IPipelineWriter, Task> produce)
 {
     var newReader = new PipelineReaderWriter(_pool);
     Execute(reader, newReader, produce);
     return newReader;
 }
Пример #14
0
 /// <summary>
 /// Creates a base <see cref="PipelineReader"/>.
 /// </summary>
 /// <param name="pool">The <see cref="IBufferPool"/> that buffers will be allocated from.</param>
 protected PipelineReader(IBufferPool pool)
 {
     _input = new PipelineReaderWriter(pool);
 }
Пример #15
0
        public PipelineWriter(IBufferPool pool)
        {
            _output = new PipelineReaderWriter(pool);

            Consume(_output);
        }
Пример #16
0
        private async void ExecuteCopyToAsync(PipelineReaderWriter output, Stream stream)
        {
            await output.ReadingStarted;

            await stream.CopyToAsync(output);
        }
Пример #17
0
 /// <summary>
 /// Creates a base <see cref="PipelineReader"/>.
 /// </summary>
 /// <param name="input">The <see cref="PipelineReaderWriter"/> the <see cref="PipelineReader"/> communicates over.</param>
 protected PipelineReader(PipelineReaderWriter input)
 {
     _input = input;
 }
Пример #18
0
        public PipelineWriter(IBufferPool pool)
        {
            _output = new PipelineReaderWriter(pool);

            Consume(_output);
        }
Пример #19
0
        private async void Execute(IPipelineReader reader, PipelineReaderWriter writer, Func<IPipelineReader, IPipelineWriter, Task> produce)
        {
            await writer.ReadingStarted;

            await produce(reader, writer);
        }
Пример #20
0
 internal WritableBuffer(PipelineReaderWriter output)
 {
     _output = output;
 }