/// <summary> /// Gets a collection of all the available platforms. /// </summary> /// <returns>A collection of all the available platforms</returns> public static async Task <ICollection <ApiPlatformSearchResult> > GetPlatforms() { XmlDocument doc = new XmlDocument(); var docstring = await StaticWebClient .DownloadDataAsync(new Uri(@"http://thegamesdb.net/api/GetPlatformsList.php")) .ConfigureAwait(false); doc.Load(docstring); XmlNode root = doc.DocumentElement; IEnumerator ienum = root.FirstChild.NextSibling.GetEnumerator(); List <ApiPlatformSearchResult> platforms = new List <ApiPlatformSearchResult>(); // Iterate through all platforms XmlNode platformNode; while (ienum.MoveNext()) { platformNode = (XmlNode)ienum.Current; ApiPlatformSearchResult platform = new ApiPlatformSearchResult(); IEnumerator ienumPlatform = platformNode.GetEnumerator(); XmlNode attributeNode; while (ienumPlatform.MoveNext()) { attributeNode = (XmlNode)ienumPlatform.Current; // Iterate through all platform attributes switch (attributeNode.Name) { case "id": int.TryParse(attributeNode.InnerText, out int id); platform.ID = id; break; case "name": platform.Name = attributeNode.InnerText; break; case "alias": platform.Alias = attributeNode.InnerText; break; } } platforms.Add(platform); } return(platforms); }
/// <summary> /// Gets all the games for a platform. /// </summary> /// <param name="platform">The platform to return games for</param> /// <returns>A collection of all the games on the platform</returns> public static async Task <ICollection <ApiGameSearchResult> > GetPlatformGames(ApiPlatformSearchResult platform) { ICollection <ApiGameSearchResult> games = await ApiGamesDb.GetPlatformGames(platform.ID) .ConfigureAwait(false); foreach (ApiGameSearchResult game in games) { game.Platform = platform.Name; } return(games); }
/// <summary> /// Gets all data for a specific platform. /// </summary> /// <param name="platform">The platform to return data for (can be found by using GetPlatformsList)</param> /// <returns>A Platform-object containing all the data about the platform, or null if no platform was found</returns> public static async Task <ApiPlatform> GetPlatform(ApiPlatformSearchResult platform) { return(await ApiGamesDb.GetPlatform(platform.ID).ConfigureAwait(false)); }