public async Task <Response <string> > ConsumeGameList() { Response <string> response = new Response <string>(); GameModelCollection gameModels = new GameModelCollection("https://api.twitch.tv/kraken/games/top?"); try { for (int i = 0; i < 10; i++) { gameModels.SetQuery(i); response.Consume(await VisitEndpointAsync(gameModels.Query)); BsonDocument doc = BsonDocument.Parse(response.ResponseCollection[response.ResponseCollection.Count - 1].Result); foreach (var _doc in doc["top"].AsBsonArray) { GameModel temp = new GameModel(); temp.ApiId = (int)_doc["game"]["_id"]; temp.Game = (string)_doc["game"]["name"]; temp.TotalViewCount = (int)_doc["viewers"]; temp.Channels = (int)_doc["channels"]; gameModels.Cache.Add(temp); } response.Consume(await gameModels.SaveCache(new MongoAccess(_config.ConnectionStrings["local"], "stream_cache"))); Thread.Sleep(10000); //query controller } } catch (Exception ex) { response.ReceiveException(ex, MethodBase.GetCurrentMethod()); } return(response); }
/// <summary> /// Carga los juegos de un archivo /// </summary> internal GameModelCollection Load(string fileName) { GameModelCollection games = new GameModelCollection(); Database gameDb = new PgnReader().ReadFromFile(fileName); // Inicializa los juegos foreach (Game game in gameDb.Games) { games.Add(Parse(game)); } // Devuelve los juegos cargados return(games); }