public void AskForCompetitors(string gameTypeName, List<ICompetitor> emptyCompetitors)
{
IsPlayButtonAvailable = false;
OutputText += string.Format("Waiting for players ({0})\n", emptyCompetitors.Count);
Task.Run(() =>
{
var competitorsTasks = emptyCompetitors.Select(async bot =>
{
try
{
await bot.VerifyAsync(gameTypeName);
lock (Lock)
{
OutputText += string.Format("Bot \"{0}\" connected!\n", bot.Name);
Elimination.Bots.First(f => f.Id == bot.Id).Name = bot.Name;
}
}
catch (Exception e)
{
bot.Name = "Not connected";
OutputText += string.Format("ERROR: Url: {0} - couldn't verify bot!\nError message:\n{1}\n", bot.Url, e.Message);
}
return bot;
}).ToList();
Task.WhenAll(competitorsTasks).ContinueWith(task =>
{
IsPlayButtonAvailable = true;
if (emptyCompetitors.All(competitor => competitor.IsVerified))
{
OutputText += "All players connected!\n";
}
else
{
OutputText += "WARNING: Not all players were succesfully verified.\nTry reconnecting or play tournament without them\n";
}
});
});
}