Exemple #1
0
        public static ComicVineIssue GetIssue(SearchType searchType, string data, bool details)
        {
            if (searchType == null)
            {
                throw new ArgumentNullException("searchType");
            }

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }


            ComicVineIssue comicVineIssue = null;

            if (searchType == SearchType.Xml)
            {
                comicVineIssue = XmlReadIssue.GetIssue(data);
            }
            else
            {
                comicVineIssue = JsonReadIssue.GetIssue(data, details);
            }

            return(comicVineIssue);
        }
        public static ComicVineIssue GetIssue(string jsonData, bool details)
        {
            JObject jObject = JObject.Parse(jsonData);

            string how_many_string = jObject["number_of_total_results"].ToString();
            bool   found           = false;
            int    how_many_number = 0;

            found = int.TryParse(how_many_string, out how_many_number);

            ComicVineIssue comicVineIssue = new ComicVineIssue();

            if (how_many_number > 0)
            {
                if (!details)
                {
                    string res = jObject["results"].ToString();
                    JArray a   = JArray.Parse(res);
                    return(Get((JObject)a[0], false));
                }
                else
                {
                    return(Get((JObject)jObject["results"], true));
                }
            }
            return(comicVineIssue);
        }
Exemple #3
0
        public ComicVineIssue GetComicVineIssue(int volumeId, int issueNumber)
        {
            ComicVineIssue comicVineIssue = new ComicVineIssue();

            string query = null;

            if (this.SearchType == SearchType.Xml)
            {
                query = this.ComicVineAddress + "issues/?api_key=" + this.ComicVineKey + "&format=xml&field_list=id,api_detail_url,issue_number,cover_date,name,image,person_credits,character_credits,volume&filter=issue_number:" + issueNumber.ToString() + ",volume:" + volumeId.ToString();
            }
            else
            {
                query = this.ComicVineAddress + "issues/?api_key=" + this.ComicVineKey + "&format=json&field_list=id,api_detail_url,issue_number,cover_date,name,image,person_credits,character_credits,volume&filter=issue_number:" + issueNumber.ToString() + ",volume:" + volumeId.ToString();
            }

            Task <ComicVineResponse> firstResponse = ComicVineConnection.ConnectAndRequest(query);

            comicVineIssue = ComicVineReader.GetIssue(this.SearchType, firstResponse.Result.Response, issueNumber, false);

            if (comicVineIssue.id > 0)
            {
                return(GetComicVineIssue(comicVineIssue.id));
            }
            else
            {
                return(comicVineIssue);
            }
        }
Exemple #4
0
        public List <ComicVineIssue> SearchIssue(string volumeName, int issueNumber)
        {
            List <ComicVineVolume> comicVineVolumeList = this.FindVolumeIdByName(volumeName);

            ConcurrentBag <ComicVineIssue> comicVineIssueBag = new ConcurrentBag <ComicVineIssue>();

            int parallelThreads = SystemEnvironment.ProcessorCountOptimizedForEnvironment();

            Parallel.ForEach(comicVineVolumeList, new ParallelOptions()
            {
                MaxDegreeOfParallelism = parallelThreads
            }, comicVineVolume =>
            {
                try
                {
                    if (comicVineVolume != null)
                    {
                        ComicVineIssue detailedComicVineIssue = this.GetComicVineIssue(comicVineVolume.id, issueNumber);

                        if (detailedComicVineIssue.issue_number == issueNumber.ToString())
                        {
                            comicVineIssueBag.Add(detailedComicVineIssue);
                        }
                    }
                }
                catch (AggregateException aggregateException)
                {
                    foreach (var exception in aggregateException.InnerExceptions)
                    {
                        if (exception is ArgumentException)
                        {
                            // Don't act on this
                        }
                        else
                        {
                            throw exception;
                        }
                    }
                }
            });

            return(comicVineIssueBag.ToList());
        }
Exemple #5
0
        public ComicVineIssue GetComicVineIssue(int issueId)
        {
            ComicVineIssue comicVineIssue = new ComicVineIssue();

            string query = null;

            if (this.SearchType == SearchType.Xml)
            {
                query = this.ComicVineAddress + "issue/4000-" + issueId.ToString() + "/?api_key=" + this.ComicVineKey + "&format=xml&field_list=id,api_detail_url,description,image,issue_number,name,person_credits,character_credits,cover_date,volume";
            }
            else
            {
                query = this.ComicVineAddress + "issue/4000-" + issueId.ToString() + "/?api_key=" + this.ComicVineKey + "&format=json&field_list=id,api_detail_url,description,image,issue_number,name,person_credits,character_credits,cover_date,volume";
            }

            Task <ComicVineResponse> firstResponse = ComicVineConnection.ConnectAndRequest(query);

            comicVineIssue = ComicVineReader.GetIssue(this.SearchType, firstResponse.Result.Response, true);


            return(comicVineIssue);
        }
        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);
        }
        static void Main(string[] args)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            // Suppose we want extract details about "The Amazing Spider-Man 175" published in December 1977.
            // First we need to extract a list of Volume candidates.

            string searchedVolume = "The Amazing Spider-Man";
            int    issueNumber    = 175;

            List <ComicVineIssue> comicVineIssueList = new List <ComicVineIssue>();

            ComicVineService comicVineService = new ComicVineService();

            comicVineService.ComicVineKey = "YOURKEY";

            // Xml Working

            comicVineService.SearchType = SearchType.Json;
            comicVineService.MatchType  = MatchType.AbsoluteMatch;

            // Query the service
            List <ComicVineVolume> comicVinevolumes = new List <ComicVineVolume>();

            comicVinevolumes = comicVineService.SearchVolume(searchedVolume);

            if (comicVinevolumes.Count > 0)
            {
                Console.WriteLine("The query returned " + comicVinevolumes.Count.ToString() + " results");
                foreach (ComicVineVolume volu in comicVinevolumes)
                {
                    Console.WriteLine(volu.id.ToString() + " - " + volu.name);


                    ComicVineIssue issue = new ComicVineIssue();
                    issue = comicVineService.GetComicVineIssue(volu.id, issueNumber);

                    if (issue.id > 0)
                    {
                        Console.WriteLine("We have a full match!");
                        Console.WriteLine("");
                        Console.WriteLine("Title: " + issue.name);
                        Console.WriteLine("URL: " + issue.api_detail_url);
                        Console.WriteLine("Issue number: " + issue.issue_number);
                        Console.WriteLine("Id: " + issue.id);

                        Console.WriteLine("----------");
                        Console.WriteLine("# of Credits:" + issue.credits.Count.ToString());
                        foreach (ComicVineCredit credit in issue.credits)
                        {
                            Console.WriteLine(credit.name + ": " + credit.role);
                        }

                        Console.WriteLine("----------");
                        Console.WriteLine("# of Characters:" + issue.characters.Count.ToString());
                        foreach (ComicVineCharacter character in issue.characters)
                        {
                            Console.WriteLine(character.name);
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("The query returned 0 results");
            }


            stopWatch.Stop();

            // Get the elapsed time as a TimeSpan value.
            TimeSpan timeSpan = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds / 10);

            Console.WriteLine("");
            Console.WriteLine("RunTime " + elapsedTime);
            Console.WriteLine("");

            Console.ReadLine();
        }
Exemple #8
0
        public static ComicVineVolume GetVolume(string xmlString)
        {
            ComicVineVolume comicVineVolume = new ComicVineVolume();

            XDocument xDocument = XDocument.Parse(xmlString);

            comicVineVolume.url                = XmlUtilFunctions.getNodeValue(xDocument, "api_detail_url");
            comicVineVolume.count_of_issues    = StringUtilFunctions.TryToParse(XmlUtilFunctions.getNodeValue(xDocument, "count_of_issues"));
            comicVineVolume.volume_description = XmlUtilFunctions.getNodeValue(xDocument, "description");
            comicVineVolume.id = StringUtilFunctions.TryToParse(XmlUtilFunctions.getNodeValue(xDocument, "id"));


            ComicVineImages comicVineImages = new ComicVineImages();

            var images = from imgs in xDocument.Descendants("image") select imgs;

            if (images.Count() > 0)
            {
                try
                {
                    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;
                }
                catch (Exception ex)
                {
                }
            }

            comicVineVolume.images = comicVineImages;

            List <ComicVineIssue> comicVineIssueList = new List <ComicVineIssue>();

            var issues = from iss in xDocument.Descendants("issue") select iss;

            foreach (var issue in issues)
            {
                ComicVineIssue comicVineIssue = new ComicVineIssue();
                comicVineIssue.id             = StringUtilFunctions.TryToParse(issue.Descendants("id").First().Value);
                comicVineIssue.api_detail_url = issue.Descendants("api_detail_url").First().Value;
                comicVineIssue.name           = issue.Descendants("name").First().Value;
                comicVineIssue.issue_number   = issue.Descendants("issue_number").First().Value;

                comicVineIssueList.Add(comicVineIssue);
            }

            comicVineVolume.list_of_issue = comicVineIssueList;
            comicVineVolume.name          = XmlUtilFunctions.getNodeValue(xDocument, "name");

            ComicVinePublisher comicVinePublisher = new ComicVinePublisher();

            var publishers = from publ in xDocument.Descendants("publisher") select publ;

            if (publishers != null & publishers.Count() > 0)
            {
                try
                {
                    comicVinePublisher.publisher_name = publishers.Descendants("name").First().Value;
                    comicVinePublisher.publisher_id   = StringUtilFunctions.TryToParse(publishers.Descendants("id").First().Value);
                    comicVinePublisher.publisher_url  = publishers.Descendants("api_detail_url").First().Value;
                }
                catch (Exception ex)
                {
                }
            }

            comicVineVolume.publisher  = comicVinePublisher;
            comicVineVolume.start_year = StringUtilFunctions.TryToParse(XmlUtilFunctions.getNodeValue(xDocument, "start_year"));

            return(comicVineVolume);
        }
        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);
        }