예제 #1
0
        public Task CopyToAsync(Stream stream)
        {
            var result = new QueueStream(stream, _logger)
            {
                OnFinished = OnFinished
            };

            var initial = _sharedBuffer.ToList();
            var list    = new List <byte>();

            foreach (var bytes in initial)
            {
                list.AddRange(bytes);
            }

            _logger.Info("QueueStream started with {0} initial bytes", list.Count);

            result.Queue(list.ToArray());

            _outputStreams.TryAdd(result.Id, result);

            result.Start(_cancellationToken);

            return(result.TaskCompletion.Task);
        }
예제 #2
0
 public void RemoveOutputStream(QueueStream stream)
 {
     lock (_outputStreams)
     {
         _outputStreams.Remove(stream);
     }
 }
예제 #3
0
        public Task CopyToAsync(Stream stream)
        {
            var result = new QueueStream(stream, _logger)
            {
                OnFinished = OnFinished
            };

            _outputStreams.TryAdd(result.Id, result);

            result.Start(_cancellationToken);

            return(result.TaskCompletion.Task);
        }
예제 #4
0
        public Task CopyToAsync(Stream stream, CancellationToken cancellationToken)
        {
            var queueStream = new QueueStream(stream, _logger);

            _outputStreams.TryAdd(queueStream.Id, queueStream);

            try
            {
                queueStream.Start(cancellationToken);
            }
            finally
            {
                _outputStreams.TryRemove(queueStream.Id, out queueStream);
                GC.Collect();
            }

            return(Task.FromResult(true));
        }
예제 #5
0
 private void OnFinished(QueueStream queueStream)
 {
     RemoveOutputStream(queueStream);
 }
예제 #6
0
        public void RemoveOutputStream(QueueStream stream)
        {
            QueueStream removed;

            _outputStreams.TryRemove(stream.Id, out removed);
        }