Example #1
0
        public ProcessingBlock <TData> Create <TData>(CancellationToken cancellation)
        {
            // Create blocks
            var emptyBlock = DataflowFacade.BufferBlock <TData>(cancellation, 1);

            return(new ProcessingBlock <TData>(emptyBlock));
        }
Example #2
0
        public StartableBlock <Data> Create(string peopleJsonFilePath, DataPool dataPool, CancellationToken cancellation)
        {
            var batchSize    = Settings.ReadingBatchSize;
            var peopleCount  = _fileLinesCounter.Count(peopleJsonFilePath);
            var batchesCount = peopleCount.CeilingOfDivisionBy(batchSize);

            var peopleJsonStream = File.OpenText(peopleJsonFilePath);

            // Create blocks
            var bufferBlock = DataflowFacade.BufferBlock <int>(cancellation);
            var readBlock   = Settings.SplitReadingIntoTwoSteps
                                ? UseLinesReaderAndParser(peopleJsonStream, dataPool, cancellation)
                                : UseDataReader(peopleJsonStream, dataPool, cancellation);

            //  Link blocks
            bufferBlock.LinkWithCompletion(readBlock);

            // Handle completion
            var completion = readBlock.Completion.ContinueWithStatusPropagation(_ => peopleJsonStream.Dispose());

            return(new StartableBlock <Data>(
                       () =>
            {
                for (var i = 0; i < batchesCount; i++)
                {
                    bufferBlock.Post(batchSize);
                }

                bufferBlock.Complete();
            },
                       readBlock,
                       peopleCount,
                       completion));
        }
Example #3
0
        public ProcessingBlock <TData> Create <TData>(CancellationToken cancellation)
        {
            // Create blocks
            var emptyBlock = DataflowFacade.BufferBlock <TData>(cancellation, 1);

            return(new ProcessingBlock <TData>
            {
                Processor = emptyBlock,
                Completion = emptyBlock.Completion
            });
        }
Example #4
0
        public StartableBlock <TOutput> Create <TOutput>(Func <TOutput> itemGetter, CancellationToken cancellation)
        {
            var sourceBuffer = DataflowFacade.BufferBlock <TOutput>(cancellation);

            return(new StartableBlock <TOutput>(() =>
            {
                var item = itemGetter();
                sourceBuffer.Post(item);
                sourceBuffer.Complete();
            },
                                                sourceBuffer,
                                                1));
        }
Example #5
0
        public StartableBlock <DataBatch <Person> > Create(CancellationToken cancellation)
        {
            var batchSize    = Settings.ReadingBatchSize;
            var batchesCount = new Lazy <int>(() => GetBatchesCount(batchSize));

            // Create blocks
            var bufferBlock = DataflowFacade.BufferBlock <DataBatch <Person> >(cancellation);

            var readBlock = DataflowFacade.TransformBlock <DataBatch <Person> >("ReadPerson",
                                                                                DataBatch <Person> .IdGetter,
                                                                                x => x.Data = _peopleBatchReader.Read(x.DataOffset, x.IntendedSize),
                                                                                cancellation);

            // Link blocks
            bufferBlock.LinkWithCompletion(readBlock);

            return(new StartableBlock <DataBatch <Person> >(
                       () => Start(batchSize, batchesCount.Value, bufferBlock),
                       readBlock,
                       batchesCount));
        }