/// <summary>Gets the covers related to games asynchronous.</summary> /// <param name="games">The games.</param> /// <returns></returns> public async Task <GameRoot[]> GetCoversToGamesAsync(GameRoot[] games) { try { var results = await _httpClient.PostAsync(new Uri(BaseUriString.IGDBCovers), new HttpStringContent( "fields *;" + "where id = (" + IdStringBuilder.GameIds(games) + ");", UnicodeEncoding.Utf8, "application/json")); var jsonGame = await results.Content.ReadAsStringAsync(); var coversArr = JsonConvert.DeserializeObject <GameCover[]>(jsonGame); foreach (var cover in coversArr) { cover.url = "https:" + cover.url; foreach (var game in games) { if (cover.id == game.Cover) { game.GameCover = cover; } } } return(games); } catch (HttpRequestException e) { GrToast.SmallToast(GrToast.Errors.IgdbError); await Log.WriteMessage(this + " ; " + e.Message + " : " + e.StackTrace).ConfigureAwait(true); return(null); } }
/// <summary>Gets the games asynchronous.</summary> /// <param name="gameNames">The game names.</param> /// <returns></returns> public async Task <GameRoot[]> GetGamesAsync(string gameNames) { try { var results = await _httpClient.PostAsync(new Uri(BaseUriString.IGDBGames), new HttpStringContent( "fields *;" + "search \"" + gameNames + "\"*;" + "where cover != 0;" + "limit 50;", UnicodeEncoding.Utf8, "application/json")); var jsonGame = await results.Content.ReadAsStringAsync(); if (!results.IsSuccessStatusCode) { return(null); } var gamesArr = JsonConvert.DeserializeObject <GameRoot[]>(jsonGame); return(gamesArr); } catch (HttpRequestException e) { await Log.WriteMessage(this + " ; " + e.Message + " : " + e.StackTrace).ConfigureAwait(true); GrToast.SmallToast(GrToast.Errors.IgdbError); return(null); } }
private static async void InitializeAppRequirements() { using (var userGroups = new UserGroups()) { var userGroup = await userGroups.GetUserGroup("User").ConfigureAwait(false); if (userGroup != null) { return; } if (await userGroups.AddUserGroup(new UserGroup { Group = "User" }).ConfigureAwait(false) != HttpStatusCode.Created) { GrToast.SmallToast(GrToast.Errors.NetworkError); return; } if (await userGroups.AddUserGroup(new UserGroup { Group = "Admin" }).ConfigureAwait(false) != HttpStatusCode.Created) { GrToast.SmallToast(GrToast.Errors.NetworkError); } } }
/// <summary> Initialize a search towards IGDB based on parameter</summary> /// <param name="gameName">Name of the game.</param> public async void InitializeGameSearchAsync(string gameName) { Page.WaitVisual(true); Games.Clear(); var context = new IgdbAccess(); using (context) { try { var games = await context.GetGamesAsync(gameName).ConfigureAwait(true); if (games.Length != 0) { await InitializeCoversToGameAsync(games, context).ConfigureAwait(true); Page.WaitVisual(false); PreviousGamesObservableCollection = Games; return; } } catch (HttpRequestException) { GrToast.SmallToast(GrToast.Errors.NetworkError); Page.WaitVisual(false); return; } } Page.WaitVisual(false); GrToast.SmallToast("No game found"); }
/// <summary>Gets the game by identifier.</summary> /// <param name="id">The identifier.</param> /// <returns></returns> public async Task <GameRoot> GetGameById(int id) { try { try { var httpResponse = await _httpClient.GetAsync(new Uri(BaseUriString.Games + id)).ConfigureAwait(true); if (httpResponse.StatusCode != HttpStatusCode.OK) { return(null); } var jsonGame = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(true); ResultGame = JsonConvert.DeserializeObject <GameRoot>(jsonGame); return(ResultGame.Id != 0 ? ResultGame : null); } catch (TaskCanceledException e) { await Log.WriteMessage(this + " ; " + e.Message + " : " + e.StackTrace).ConfigureAwait(true); GrToast.SmallToast(GrToast.Errors.ApiError); return(null); } } catch (HttpRequestException e) { await Log.WriteMessage(this + " ; " + e.Message + " : " + e.StackTrace).ConfigureAwait(true); GrToast.SmallToast(GrToast.Errors.ApiError); return(null); } }
/// <summary>Adds the game.</summary> /// <param name="mainGame">The main game.</param> /// <returns></returns> public async Task <HttpResponseMessage> AddGame(GameRoot mainGame) { try { try { var payload = JsonConvert.SerializeObject(mainGame); HttpContent cont = new StringContent(payload, Encoding.UTF8, "application/json"); var result = await _httpClient.PostAsync(new Uri(BaseUriString.Games), cont).ConfigureAwait(true); return(result); } catch (TaskCanceledException e) { await Log.WriteMessage(this + " ; " + e.Message + " : " + e.StackTrace).ConfigureAwait(true); return(new HttpResponseMessage { StatusCode = HttpStatusCode.RequestTimeout }); } } catch (HttpRequestException e) { await Log.WriteMessage(this + " ; " + e.Message + " : " + e.StackTrace).ConfigureAwait(true); GrToast.SmallToast(GrToast.Errors.ApiError); return(null); } }
/// <summary>Executes initializing of search based on Search bar query text </summary> /// <param name="sender">Search bar</param> /// <param name="args">The <see cref="SearchBoxQuerySubmittedEventArgs" /> instance containing the event data.</param> public void SubmitSearch(SearchBox sender, SearchBoxQuerySubmittedEventArgs args) { if (!NetworkInterface.GetIsNetworkAvailable()) { GrToast.SmallToast(GrToast.Errors.NetworkError); return; } sender.IsFocusEngaged = false; InitializeGameSearchAsync(args.QueryText); }
/// <summary>Fetches the games related to user reviews.</summary> public async void FetchGamesRelatedToUserReviews() { foreach (var review in UserAuthenticator.SessionUserAuthenticator.User.Reviews) { var game = await new Games().GetGameById(review.GameRootId).ConfigureAwait(true); if (game == null) { GrToast.SmallToast(GrToast.Errors.ApiError); return; } if (Games.All(x => x.Id != game.Id)) { Games.Add(game); } } }
/// <summary>Gets the platforms related to game asynchronous.</summary> /// <param name="game">The game.</param> /// <returns></returns> public async Task <Platform[]> GetPlatformsAsync(GameRoot game) { try { var results = await _httpClient.PostAsync(new Uri(BaseUriString.IGDBPlatforms), new HttpStringContent( "fields *;" + "where id = (" + IdStringBuilder.PlatformIds(game) + ");", UnicodeEncoding.Utf8, "application/json")); var jsonGame = await results.Content.ReadAsStringAsync(); var platforms = JsonConvert.DeserializeObject <Platform[]>(jsonGame); return(platforms); } catch (HttpRequestException e) { await Log.WriteMessage(this + " ; " + e.Message + " : " + e.StackTrace).ConfigureAwait(true); GrToast.SmallToast(GrToast.Errors.IgdbError); return(null); } }