Пример #1
0
        public Pipeline()
        {
            _start  = StartBlock <string>();
            _path1a = TransformBlock <string, string>(async(job, data) =>
            {
                Console.WriteLine("1a: " + data);
                await Task.Delay(100);

                return(data);
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 4
            });

            _path1b = TransformBlock <string, string>(async(job, data) =>
            {
                Console.WriteLine("1b: " + data);
                await Task.Delay(100);

                return(data);
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 4
            });

            _path1c = TransformBlock <string, string>(async(job, data) =>
            {
                Console.WriteLine("1c: " + data);
                await Task.Delay(100);

                return(data);
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 4
            });

            _path1d = TransformBlock <string, string>(async(job, data) =>
            {
                Console.WriteLine("1d: " + data);
                await Task.Delay(100);

                return(data);
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 4
            });

            _path2a = TransformBlock <string, string>(async(job, data) =>
            {
                Console.WriteLine("2a: " + data);
                await Task.Delay(100);

                return(data);
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 4
            });
            _path2b = TransformBlock <string, string>(async(job, data) =>
            {
                Console.WriteLine("2b: " + data);
                await Task.Delay(100);

                return(data);
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 4
            });

            _merge = TransformBlock <Tuple <string, string>, string>(async(job, data) =>
            {
                Console.WriteLine("m: " + data);
                await Task.Delay(100);

                return(data.Item1 + data.Item2);
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 4
            });

            _finish = ActionBlock <string>(async(job, data) =>
            {
                Console.WriteLine("f: " + data);
                await Task.Delay(100);
            }, true, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 4
            });

            _start.LinkTo(_path1a, e => e.Properties.ContainsKey("Even"));
            _start.LinkTo(_path2a, e => e.Properties.ContainsKey("Odd"));

            _path1a.LinkTo(_path1b);
            _path1b.LinkTo(_path1c);
            _path1c.LinkTo(_path1d);

            _path2a.LinkTo(_path2b);

            _merge.LinkFrom(_path1d, _path2b);
            _merge.LinkTo(_finish);
        }