예제 #1
0
        private static void UseBuilder()
        {
            var pipeline = new TPLPipelineWithAwaitAttempt2 <string, bool>()
                           .AddStep <string, string>(sentence => FindMostCommon(sentence))
                           .AddStep <string, int>(word => word.Length)
                           .AddStep <int, bool>(length => length % 2 == 1)
                           .CreatePipeline();

            System.Threading.Tasks.Task.Run(async() =>
            {
                bool res;
                try
                {
                    res = await pipeline.Execute("The pipeline pattern is the best pattern");
                    Console.WriteLine(res);
                }
                catch (Exception e)
                {
                }

                try
                {
                    res = await pipeline.Execute("The pipeline pattern is the best pattern");
                    Console.WriteLine(res);
                }
                catch (Exception e)
                {
                }

                try
                {
                    res = await pipeline.Execute("abcd");
                    Console.WriteLine(res);
                }
                catch (Exception e)
                {
                }

                try
                {
                    res = await pipeline.Execute("abcd");
                    Console.WriteLine(res);
                }
                catch (Exception e)
                {
                }

                res = await pipeline.Execute("The pipeline pattern is the best pattern");
                Console.WriteLine(res);
                res = await pipeline.Execute("The pipeline pattern is the best pattern");
                Console.WriteLine(res);
                res = await pipeline.Execute("The pipeline pattern is the best pattern");
                Console.WriteLine(res);
            }).Wait();
        }
        private static void UseBuilder()
        {
            var pipeline = new TPLPipelineWithAwaitAttempt2 <string, bool>()
                           .AddStep <string, string>(sentence => Utils.FindMostCommon(sentence))
                           .AddStep <string, int>(word => Utils.CountChars(word))
                           .AddStep <int, bool>(length => Utils.IsOdd(length))
                           .CreatePipeline();

            Task.Run(async() =>
            {
                bool res;
                try
                {
                    res = await pipeline.Execute("The pipeline pattern is the best pattern");
                    Console.WriteLine(res);
                }
                catch (Exception)
                {
                }

                try
                {
                    res = await pipeline.Execute("The pipeline pattern is the best pattern");
                    Console.WriteLine(res);
                }
                catch (Exception)
                {
                }

                try
                {
                    res = await pipeline.Execute("abcd");
                    Console.WriteLine(res);
                }
                catch (Exception)
                {
                }

                try
                {
                    res = await pipeline.Execute("abcd");
                    Console.WriteLine(res);
                }
                catch (Exception)
                {
                }

                res = await pipeline.Execute("The pipeline pattern is the best pattern");
                Console.WriteLine(res);
                res = await pipeline.Execute("The pipeline pattern is the best pattern");
                Console.WriteLine(res);
                res = await pipeline.Execute("The pipeline pattern is the best pattern");
                Console.WriteLine(res);
            }).Wait();
        }