Exemplo n.º 1
0
        private MessageResult RollbackGame(Command command, Match args)
        {
            var leagueName       = args.Group("league");
            var gamesPersistence = new ListPersistenceApi <Game>(m_Persistence, "games." + leagueName);
            var existingGames    = gamesPersistence.ReadList();

            var lastGame = existingGames.Last();

            gamesPersistence.RemoveFromList(x => x.Id == lastGame.Id);

            existingGames = gamesPersistence.ReadList();
            var league = GetCurrentLeague(existingGames);

            // Wipe the leaderboard
            var playersPersistence = new HashPersistenceApi <int>(m_Persistence, "players." + leagueName);

            playersPersistence.Clear();

            // Recalculate
            var leaderboard = league.GetLeaderBoard(m_EloScoringStrategy).ToList();

            foreach (var player in leaderboard.Select(x => x.Name))
            {
                var newRanking = GetRatingForPlayer(leaderboard, player);
                playersPersistence.Set(player, int.Parse(newRanking.ToString()));
            }

            return(new MessageResult(new List <Response>()
            {
                Response.ToMessage(command, "Successfully rolled back the last game")
            }));
        }
Exemplo n.º 2
0
        public MessageResult ProcessTimerTick()
        {
            var trackedTickets = m_Persistence.ReadList();

            var comparison = trackedTickets.Select(x =>
                                                   new Update <TeamcityBuildStatus>(x.Channel, x.Value, m_TeamcityBuildApi.GetBuild(x.Value.Id).Result)
                                                   ).Where(x => x.NewValue.IsNotDefault());

            var results = m_TeamcityBuildCompareEngine.Compare(comparison).ToList();

            foreach (var result in results)
            {
                var id = result.NewValue.Id;
                m_Persistence.RemoveFromList(x => x.Value.Id == id);
                m_Persistence.AddToList(new Tracked <TeamcityBuildStatus>(result.NewValue, result.Response.Channel));
            }

            return(new MessageResult(results.Select(x => x.Response).ToList()));
        }