Esempio n. 1
0
        public PipeLine(
            DataflowOptions dataflowOptions,
            int maxDegreeOfParallelism,
            HttpClient client)
            : base(dataflowOptions)
        {
            _client          = client;
            _dataflowOptions = dataflowOptions;
            _options         = dataflowOptions.ToExecutionBlockOption(true);
            _options.MaxDegreeOfParallelism    = maxDegreeOfParallelism;
            _options.BoundedCapacity           = 10000;
            _options.MaxMessagesPerTask        = 100;
            _options.SingleProducerConstrained = true;

            _requestBlock = new TransformBlock <string, HttpResponseMessage>(x =>
            {
                Interlocked.Increment(ref _totalOut);

                Console.WriteLine("lines " + _totalOut);

                var response = _client.GetAsync("http://localhost:3000/endpoint/info").Result;

                return(default(HttpResponseMessage));
            }, _options);

            _flowBlock = new ActionBlock <HttpResponseMessage>(x =>
            {
            }, _options);

            _request = _requestBlock.ToDataflow(_dataflowOptions, "Request");
            _flow    = _flowBlock.ToDataflow(_dataflowOptions, "Flow");

            _request.LinkTo(_flow);
        }
Esempio n. 2
0
            protected override Dataflow <ICommand, ICommand> CreateChildFlow(string target)
            {
                var block = new TransformBlock <ICommand, ICommand>(
                    async c =>
                {
                    await _handler(c);
                    return(c);
                }, _options.ToDataflowBlockOptions());

                return(block.ToDataflow(_options));
            }
        public CompletionDemo1()
        {
            broadCaster = new BroadcastBlock<int>(
                i =>
                    {
                        return i;
                    }).ToDataflow();

            transformBlock1 = new TransformBlock<int, string>(
                i =>
                    {
                        Console.WriteLine("1 input count: " + transformBlock1.InputCount);
                        Thread.Sleep(50);
                        return ("1_" + i);
                    });

            transformBlock2 = new TransformBlock<int, string>(
                i =>
                    {
                        Console.WriteLine("2 input count: " + transformBlock2.InputCount);
                        Thread.Sleep(20);
                        return ("2_" + i);
                    });

            processor = new ActionBlock<string>(
                i =>
                    {
                        Console.WriteLine(i);
                    }).ToDataflow();

            /** rather than TPL linking
              broadCastBlock.LinkTo(transformBlock1, new DataflowLinkOptions { PropagateCompletion = true });
              broadCastBlock.LinkTo(transformBlock2, new DataflowLinkOptions { PropagateCompletion = true });
              transformBlock1.LinkTo(processorBlock, new DataflowLinkOptions { PropagateCompletion = true });
              transformBlock2.LinkTo(processorBlock, new DataflowLinkOptions { PropagateCompletion = true });
             **/

            //Use DataflowEx linking
            var transform1 = transformBlock1.ToDataflow();
            var transform2 = transformBlock2.ToDataflow();

            broadCaster.LinkTo(transform1);
            broadCaster.LinkTo(transform2);
            transform1.LinkTo(processor);
            transform2.LinkTo(processor);
        }
Esempio n. 4
0
        public CompletionDemo1()
        {
            broadCaster = new BroadcastBlock <int>(
                i =>
            {
                return(i);
            }).ToDataflow();

            transformBlock1 = new TransformBlock <int, string>(
                i =>
            {
                Console.WriteLine("1 input count: " + transformBlock1.InputCount);
                Thread.Sleep(50);
                return("1_" + i);
            });

            transformBlock2 = new TransformBlock <int, string>(
                i =>
            {
                Console.WriteLine("2 input count: " + transformBlock2.InputCount);
                Thread.Sleep(20);
                return("2_" + i);
            });

            processor = new ActionBlock <string>(
                i =>
            {
                Console.WriteLine(i);
            }).ToDataflow();

            /** rather than TPL linking
             * broadCastBlock.LinkTo(transformBlock1, new DataflowLinkOptions { PropagateCompletion = true });
             * broadCastBlock.LinkTo(transformBlock2, new DataflowLinkOptions { PropagateCompletion = true });
             * transformBlock1.LinkTo(processorBlock, new DataflowLinkOptions { PropagateCompletion = true });
             * transformBlock2.LinkTo(processorBlock, new DataflowLinkOptions { PropagateCompletion = true });
             **/

            //Use DataflowEx linking
            var transform1 = transformBlock1.ToDataflow();
            var transform2 = transformBlock2.ToDataflow();

            broadCaster.LinkTo(transform1);
            broadCaster.LinkTo(transform2);
            transform1.LinkTo(processor);
            transform2.LinkTo(processor);
        }