Esempio n. 1
0
        private static GameInfo ConvertNodeToInfo(XmlNode node)
        {
            string title                 = node.Attributes["Name"].Value;
            string id                    = node.Attributes["Id"].Value;
            string publisher             = node.Attributes["Publisher"].Value;
            string developer             = node.Attributes["Developer"].Value;
            bool   coOp                  = Boolean.Parse(node.Attributes["Co-Op"].Value);
            int    players               = Convert.ToInt32(node.Attributes["Players"].Value);
            string overview              = null;
            List <GameInfo.Image> images = new List <GameInfo.Image>();
            List <string>         genres = new List <string>();

            foreach (XmlNode child in node.ChildNodes)
            {
                switch (child.Name)
                {
                case "Overview":
                    overview = child.InnerText;
                    break;

                case "Genres":
                    foreach (XmlNode genre in child.ChildNodes)
                    {
                        genres.Add(genre.InnerText);
                    }
                    break;

                case "Images":
                    foreach (XmlNode imageNode in child.ChildNodes)
                    {
                        string url = imageNode.Attributes["Url"].Value;
                        GameInfo.Image.ImageStyle style = (GameInfo.Image.ImageStyle)Enum.Parse(typeof(GameInfo.Image.ImageStyle), imageNode.Attributes["Type"].Value);
                        images.Add(new GameInfo.Image(url, style));
                    }
                    break;
                }
            }
            return(new GameInfo(id, title, genres, coOp, players, publisher, developer, images, overview, null));
        }
Esempio n. 2
0
        internal static async Task <GameInfo> GetGame(string rom, string system)
        {
            if (Globals.gamesDbConnection == null)
            {
                Globals.gamesDbConnection = CheckConnection();
                if (Globals.gamesDbConnection == false)
                {
                    return(null);
                }
            }
            var             apiURL   = new Uri(baseUri, $"api/GetGame.php?exactname={rom}&platform={system}");
            HttpWebRequest  request  = (WebRequest.Create(apiURL.ToString())) as HttpWebRequest;
            HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();

            Stream       receiveStream = response.GetResponseStream();
            StreamReader readStream    = null;

            if (response.CharacterSet == null)
            {
                readStream = new StreamReader(receiveStream);
            }
            else
            {
                readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
            }

            string      page = readStream.ReadToEnd();
            XmlDocument xDoc = new XmlDocument();

            xDoc.LoadXml(page);

            XmlNode  node   = xDoc.SelectSingleNode("Data/Game");
            GameInfo output = null;

            if (node != null)
            {
                string                id         = null;
                string                title      = null;
                string                platformId = null;
                string                platform   = null;
                string                overview   = null;
                List <string>         genres     = new List <string>();
                int?                  players    = null;
                bool?                 coOp       = null;
                string                publisher  = null;
                string                developer  = null;
                List <GameInfo.Image> images     = new List <GameInfo.Image>();
                foreach (XmlNode child in node.ChildNodes)
                {
                    switch (child.Name)
                    {
                    case "id":
                        id = child.InnerText;
                        break;

                    case "GameTitle":
                        title = child.InnerText;
                        break;

                    case "PlatformId":
                        platformId = child.InnerText;
                        break;

                    case "Platform":
                        platform = child.InnerText;
                        break;

                    case "Overview":
                        overview = child.InnerText;
                        break;

                    case "Genres":
                        foreach (XmlNode genre in child.ChildNodes)
                        {
                            genres.Add(genre.InnerText);
                        }
                        break;

                    case "Players":
                        int holder;
                        if (int.TryParse(child.InnerText, out holder))
                        {
                            players = holder;
                        }
                        players = Convert.ToInt32(child.InnerText);
                        break;

                    case "Co-op":
                        switch (child.InnerText)
                        {
                        case "Yes":
                            coOp = true;
                            break;

                        case "No":
                            coOp = false;
                            break;
                        }
                        break;

                    case "Publisher":
                        publisher = child.InnerText;
                        break;

                    case "Developer":
                        developer = child.InnerText;
                        break;

                    case "Images":
                        foreach (XmlNode imageNode in child.ChildNodes)
                        {
                            GameInfo.Image.ImageStyle style = GameInfo.Image.ImageStyle.Unknown;
                            switch (imageNode.Name)
                            {
                            case "boxart":
                                //style = GameInfo.Image.ImageStyle.BoxArt;
                                switch (imageNode.Attributes["side"].Value)
                                {
                                case "back":
                                    style = GameInfo.Image.ImageStyle.BoxArt_Back;
                                    break;

                                case "front":
                                    style = GameInfo.Image.ImageStyle.BoxArt_Front;
                                    break;

                                default:
                                    break;
                                }
                                break;

                            case "screenshot":
                                style = GameInfo.Image.ImageStyle.ScreenShot;
                                break;

                            case "clearlogo":
                                style = GameInfo.Image.ImageStyle.ClearLogo;
                                break;

                            case "banner":
                                style = GameInfo.Image.ImageStyle.Banner;
                                break;

                            case "fanart":
                                style = GameInfo.Image.ImageStyle.FanArt;
                                break;

                            default:
                                throw new NotImplementedException();
                            }

                            string imageUri = null;
                            if (imageNode.ChildNodes.Count == 1)
                            {
                                imageUri = imageNode.InnerText;
                            }
                            else
                            {
                                foreach (XmlNode imageSizeNode in imageNode.ChildNodes)
                                {
                                    if (imageSizeNode.Name == "original")
                                    {
                                        imageUri = imageSizeNode.InnerText;
                                    }
                                }
                            }
                            if (!imageUri.StartsWith("banners"))
                            {
                                imageUri = "banners/" + imageUri;
                            }
                            string url = new Uri(baseUri, imageUri).ToString();
                            images.Add(new GameInfo.Image(url, style));
                        }
                        break;
                    }
                }
                output = new GameInfo(id, title, genres, coOp, players, publisher, developer, images, overview, system);
            }
            else
            {
                output = new GameInfo(null, rom, new List <string>(), null, 1, new List <GameInfo.Image>(), noDataOverview, system);
            }
            return(output);
        }