private void ClearCrawler() { // Retrieve storage account from connection string CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the queue and table client CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Retrieve a reference to CrawlingQueue and CrawlingTable CloudQueue crawlingQueue = queueClient.GetQueueReference(WebRole.AZURE_CRAWLING_QUEUE); CloudTable crawlingTable = tableClient.GetTableReference(WebRole.AZURE_CRAWLING_TABLE); // Create the queue and table if it doesn't already exist crawlingQueue.CreateIfNotExists(); crawlingTable.CreateIfNotExists(); crawledUrls.Clear(); crawlingQueue.Clear(); disallowedDirs.Clear(); crawlingTable.Delete(); crawlingTable.CreateIfNotExists(); statsEntity = new StatsEntity(); }
public Stats(StatsEntity stats, List <Player> players) { StatsId = new Guid(stats.RowKey); Name = stats.Name; PlayerStats = new List <Stat>(); int numGames = stats.Wins1 + stats.Wins2 + stats.Wins3; if (stats.PlayerId1 != null) { PlayerStats.Add(new Stat(stats.PlayerId1, stats.Wins1, numGames, players)); } if (stats.PlayerId2 != null) { PlayerStats.Add(new Stat(stats.PlayerId2, stats.Wins2, numGames, players)); } if (stats.PlayerId3 != null) { PlayerStats.Add(new Stat(stats.PlayerId3, stats.Wins3, numGames, players)); } PlayerStats = PlayerStats.OrderBy(p => p.Name).ToList(); }
public async Task AddUpdateStatsAsync(List <string> playerIds, string winnerId) { if (playerIds.Count < 1) { throw new Exception("Must have at least 1 player"); } if (playerIds.Count > 3) { throw new Exception("Cannot have more than 3 players"); } if (!playerIds.Contains(winnerId)) { throw new Exception("One of the players must be the winner"); } // Get all the stats var stats = await GetStatsAsync(); // Find an stat that matches the list of players StatsEntity match = null; foreach (var stat in stats) { if (stat.PlayerId1 != null && !playerIds.Contains(stat.PlayerId1)) { continue; } if (stat.PlayerId2 != null && !playerIds.Contains(stat.PlayerId2)) { continue; } if (stat.PlayerId3 != null && !playerIds.Contains(stat.PlayerId3)) { continue; } match = stat; break; } if (match == null) { // No match was found var players = await GetPlayersAsync(); var playerGroup = players.Where(p => playerIds.Contains(p.RowKey.ToString())).OrderBy(p => p.Name).ToList(); // Create a new stat match = new StatsEntity { PartitionKey = partitionKey, RowKey = Guid.NewGuid().ToString(), Name = string.Join(" vs ", playerGroup.Select(p => p.Name).ToList()), Wins1 = 0, Wins2 = 0, Wins3 = 0, }; // Update the player ids and the winner if (playerIds.Count >= 1) { match.PlayerId1 = playerIds[0]; if (winnerId == match.PlayerId1) { ++match.Wins1; } } if (playerIds.Count >= 2) { match.PlayerId2 = playerIds[1]; if (winnerId == match.PlayerId2) { ++match.Wins2; } } if (playerIds.Count >= 3) { match.PlayerId3 = playerIds[2]; if (winnerId == match.PlayerId3) { ++match.Wins3; } } // Insert new stat TableOperation insert = TableOperation.Insert(match); await statsTable.ExecuteAsync(insert); } else { // Increment the stat for the player that one if (winnerId == match.PlayerId1) { ++match.Wins1; } if (winnerId == match.PlayerId2) { ++match.Wins2; } if (winnerId == match.PlayerId3) { ++match.Wins3; } // Update stat TableOperation update = TableOperation.Replace(match); await statsTable.ExecuteAsync(update); } }