コード例 #1
0
        /// <summary>
        /// Convert the Image Mode for CortanaImageModel
        /// </summary>
        /// <param name="imageModel"></param>
        /// <returns></returns>
        private List<CortanaModelImage> ConvertImagesForCortanaModel(WikipediaImagesModel imageModel)
        {

            List<CortanaModelImage> lstCortanaImages = new List<CortanaModelImage>();

            var AllPages = imageModel.query.pages;

            foreach (KeyValuePair<string, pageid> item in AllPages)
            {
                var wikiImages = item.Value.images;
                foreach (var image in wikiImages)
                {
                    //Add the ImageURL in CortanaModel
                    lstCortanaImages.Add(new CortanaModelImage { ImageByte = null, ImageTitle = image.ImgURL });                    
                }
            }

            return lstCortanaImages;
        }
コード例 #2
0
        /// <summary>
        /// Access the WikiPedia API to Retrieve Image URL
        /// </summary>
        /// <param name="wikipediaImagesModel"></param>
        /// <param name="model"></param>

        private async Task<WikipediaImagesModel> GetImagesURL(WikipediaImagesModel model)
        {
         
            //Update the Parameter to get image INFO
            parameters["&prop="] = "imageinfo";
            parameters.Add("&iiprop=", "url");

            //Navigate throught images and get on API their imageInfo

            var AllPages = model.query.pages;

            foreach (KeyValuePair<string, pageid> item in AllPages)
            {
                var wikiImages = item.Value.images;
                foreach (var image in wikiImages)
                {
                    //get Image Name for API
                    parameters["&titles="] = image.title;                    
                    
                    //Update the Image URL for Cortana
                    image.ImgURL = await CallWikiAPIAndGetImageUrl(image.title, parameters);                    
                }
            }

            return model;
        }