コード例 #1
0
        private static async Task CreateWordNumTHing(int limit, ILogger logger)
        {
            var currentDate   = DateTime.Today;
            var wordNumbTHing = new List <NumbersAndWords>();

            for (var x = 0; x < limit; ++x)
            {
                var cryptoData = new byte[sizeof(int)];
                rngCsp.GetBytes(cryptoData);

                var number     = BitConverter.ToInt32(cryptoData, 0) & (int.MaxValue - 1);
                var numberWord = NumToWor.NumbersToWords(number);
                wordNumbTHing.Add(new NumbersAndWords(number, numberWord)
                {
                    Published = currentDate
                });
                currentDate = currentDate.AddDays(1);
            }

            var ctx      = new CloudStorageContext("UseDevelopmentStorage=true");
            var numWords = await ctx.CreateTableHelper("xpclNumWords", logger);

            var tasks = new List <Task>();

            wordNumbTHing.ForEach(a => tasks.Add(numWords.Insert(a)));
            var task1 = tasks.Skip(0).Take(1000).ToList();
            var task2 = tasks.Skip(1000).Take(1000);
            var task3 = tasks.Skip(2000).Take(1000);
            var task4 = tasks.Skip(3000).Take(1000);
            var task5 = tasks.Skip(4000).Take(1000);


            Task.WaitAll(task1.ToArray());
            Task.WaitAll(task2.ToArray());
            Task.WaitAll(task3.ToArray());
            Task.WaitAll(task4.ToArray());
            Task.WaitAll(task5.ToArray());

            Console.WriteLine($"Did it");
        }
コード例 #2
0
        private static async Task BulkCreateWordNumThing(int limit, ILogger logger)
        {
            var currentDate   = DateTime.Today;
            var WordNumThings = new List <NumbersAndWords>();

            for (var x = 0; x < limit; ++x)
            {
                var cryptoData = new byte[sizeof(int)];
                rngCsp.GetBytes(cryptoData);

                var number     = BitConverter.ToInt32(cryptoData, 0) & (int.MaxValue - 1);
                var numberWord = NumToWor.NumbersToWords(number);
                WordNumThings.Add(new NumbersAndWords(number, numberWord)
                {
                    Published = currentDate
                });
                currentDate = currentDate.AddDays(1);
            }

            var ctx      = new CloudStorageContext("UseDevelopmentStorage=true");
            var numWords = await ctx.CreateTableHelper("xpclNumWords", logger);

            await numWords.Insert(WordNumThings);
        }