Beispiel #1
0
        /// <summary>
        /// Gets a collection of games matched up with loose search terms.
        /// </summary>
        /// <param name="name">The game title to search for</param>
        /// <param name="platform">Filters results by platform</param>
        /// <param name="genre">Filters results by genre</param>
        /// <returns>A collection of games that matched the search terms</returns>
        public static async Task <ICollection <ApiGameSearchResult> > GetGames(string name, string platform = "",
                                                                               string genre = "")
        {
            XmlDocument doc       = new XmlDocument();
            var         docstring = await StaticWebClient.DownloadDataAsync(new Uri(
                                                                                @"http://thegamesdb.net/api/GetGamesList.php?name=" + name + @"&platform=" + platform + @"&genre=" +
                                                                                genre))
                                    .ConfigureAwait(false);

            doc.Load(docstring);

            XmlNode     root  = doc.DocumentElement;
            IEnumerator ienum = root.GetEnumerator();

            List <ApiGameSearchResult> games = new List <ApiGameSearchResult>();

            // Iterate through all games
            XmlNode gameNode;

            while (ienum.MoveNext())
            {
                ApiGameSearchResult game = new ApiGameSearchResult();
                gameNode = (XmlNode)ienum.Current;

                IEnumerator ienumGame = gameNode.GetEnumerator();
                XmlNode     attributeNode;
                while (ienumGame.MoveNext())
                {
                    attributeNode = (XmlNode)ienumGame.Current;

                    // Iterate through all game attributes
                    switch (attributeNode.Name)
                    {
                    case "id":
                        int.TryParse(attributeNode.InnerText, out int id);
                        game.ID = id;
                        break;

                    case "GameTitle":
                        game.Title = attributeNode.InnerText;
                        break;

                    case "ReleaseDate":
                        game.ReleaseDate = attributeNode.InnerText;
                        break;

                    case "Platform":
                        game.Platform = attributeNode.InnerText;
                        break;
                    }
                }

                games.Add(game);
            }

            return(games);
        }
Beispiel #2
0
 /// <summary>
 /// Gets the data for a specific game.
 /// </summary>
 /// <param name="game">The game to return data for</param>
 /// <returns>A Game-object containing all the data about the game, or null if no game was found</returns>
 public static async Task <ApiGame> GetGame(ApiGameSearchResult game)
 {
     return(await ApiGamesDb.GetGame(game.ID)
            .ConfigureAwait(false));
 }