Exemplo n.º 1
0
        public static ComicVineIssue GetIssue(string xmlString)
        {
            ComicVineIssue comicVineIssue = new ComicVineIssue();

            XDocument xDocument = XDocument.Parse(xmlString, LoadOptions.None);

            comicVineIssue.api_detail_url    = XmlUtilFunctions.getNodeValue(xDocument, "api_detail_url");
            comicVineIssue.issue_description = XmlUtilFunctions.getNodeValue(xDocument, "description");
            comicVineIssue.id = StringUtilFunctions.TryToParse(XmlUtilFunctions.getNodeValue(xDocument, "id"));

            // Get the volume images
            var             images          = from imgs in xDocument.Descendants("image") select imgs;
            ComicVineImages comicVineImages = new ComicVineImages();

            if (images != null | images.Count() > 0)
            {
                comicVineImages.icon_url   = images.Descendants("icon_url").First().Value;
                comicVineImages.medium_url = images.Descendants("medium_url").First().Value;
                comicVineImages.screen_url = images.Descendants("screen_url").First().Value;
                comicVineImages.small_url  = images.Descendants("small_url").First().Value;
                comicVineImages.super_url  = images.Descendants("super_url").First().Value;
                comicVineImages.thumb_url  = images.Descendants("thumb_url").First().Value;
                comicVineImages.tiny_url   = images.Descendants("tiny_url").First().Value;
            }

            comicVineIssue.images       = comicVineImages;
            comicVineIssue.issue_number = XmlUtilFunctions.getNodeValue(xDocument, "issue_number");
            comicVineIssue.name         = XmlUtilFunctions.getNodeValue(xDocument, "name");

            string comic_tentative_date = XmlUtilFunctions.getNodeValue(xDocument, "cover_date");

            comicVineIssue.issue_year  = StringUtilFunctions.TryToExtractYear(comic_tentative_date);
            comicVineIssue.issue_month = StringUtilFunctions.TryToExtractMonth(comic_tentative_date);



            // Get the volume details
            var volumes = from vols in xDocument.Descendants("volume") select vols;

            if (volumes != null & volumes.Count() > 0)
            {
                ComicVineVolume volum = new ComicVineVolume();
                volum.id              = StringUtilFunctions.TryToParse(volumes.Descendants("id").First().Value);
                volum.name            = volumes.Descendants("name").First().Value;
                volum.url             = volumes.Descendants("api_detail_url").First().Value;
                comicVineIssue.volume = volum;
            }



            var persons = from rols in xDocument.Descendants("person") select rols;
            List <ComicVineCredit> comicVineCreditList = new List <ComicVineCredit>();

            if (persons.Count() > 0)
            {
                foreach (var person in persons)
                {
                    ComicVineCredit comicVineCredit = new ComicVineCredit();
                    comicVineCredit.id             = StringUtilFunctions.TryToParse(person.Descendants("id").First().Value);
                    comicVineCredit.name           = person.Descendants("name").First().Value;
                    comicVineCredit.api_detail_url = person.Descendants("api_detail_url").First().Value;
                    comicVineCredit.role           = person.Descendants("role").First().Value;

                    comicVineCreditList.Add(comicVineCredit);
                }
            }

            comicVineIssue.credits = comicVineCreditList;

            var characters = from character in xDocument.Descendants("character") select character;
            List <ComicVineCharacter> comicVineCharacterList = new List <ComicVineCharacter>();

            if (characters.Count() > 0)
            {
                foreach (var tchar in characters)
                {
                    ComicVineCharacter comicVineCharacter = new ComicVineCharacter();
                    comicVineCharacter.id              = StringUtilFunctions.TryToParse(tchar.Descendants("id").First().Value);
                    comicVineCharacter.name            = tchar.Descendants("name").First().Value;
                    comicVineCharacter.api_detail_url  = tchar.Descendants("api_detail_url").First().Value;
                    comicVineCharacter.site_detail_url = tchar.Descendants("site_detail_url").First().Value;

                    comicVineCharacterList.Add(comicVineCharacter);
                }
            }

            comicVineIssue.characters = comicVineCharacterList;

            return(comicVineIssue);
        }
Exemplo n.º 2
0
        private static ComicVineIssue Get(JObject j_ob, bool details)
        {
            ComicVineIssue comicVineIssue = new ComicVineIssue();

            comicVineIssue.id             = (int)j_ob["id"];
            comicVineIssue.api_detail_url = j_ob["api_detail_url"].ToString();

            ComicVineImages images = new ComicVineImages();

            if (!String.IsNullOrEmpty(j_ob["image"].ToString()))
            {
                try
                {
                    images = JsonConvert.DeserializeObject <ComicVineImages>(j_ob["image"].ToString());
                }
                catch (Exception ex)
                {
                    // We don't catch this exeption.
                }
            }

            comicVineIssue.images       = images;
            comicVineIssue.issue_number = j_ob["issue_number"].ToString();
            comicVineIssue.name         = j_ob["name"].ToString();

            string coverdate = j_ob["cover_date"].ToString();

            comicVineIssue.issue_year  = StringUtilFunctions.TryToExtractYear(coverdate);
            comicVineIssue.issue_month = StringUtilFunctions.TryToExtractMonth(coverdate);
            comicVineIssue.issue_title = j_ob["name"].ToString();

            ComicVineVolume volum = new ComicVineVolume();

            if (!String.IsNullOrEmpty(j_ob["volume"].ToString()))
            {
                volum = JsonConvert.DeserializeObject <ComicVineVolume>(j_ob["volume"].ToString());
            }

            comicVineIssue.volume = volum;

            if (details)
            {
                IList <JToken>            jCharacters            = j_ob["character_credits"].Children().ToList();
                IList <JToken>            jCredits               = j_ob["person_credits"].Children().ToList();
                List <ComicVineCharacter> comicVineCharacterList = new List <ComicVineCharacter>();
                List <ComicVineCredit>    comicVineCreditList    = new List <ComicVineCredit>();


                foreach (JToken character in jCharacters)
                {
                    ComicVineCharacter comicVineCharacter = JsonConvert.DeserializeObject <ComicVineCharacter>(character.ToString());
                    comicVineCharacterList.Add(comicVineCharacter);
                }

                foreach (JToken credit in jCredits)
                {
                    ComicVineCredit cc = JsonConvert.DeserializeObject <ComicVineCredit>(credit.ToString());
                    comicVineCreditList.Add(cc);
                }

                comicVineIssue.credits = new List <ComicVineCredit>();
                comicVineIssue.credits = comicVineCreditList;

                comicVineIssue.characters = new List <ComicVineCharacter>();
                comicVineIssue.characters = comicVineCharacterList;
            }



            return(comicVineIssue);
        }