コード例 #1
0
        static void Main(string[] args)
        {
            string s =
                "http://cn.bing.com/search?q=MD5CryptoServiceProvider+slow&qs=n&pq=md5cryptoserviceprovider+slow&sc=0-25&sp=-1&sk=&cvid=67d40cbd8c424d55a3db83e6e9868267&first=51&FORM=PERE4";

            using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())
            {
                byte[] inBytes = Encoding.UTF8.GetBytes(s);
                var    bytes   = md5.ComputeHash(inBytes);
                Console.WriteLine(bytes.Length);
            }


            var splitter = new TransformBlock <string, KeyValuePair <string, int> >(
                input =>
            {
                var splitted = input.Split('=');
                return(new KeyValuePair <string, int>(splitted[0], int.Parse(splitted[1])));
            });

            var dict       = new Dictionary <string, int>();
            var aggregater = new ActionBlock <KeyValuePair <string, int> >(
                pair =>
            {
                int oldValue;
                dict[pair.Key] = dict.TryGetValue(pair.Key, out oldValue) ? oldValue + pair.Value : pair.Value;
            });

            splitter.LinkTo(aggregater, new DataflowLinkOptions()
            {
                PropagateCompletion = true
            });

            splitter.Post("a=1");
            splitter.Post("b=2");
            splitter.Post("a=5");

            splitter.Complete();
            aggregater.Completion.Wait();
            Console.WriteLine("sum(a) = {0}", dict["a"]); //prints sum(a) = 6

            string containerName = "dataflowex-demo-" + Guid.NewGuid();

            TestBootstrapper.BootSqlServerWithDockerCli(null, containerName);
            //CalcAsync().Wait();
            //SlowFlowAsync().Wait();
            //FailDemoAsync().Wait();
            //TransformAndLinkDemo().Wait();
            //LinkLeftToDemo().Wait();
            //CircularFlowAutoComplete().Wait();
            //RecorderDemo().Wait();
            BulkInserterDemo().Wait();
            //BulkInserterDemo2().Wait();
            //BroadcasterDemo().Wait();
            //MyLoggerDemo().Wait();
            //ETLLookupDemo().Wait();

            TestBootstrapper.ShutdownSqlServerWithDockerCli(false, containerName); // leave the container so that we can check result manually through ssms.
        }