Exemplo n.º 1
0
        /// <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(ApiPlatform platform)
        {
            ICollection <ApiGameSearchResult> games = await ApiGamesDb.GetPlatformGames(platform.ID)
                                                      .ConfigureAwait(false);

            foreach (ApiGameSearchResult game in games)
            {
                game.Platform = platform.Name;
            }

            return(games);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets all data for a specific platform.
        /// </summary>
        /// <param name="iD">The platform ID 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(int iD)
        {
            XmlDocument doc       = new XmlDocument();
            var         docstring = await StaticWebClient
                                    .DownloadDataAsync(new Uri(@"http://thegamesdb.net/api/GetPlatform.php?id=" + iD))
                                    .ConfigureAwait(false);

            doc.Load(docstring);

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

            XmlNode     platformNode = root.FirstChild.NextSibling;
            ApiPlatform platform     = new ApiPlatform();

            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 "Platform":
                    platform.Name = attributeNode.InnerText;
                    break;

                case "overview":
                    platform.Overview = attributeNode.InnerText;
                    break;

                case "developer":
                    platform.Developer = attributeNode.InnerText;
                    break;

                case "manufacturer":
                    platform.Manufacturer = attributeNode.InnerText;
                    break;

                case "cpu":
                    platform.CPU = attributeNode.InnerText;
                    break;

                case "memory":
                    platform.Memory = attributeNode.InnerText;
                    break;

                case "graphics":
                    platform.Graphics = attributeNode.InnerText;
                    break;

                case "sound":
                    platform.Sound = attributeNode.InnerText;
                    break;

                case "display":
                    platform.Display = attributeNode.InnerText;
                    break;

                case "media":
                    platform.Media = attributeNode.InnerText;
                    break;

                case "maxcontrollers":
                    int.TryParse(attributeNode.InnerText, out int maxControllers);
                    platform.MaxControllers = maxControllers;
                    break;

                case "Rating":
                    float.TryParse(attributeNode.InnerText, out float rating);
                    platform.Rating = rating;
                    break;

                case "Images":
                    platform.Images.FromXmlNode(attributeNode);
                    break;
                }
            }

            return(platform);
        }