Exemplo n.º 1
0
        public async Task <CurrentGame> GetCurrentGame(Summoner summoner, Action <CurrentGame> action = null)
        {
            try
            {
                var playingGame = await MongoDbCurrentGame.FindOneAsync(Builders <CurrentGame> .Filter.Eq(x => x.GameId, summoner.TrackingGameId.GetValueOrDefault()));

                if (playingGame != null)
                {
                    return(playingGame);
                }

                var currentGame = await RiotApi.SpectatorV4.GetCurrentGameInfoBySummonerAsync(Region.Get(summoner.Region), summoner.SummonerId);

                if (currentGame == null)
                {
                    return(null);
                }

                return(await MongoDbCurrentGame.UpsertAsync(Builders <CurrentGame> .Filter.Eq(x => x.GameId, currentGame.GameId),
                                                            currentGame.ConvertTo <CurrentGame, MingweiSamuel.Camille.SpectatorV4.CurrentGameInfo>(),
                                                            async (game) =>
                {
                    game.GameState = Code.GameState.Playing;
                    summoner.TrackingGameId = game.GameId;
                    await MongoDbSummoner.UpdateAsync(summoner.Id, summoner);
                    action?.Invoke(game);
                }));
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex.Message);
                return(null);
            }
        }
Exemplo n.º 2
0
        public CurrentGame EndGame(Summoner summoner, CurrentGame currentGame)
        {
            try
            {
                summoner.TrackingGameId = null;
                MongoDbSummoner.Update(summoner.Id, summoner);

                currentGame.GameState = Code.GameState.End;
                return(MongoDbCurrentGame.Update(currentGame.Id, currentGame));
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex.Message);
                return(null);
            }
        }