Beispiel #1
0
        public Task <long> ReadSegments(
            IObserver <RecordSegment> observer,
            Stream stream,
            CancellationToken cancellationToken)
        {
            return(Task.Factory.StartNew(() => {
                var scanner = (IScanner)Activator.CreateInstance(this.SegmentsScannerType);
                var initialOffset = stream.Position;
                var lastOffset = initialOffset;

                scanner.OffsetCallback = (offset, length) => {
                    if (length > 0 && offset >= 0)
                    {
                        var segment = new RecordSegment(initialOffset + offset, length);
                        lastOffset = initialOffset + offset + length;
                        observer.OnNext(segment);
                    }
                };

                scanner.Diagnostics = this.Diagnostics ?? TextWriter.Null;

                scanner.SetSourceWithEncoding(
                    new InternalStreamWrapper(stream, stream.Position),
                    Encoding.UTF8.CodePage);

                scanner.Parse(cancellationToken);

                return lastOffset;
            }, cancellationToken,
                                         TaskCreationOptions.LongRunning,
                                         this.TaskScheduler));
        }
Beispiel #2
0
        public Task<long> ReadSegments(
            IObserver<RecordSegment> observer,
            Stream stream,
            CancellationToken cancellationToken)
        {
            return Task.Factory.StartNew(() => {
                var scanner = (IScanner) Activator.CreateInstance(this.SegmentsScannerType);
                var initialOffset = stream.Position;
                var lastOffset = initialOffset;

                scanner.OffsetCallback = (offset, length) => {
                    if (length > 0 && offset >= 0) {
                        var segment = new RecordSegment(initialOffset + offset, length);
                        lastOffset = initialOffset + offset + length;
                        observer.OnNext(segment);
                    }
                };

                scanner.Diagnostics = this.Diagnostics ?? TextWriter.Null;

                scanner.SetSourceWithEncoding(
                    new InternalStreamWrapper(stream, stream.Position),
                    Encoding.UTF8.CodePage);

                scanner.Parse(cancellationToken);

                return lastOffset;
            }, cancellationToken,
                TaskCreationOptions.LongRunning,
                this.TaskScheduler);
        }