/// <summary> /// IGDB Helper Class for Working with IGDB API efficiently for thi project. /// </summary> /// <param name="listDataTable">DataTable that stores all the Picked Results.</param> /// <param name="serviceClient">Initialized IGDB/Twitch Client</param> /// <param name="imgDownloadList">List that stores all the images to download.</param> public IgdbClass(ref DataTable listDataTable, ref IGDBClient serviceClient, ref List <ImageToDownload> imgDownloadList) { _listDataTable = listDataTable ?? throw new ArgumentNullException(nameof(listDataTable)); _serviceClient = serviceClient ?? throw new ArgumentNullException(nameof(serviceClient)); _imgDownloadList = imgDownloadList ?? throw new ArgumentNullException(nameof(imgDownloadList)); }
public Games() { _api = new IGDB.IGDBClient( Environment.GetEnvironmentVariable("IGDB_CLIENT_ID"), Environment.GetEnvironmentVariable("IGDB_CLIENT_SECRET") ); }
public Games() { var IGDB_CLIENT_ID = "suir6rwr94fhs2s3x8jcyfqfjpd6lj"; var IGDB_CLIENT_SECRET = "a07fcbs0o7est8f2p9o6qpk09t5zfw"; _api = new IGDB.IGDBClient(IGDB_CLIENT_ID, IGDB_CLIENT_SECRET); // Environment.GetEnvironmentVariable("IGDB_CLIENT_ID"), // Environment.GetEnvironmentVariable("IGDB_CLIENT_SECRET") //); }
public async Task <IActionResult> HomeAsync() { var userid = User.Claims.FirstOrDefault().Value.ToString(); if (userid == null) { return(RedirectToAction("login", "LogonProfile")); } _api = new IGDB.IGDBClient(IGDB_CLIENT_ID, IGDB_CLIENT_SECRET); int?Maxrating = HttpContext.Session.GetInt32("MaxRating"); int?Minrating = HttpContext.Session.GetInt32("MinRating"); if (Maxrating == null) { HttpContext.Session.SetInt32("MaxRating", 100); } if (Minrating == null) { HttpContext.Session.SetInt32("MinRating", 1); } if (TempData["gameName"] == null) { TempData["gameName"] = "Halo"; //Test Account } var DashboardBundle = await FetchGames((string)TempData["gameName"]); if (DashboardBundle.games.Count < 1) { TempData["gameName"] = "Halo"; return(RedirectToAction("ForbiddenError", "ErrorPages")); } var dbUser = _dbContext.UserAccounts.FirstOrDefault(user => user.UserId == userid); if (dbUser == null) { return(RedirectToAction("register", "LogonProfile")); } //throw new NullReferenceException(nameof(dbUser)); DashboardBundle.user = dbUser; HttpContext.Session.SetString("userName", DashboardBundle.user.FirstName + " " + DashboardBundle.user.LastName); ViewBag.filters = new Dictionary <string, object> { { "MinRating", (int)HttpContext.Session.GetInt32("MinRating") }, { "MaxRating", (int)HttpContext.Session.GetInt32("MaxRating") }, { "Platform", HttpContext.Session.GetString("Platform") }, { "Genre", HttpContext.Session.GetString("Genre") } }; ViewBag.userName = HttpContext.Session.GetString("userName"); return(View("Dashboard", DashboardBundle)); }
public PollingTwitchCategoryProvider( TwitchAPIClient twitchAPIClient, IGDBClient IGDBClient, SteamStoreClient steamStoreClient, IGameLocalizationStore gameLocalizationStore, IOptions <TwitchApplicationOptions> twitchOptions, ILogger <PollingTwitchCategoryProvider> logger) { _twitchAPIClient = twitchAPIClient; _igdbClient = IGDBClient; _gameLocalization = gameLocalizationStore; _twitchOptions = twitchOptions.Value; _logger = logger; }
public GrainTwitchCategoryProvider( IGrainFactory grainFactory, TwitchAPIClient twitchClient, IGDBClient igdbClient, SteamStoreClient steamStoreClient, IGameLocalizationStore localizationStore, ILogger <GrainTwitchCategoryProvider> logger) { _grainFactory = grainFactory; _twitchAPIClient = twitchClient; _igdbClient = igdbClient; _steamStoreClient = steamStoreClient; _gameLocalizationStore = localizationStore; _logger = logger; }
public TwitchCategoriesSynchronizationService( TwitchAPIClient twitchApiClient, IGDBClient igdbClient, SteamStoreClient steamStoreClient, IOptions <TwitchApplicationOptions> options, IGameLocalizationStore gameLocalizationStore, ILogger <TwitchCategoriesSynchronizationService> logger) { _twitchAPIClient = twitchApiClient; _igdbClient = igdbClient; _steamStoreClient = steamStoreClient; _steamStoreClient.WebAPIKey = options.Value.SteamApiKey; _gameLocalization = gameLocalizationStore; _options = options.Value; _logger = logger; }
public async Task <List <Models.Game> > Index() { Database.Games.RemoveRange(Database.Games.ToList()); IGDBClient igdb = new IGDBClient( "gdomcl7slhaqk8348e5ecoxrhavcs5", "jqi256wvzibuy4y5mbexb7efyv0e80" ); Game[] json = igdb.QueryAsync <Game>(IGDBClient.Endpoints.Games, query: "fields id,name,summary; where category = 0 & status = 0; sort rating desc; limit 20;").Result; foreach (Game game in json) { RegisterLogin.Models.Game dbgame = new RegisterLogin.Models.Game { GameName = game.Name, GameSummary = game.Summary }; Database.Games.Add(dbgame); } Database.SaveChanges(); return(await Database.Games.ToListAsync()); }
public GameService(IGDBClient igdbClient, IFileService fileService) { _igdbClient = igdbClient; _fileService = fileService; }
public async void GetDataAndSendToDatabase() { DateTime currentDate = DateTime.UtcNow.Date; DateTime threeMonthsBehindUNIX = DateTime.UtcNow.Date.AddMonths(-3); var firstDayMonth = new DateTime(threeMonthsBehindUNIX.Year, threeMonthsBehindUNIX.Month, 1); var unixFirst = ConvertToUnixTime(firstDayMonth); var unixCurr = ConvertToUnixTime(currentDate); var igdb = new IGDBClient(Environment.GetEnvironmentVariable("CLIENT_ID"), Environment.GetEnvironmentVariable("SECRET")); using var dbcontextpopular = new gamesrankdbContext(); { //First - check if database is created, if not, stop all actions. dbcontextpopular.Database.EnsureCreated(); // // Adding data to Top10PopularGames // // /*>> FDR variables are holding the F.irst R.ow D.ata of selected table for checkups. <<*/ // Top10populargames?FRDPopular = dbcontextpopular.Top10populargames.FirstOrDefault(); if (FRDPopular?.Updated == null) // If date in table is null we provide the thing with data and set the update row. { var top10PopularGames = await igdb.QueryAsync <Game>(IGDBClient.Endpoints.Games, query : "fields id, rating, rating_count, name;" + " sort rating_count desc;" + " where(rating > 60) & (rating_count > 8) & (hypes != null) & (category = 0) & (first_release_date >= " + unixFirst + ") & (first_release_date < " + unixCurr + ");" + " limit 10;"); foreach (Game game in top10PopularGames) //Checking every thing in the top10 popular games object from IGDB API Package. { var TPRecord = new Top10populargames() { GameId = game.Id, Title = game.Name, Rating = game.Rating, RatingCount = game.RatingCount, Updated = currentDate }; dbcontextpopular.Top10populargames.Add(TPRecord); } await dbcontextpopular.SaveChangesAsync(); } else { DateTime LastUpdate = (DateTime)FRDPopular.Updated; TimeSpan timeSpan = currentDate.Subtract(LastUpdate); if (timeSpan.TotalDays > 6) { try { dbcontextpopular.Database.ExecuteSqlRaw("TRUNCATE TABLE top10populargames;"); // Working deletion of all data inside table. await dbcontextpopular.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw new Exception("Failed truncating the tables."); } catch (Exception) { throw; } var top10PopularGames = await igdb.QueryAsync <Game>(IGDBClient.Endpoints.Games, query : "fields id, rating, rating_count, name;" + " sort rating_count desc;" + " where(rating > 60) & (rating_count > 8) & (hypes != null) & (category = 0) & (first_release_date >= " + unixFirst + ") & (first_release_date < " + unixCurr + ");" + " limit 10;"); foreach (Game game in top10PopularGames) //Checking every thing in the top10 popular games object from IGDB API Package. { var TPRecord = new Top10populargames() { GameId = game.Id, Title = game.Name, Rating = game.Rating, RatingCount = game.RatingCount, Updated = currentDate }; dbcontextpopular.Top10populargames.Add(TPRecord); } await dbcontextpopular.SaveChangesAsync(); } } } using var dbcontextgenre = new gamesrankdbContext(); { //First - check if database is created, if not, stop all actions. dbcontextgenre.Database.EnsureCreated(); // // Adding all genres to the Genres table // //Second - Check if there's data, if not, then fill table up. Genres?FRDGenres = dbcontextgenre.Genres.FirstOrDefault(); if (FRDGenres?.GenreId == null) { var genres = await igdb.QueryAsync <Genre>(IGDBClient.Endpoints.Genres, query : "fields id, name; sort name; limit 50; "); foreach (Genre genre in genres) { var GRecord = new Genres() { GenreId = genre.Id, Name = genre.Name }; await dbcontextgenre.Genres.AddAsync(GRecord); } await dbcontextgenre.SaveChangesAsync(); } } using var dbcontextinteresting = new gamesrankdbContext(); { //First - check if database is created, if not, stop all actions. dbcontextinteresting.Database.EnsureCreated(); // // Adding data to Top15InterestingGames that has many-to-many relationship with Genres // Top15interestinggames?FirstRowData = dbcontextinteresting.Top15interestinggames.FirstOrDefault(); if (FirstRowData?.Updated == null) { var top15InterestingGames = await igdb.QueryAsync <Game>(IGDBClient.Endpoints.Games, query : "fields id, name, genres.name, first_release_date, url;" + " sort follows desc;" + " where follows != null & first_release_date >= " + unixFirst + ";" + " limit 15; "); foreach (Game game in top15InterestingGames) { var tmp = game.Genres.Values.ToList(); var ReleaseDate = game.FirstReleaseDate.Value; // var TIRecord = new Top15interestinggames() // { GameId = game.Id, Title = game.Name, FirstReleaseDate = ReleaseDate.UtcDateTime, Url = game.Url, Updated = currentDate }; foreach (Genre genre in tmp) { var genreFromDb = await dbcontextinteresting.Genres.FindAsync(genre.Id); var TIGHG = new Top15interestinggamesHasGenres { GenresGenre = genreFromDb, Top15interestinggamesGame = TIRecord }; TIRecord.Top15interestinggamesHG.Add(TIGHG); } await dbcontextinteresting.Set <Top15interestinggames>().AddAsync(TIRecord); } await dbcontextinteresting.SaveChangesAsync(); } else { DateTime LastUpdate = (DateTime)FirstRowData.Updated; TimeSpan timeSpan = currentDate.Subtract(LastUpdate); if (timeSpan.TotalDays > 6) { try { dbcontextinteresting.Database.ExecuteSqlRaw("DELETE FROM top15interestinggames_has_genres;"); // Working deletion of all data inside table. await dbcontextinteresting.SaveChangesAsync(); dbcontextinteresting.Database.ExecuteSqlRaw("DELETE FROM top15interestinggames;"); await dbcontextinteresting.SaveChangesAsync(); dbcontextinteresting.Database.ExecuteSqlRaw("DELETE FROM genres;"); await dbcontextinteresting.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw new Exception("Failed truncating the tables."); } catch (Exception) { throw; } //First - check if database is created, if not, stop all actions. dbcontextinteresting.Database.EnsureCreated(); // // Adding data to Top15InterestingGames that has many-to-many relationship with Genres // FirstRowData = dbcontextinteresting.Top15interestinggames.FirstOrDefault(); if (FirstRowData?.Updated == null) { var top15InterestingGames = await igdb.QueryAsync <Game>(IGDBClient.Endpoints.Games, query : "fields id, name, genres.name, first_release_date, url;" + " sort follows desc;" + " where follows != null & first_release_date >= " + unixFirst + ";" + " limit 15; "); foreach (Game game in top15InterestingGames) { var tmp = game.Genres.Values.ToList(); var ReleaseDate = game.FirstReleaseDate.Value; // var TIRecord = new Top15interestinggames() // { GameId = game.Id, Title = game.Name, FirstReleaseDate = ReleaseDate.UtcDateTime, Url = game.Url, Updated = currentDate }; foreach (Genre genre in tmp) { var genreFromDb = await dbcontextinteresting.Genres.FindAsync(genre.Id); var TIGHG = new Top15interestinggamesHasGenres { GenresGenre = genreFromDb, Top15interestinggamesGame = TIRecord }; TIRecord.Top15interestinggamesHG.Add(TIGHG); } await dbcontextinteresting.Set <Top15interestinggames>().AddAsync(TIRecord); } await dbcontextinteresting.SaveChangesAsync(); } } } } }