コード例 #1
0
        public JoinBlock(GroupingDataflowBlockOptions dataflowBlockOptions)
        {
            if (dataflowBlockOptions == null)
            {
                throw new ArgumentNullException("dataflowBlockOptions");
            }

            this.dataflowBlockOptions = dataflowBlockOptions;
            this.compHelper           = new CompletionHelper(dataflowBlockOptions);

            target1 = new JoinTarget <T1> (this, SignalArrivalTarget, compHelper,
                                           () => outgoing.IsCompleted, dataflowBlockOptions,
                                           dataflowBlockOptions.Greedy, TryAdd1);
            target2 = new JoinTarget <T2> (this, SignalArrivalTarget, compHelper,
                                           () => outgoing.IsCompleted, dataflowBlockOptions,
                                           dataflowBlockOptions.Greedy, TryAdd2);
            target3 = new JoinTarget <T3> (this, SignalArrivalTarget, compHelper,
                                           () => outgoing.IsCompleted, dataflowBlockOptions,
                                           dataflowBlockOptions.Greedy, TryAdd3);
            outgoing = new OutgoingQueue <Tuple <T1, T2, T3> > (
                this, compHelper,
                () => target1.Buffer.IsCompleted || target2.Buffer.IsCompleted ||
                target3.Buffer.IsCompleted,
                _ =>
            {
                target1.DecreaseCount();
                target2.DecreaseCount();
                target3.DecreaseCount();
            }, dataflowBlockOptions);
        }
コード例 #2
0
        public BatchedJoinBlock(int batchSize,
                                GroupingDataflowBlockOptions dataflowBlockOptions)
        {
            if (batchSize <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          "batchSize", batchSize, "The batchSize must be positive.");
            }
            if (dataflowBlockOptions == null)
            {
                throw new ArgumentNullException("dataflowBlockOptions");
            }
            if (!dataflowBlockOptions.Greedy)
            {
                throw new ArgumentException(
                          "Greedy must be true for this dataflow block.", "dataflowBlockOptions");
            }
            if (dataflowBlockOptions.BoundedCapacity != DataflowBlockOptions.Unbounded)
            {
                throw new ArgumentException(
                          "BoundedCapacity must be Unbounded or -1 for this dataflow block.",
                          "dataflowBlockOptions");
            }

            BatchSize        = batchSize;
            options          = dataflowBlockOptions;
            completionHelper = CompletionHelper.GetNew(options);

            target1 = new JoinTarget <T1> (
                this, SignalTarget, completionHelper, () => outgoing.IsCompleted,
                dataflowBlockOptions, true, TryAdd);
            target2 = new JoinTarget <T2> (
                this, SignalTarget, completionHelper, () => outgoing.IsCompleted,
                dataflowBlockOptions, true, TryAdd);
            target3 = new JoinTarget <T3> (
                this, SignalTarget, completionHelper, () => outgoing.IsCompleted,
                dataflowBlockOptions, true, TryAdd);

            outgoing = new OutgoingQueue <Tuple <IList <T1>, IList <T2>, IList <T3> > > (
                this, completionHelper,
                () => target1.Buffer.IsCompleted || target2.Buffer.IsCompleted ||
                target3.Buffer.IsCompleted,
                _ =>
            {
                target1.DecreaseCount();
                target2.DecreaseCount();
                target3.DecreaseCount();
            }, options);
        }
コード例 #3
0
        public BufferBlock(DataflowBlockOptions dataflowBlockOptions)
        {
            if (dataflowBlockOptions == null)
            {
                throw new ArgumentNullException("dataflowBlockOptions");
            }

            this.dataflowBlockOptions = dataflowBlockOptions;
            this.compHelper           = new CompletionHelper(dataflowBlockOptions);
            this.messageBox           = new PassingMessageBox <T> (this, messageQueue, compHelper,
                                                                   () => outgoing.IsCompleted, _ => ProcessQueue(), dataflowBlockOptions);
            this.outgoing = new OutgoingQueue <T> (this, compHelper,
                                                   () => messageQueue.IsCompleted, messageBox.DecreaseCount,
                                                   dataflowBlockOptions);
        }
コード例 #4
0
        public TransformManyBlock(Func <TInput, Task <IEnumerable <TOutput> > > transform,
                                  ExecutionDataflowBlockOptions dataflowBlockOptions)
            : this(dataflowBlockOptions)
        {
            if (transform == null)
            {
                throw new ArgumentNullException("transform");
            }

            this.asyncTransform = transform;
            this.messageBox     = new AsyncExecutingMessageBox <TInput, Task <IEnumerable <TOutput> > > (this, messageQueue, compHelper,
                                                                                                         () => outgoing.IsCompleted, AsyncTransformProcess, ProcessFinishedTask, () => outgoing.Complete(),
                                                                                                         dataflowBlockOptions);
            this.outgoing = new OutgoingQueue <TOutput> (this, compHelper,
                                                         () => messageQueue.IsCompleted, messageBox.DecreaseCount,
                                                         dataflowBlockOptions);
        }
コード例 #5
0
        public TransformBlock(Func <TInput, TOutput> transform,
                              ExecutionDataflowBlockOptions dataflowBlockOptions)
            : this(dataflowBlockOptions)
        {
            if (transform == null)
            {
                throw new ArgumentNullException("transform");
            }

            this.transform  = transform;
            this.messageBox = new ExecutingMessageBox <TInput> (
                this, messageQueue, compHelper,
                () => outgoing.IsCompleted, TransformProcess, () => outgoing.Complete(),
                dataflowBlockOptions);
            this.outgoing = new OutgoingQueue <TOutput> (this, compHelper,
                                                         () => messageQueue.IsCompleted, messageBox.DecreaseCount,
                                                         dataflowBlockOptions);
        }
コード例 #6
0
        public BatchBlock(int batchSize, GroupingDataflowBlockOptions dataflowBlockOptions)
        {
            if (batchSize <= 0)
            {
                throw new ArgumentOutOfRangeException("batchSize", batchSize,
                                                      "The batchSize must be positive.");
            }
            if (dataflowBlockOptions == null)
            {
                throw new ArgumentNullException("dataflowBlockOptions");
            }
            if (dataflowBlockOptions.BoundedCapacity != -1 &&
                batchSize > dataflowBlockOptions.BoundedCapacity)
            {
                throw new ArgumentOutOfRangeException("batchSize",
                                                      "The batchSize must be smaller than the value of BoundedCapacity.");
            }

            this.batchSize            = batchSize;
            this.dataflowBlockOptions = dataflowBlockOptions;
            this.compHelper           = CompletionHelper.GetNew(dataflowBlockOptions);

            Action <bool> processQueue;
            Func <bool>   canAccept;

            if (dataflowBlockOptions.MaxNumberOfGroups == -1)
            {
                processQueue = newItem => BatchProcess(newItem ? 1 : 0);
                canAccept    = null;
            }
            else
            {
                processQueue = _ => BatchProcess();
                canAccept    = TryAdd;
            }

            this.messageBox = new PassingMessageBox <T> (this, messageQueue, compHelper,
                                                         () => outgoing.IsCompleted, processQueue, dataflowBlockOptions,
                                                         dataflowBlockOptions.Greedy, canAccept);
            this.outgoing = new OutgoingQueue <T[]> (this, compHelper,
                                                     () => messageQueue.IsCompleted, messageBox.DecreaseCount,
                                                     dataflowBlockOptions, batch => batch.Length);
        }