示例#1
0
        /// <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");
        }
示例#2
0
        /// <summary>Initializes process of fetching covers related to game asynchronous.</summary>
        /// <param name="games">The games.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private async Task InitializeCoversToGameAsync(GameRoot[] games, IgdbAccess context)
        {
            const int searchLimit = 5;
            var       tempArr     = new GameRoot[searchLimit];
            const int x           = 0;

            if (games.Length > 4)
            {
                await BindCoversToGameLargeAsync(games, context, tempArr, searchLimit, x).ConfigureAwait(true);
            }
            else
            {
                await BindCoversToGameSmallAsync(games, context, x).ConfigureAwait(true);
            }
        }
示例#3
0
        /// <summary>
        ///     Binds the covers to game asynchronous.
        ///     Used if less than 5 covers
        /// </summary>
        /// <param name="games">The games.</param>
        /// <param name="context">The context.</param>
        /// <param name="x">The x.</param>
        /// <returns></returns>
        private async Task BindCoversToGameSmallAsync(GameRoot[] games, IgdbAccess context, int x)
        {
            var toFindCoverList = new GameRoot[games.Length];

            foreach (var t in games)
            {
                toFindCoverList[x] = t;
                x++;
            }

            Page.WaitVisual(false);
            await context.GetCoversToGamesAsync(toFindCoverList).ConfigureAwait(true);

            foreach (var gamesRoot in toFindCoverList)
            {
                Games.Add(gamesRoot);
            }
        }
示例#4
0
        /// <summary>
        ///     Binds the covers to game asynchronous.
        ///     Used if more than 4 covers
        /// </summary>
        /// <param name="games">The games.</param>
        /// <param name="context">The context.</param>
        /// <param name="x">The x.</param>
        /// <returns></returns>
        private async Task BindCoversToGameLargeAsync(GameRoot[] games, IgdbAccess context, GameRoot[] toFindCoverList,
                                                      int searchLimit, int x)
        {
            foreach (var t in games)
            {
                if (toFindCoverList[searchLimit - 1] != null)
                {
                    await context.GetCoversToGamesAsync(toFindCoverList).ConfigureAwait(true);

                    foreach (var gamesRoot in toFindCoverList)
                    {
                        Games.Add(gamesRoot);
                    }
                    toFindCoverList = new GameRoot[searchLimit];
                    x = 0;
                    Page.WaitVisual(false);
                }

                toFindCoverList[x] = t;
                x++;
            }
        }