Exemple #1
0
        /// <summary>
        /// Check if the tournament exist in database otherwise call Challonge.
        /// </summary>
        /// <param name="ids">tournaments ids</param>
        /// <param name="games">List of known games</param>
        /// <returns>List of the challonge's tournament with participents</returns>
        private async Task <List <ChallongeTournament> > GetChallongeTournaments(List <int> ids, List <Game> games)
        {
            var tournaments = new List <ChallongeTournament>();

            foreach (var idTournament in ids)
            {
                if (!TournamentExist(idTournament))
                {
                    ChallongeTournament challongeTournament = await _challongeProvider.GetTournament(idTournament);

                    challongeTournament.Participents =
                        await _challongeProvider.GetParticipents(challongeTournament.ChallongeId);

                    var game = games.FirstOrDefault(g => challongeTournament.Name.Contains(g.Name));
                    if (game != null)
                    {
                        challongeTournament.Game = game;
                    }
                    challongeTournament.Sync = DateTime.Now;

                    tournaments.Add(challongeTournament);
                    _context.ChallongeTournament.Add(challongeTournament);
                    _context.SaveChanges();
                }
                else
                {
                    tournaments.Add(_context.ChallongeTournament.Where(e => e.ChallongeId == idTournament)
                                    .Include(e => e.Participents).First());
                }
            }

            return(tournaments);
        }
Exemple #2
0
        private TournamentResult AddTournament(string eventDate, string selectedEvent, Game selectedGame, string url, WPEvent currentEvent)
        {
            int createTry = 0;
            var name      = $"[{eventDate}] LaDOSE.net - {selectedEvent} - {selectedGame.Name}";
            TournamentResult tournament = null;

            do
            {
                try
                {
                    if (createTry > 0)
                    {
                        url += createTry.ToString();
                    }
                    tournament = _challongeProvider.CreateTournament(name, url, currentEvent.Date).Result;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error Creating Challonge : " + ex.Message);
                    try
                    {
                        //Deja crée
                        var result = _challongeProvider.GetTournament(url).Result;
                        if (result.Name == name)
                        {
                            throw;
                        }
                    }
                    catch (Exception getex)
                    {
                        Console.WriteLine("Error Getting Challonge: " + url + " : " + getex.Message);
                    }

                    createTry++;
                }
            } while (tournament == null || createTry > MAX_CREATE_TRY);


            return(tournament);
        }