Пример #1
0
        public static ComicVineResponseData GetFirstVolumeQueryResponse(SearchType searchType, string data)
        {
            if (searchType == null)
            {
                throw new ArgumentNullException("searchType");
            }

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

            ComicVineResponseData comicVineResponseData = null;

            if (searchType == SearchType.Xml)
            {
                comicVineResponseData = XmlReadVolumeQuery.GetFirstVolumeQueryResponse(data);
            }
            else
            {
                comicVineResponseData = JsonReadVolumeQuery.GetFirstVolumeQueryResponse(data);
            }

            return(comicVineResponseData);
        }
Пример #2
0
        public static ComicVineResponseData GetFirstVolumeQueryResponse(string jsonData)
        {
            ComicVineResponseData comicVineResponseData = new ComicVineResponseData();

            comicVineResponseData = JsonConvert.DeserializeObject <ComicVineResponseData>(jsonData);

            return(comicVineResponseData);
        }
Пример #3
0
        public static ComicVineResponseData GetFirstVolumeQueryResponse(string xmlString)
        {
            ComicVineResponseData comicVineResponseData = new ComicVineResponseData();

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

            comicVineResponseData.number_of_page_results  = StringUtilFunctions.TryToParse(XmlUtilFunctions.getNodeValue(xDocument, "number_of_page_results"));
            comicVineResponseData.number_of_total_results = StringUtilFunctions.TryToParse(XmlUtilFunctions.getNodeValue(xDocument, "number_of_total_results"));
            comicVineResponseData.limit = StringUtilFunctions.TryToParse(XmlUtilFunctions.getNodeValue(xDocument, "limit"));

            return(comicVineResponseData);
        }
Пример #4
0
        private List <ComicVineVolume> FindVolumeIdByName(string volumeName)
        {
            string query = null;

            if (this.SearchType == SearchType.Xml)
            {
                query = this.ComicVineAddress + "volumes/?api_key=" + this.ComicVineKey + "&format=xml&field_list=id,name,publisher&filter=name:" + volumeName;
            }
            else
            {
                query = this.ComicVineAddress + "volumes/?api_key=" + this.ComicVineKey + "&format=json&field_list=id,name,publisher&filter=name:" + volumeName;
            }

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

            ConcurrentBag <List <ComicVineVolume> > comicVineVolumeLists = new ConcurrentBag <List <ComicVineVolume> >();

            if (comicVineResponse.Result.Status == "OK")
            {
                ComicVineResponseData firstData = ComicVineReader.GetFirstVolumeQueryResponse(this.SearchType, comicVineResponse.Result.Response);

                if (firstData.number_of_total_results > 0)
                {
                    int parallelThreads = SystemEnvironment.ProcessorCountOptimizedForEnvironment();

                    int numberOfIterations = (int)Math.Ceiling(((double)firstData.number_of_total_results / (double)firstData.limit));

                    Parallel.For(0, numberOfIterations, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = parallelThreads
                    }, i =>
                    {
                        int offset         = i * firstData.limit;
                        string secondQuery = query + "&offset=" + offset.ToString();

                        Task <ComicVineResponse> secondResponse = ComicVineConnection.ConnectAndRequest(secondQuery);
                        var volumeList = ComicVineReader.GetVolumeQueryResponse(this.SearchType, secondResponse.Result.Response);

                        comicVineVolumeLists.Add(volumeList);
                        secondResponse = null;
                    });
                }
            }

            if (this.MatchType == MatchType.AbsoluteMatch)
            {
                ConcurrentBag <List <ComicVineVolume> > filteredComicVineVolumeLists = new ConcurrentBag <List <ComicVineVolume> >();
                List <ComicVineVolume> filteredComicVineVolumeList = new List <ComicVineVolume>();

                foreach (var volumeList in comicVineVolumeLists)
                {
                    foreach (var volume in volumeList)
                    {
                        if (volume.name == volumeName)
                        {
                            filteredComicVineVolumeList.Add(volume);
                        }
                    }
                }

                filteredComicVineVolumeLists.Add(filteredComicVineVolumeList);
                comicVineVolumeLists = filteredComicVineVolumeLists;
            }

            List <ComicVineVolume> comicVineVolumeList = new List <ComicVineVolume>();

            foreach (List <ComicVineVolume> comicVineVolume in comicVineVolumeLists)
            {
                comicVineVolumeList.AddRange(comicVineVolume);
            }

            return(comicVineVolumeList);
        }