Beispiel #1
0
        private void ImportContracts(IEnumerable <Club> clubs, CloudTable eventsTable)
        {
            var contractsTable = TableClient.GetTableReference("contracts");

            var tasks = new List <Task>();

            foreach (var club in clubs)
            {
                tasks.Add(Task.Run(() => {
                    var query = new TableQuery <Contract>()
                                .Where(TableQuery.GenerateFilterCondition("PartitionKey",
                                                                          QueryComparisons.Equal, club.Id.ToString()));

                    var contracts = query.BatchQuery(contractsTable).Result;
                    int version   = 1;

                    foreach (var contractPartition in contracts.Partition(maximumBatchSize))
                    {
                        var insert = new TableBatchOperation();

                        foreach (var contract in contractPartition)
                        {
                            var contractEvent = new ContractImportedEvent
                            {
                                PlayerId  = contract.PlayerId,
                                FromRound = contract.FromRound,
                                ToRound   = contract.ToRound,
                                DraftPick = contract.DraftPick
                            };

                            var insertEvent = new Event(club.Id, version++, "ContractImported", JsonConvert.SerializeObject(contractEvent));
                            insert.Add(TableOperation.Insert(insertEvent));
                        }

                        try
                        {
                            eventsTable.ExecuteBatchAsync(insert).Wait();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                            throw;
                        }
                    }
                }));
            }

            Task.WaitAll(tasks.ToArray());
        }
Beispiel #2
0
        public void Run()
        {
            var clubsTable  = TableClient.GetTableReference("clubs");
            var eventsTable = TableClient.GetTableReference("clubEvents");

            clubsTable.CreateIfNotExistsAsync().Wait();
            eventsTable.CreateIfNotExistsAsync().Wait();

            var query = new TableQuery <Club>();

            var clubs = query.BatchQuery(clubsTable).Result;

            ImportClubs(clubs, eventsTable);

            ImportContracts(clubs, eventsTable);
        }