コード例 #1
0
        static void Main(string[] args)
        {
            // This is the query - or you could get it from args.
            string query = "human form abstract";

            var count = 100;
            var debug = true;

            List <ImageQueryResult> imageList = new List <ImageQueryResult>();

            if (GlobalConfig._global_useSearchApiSource)
            {
                if (debug)
                {
                    Console.WriteLine("Getting ImageQueryResults from BING SEARCH API");
                }

                // get the image list from actual source
                var grabber = new ImageUrlGrabber();
                imageList = grabber.GetImageUrlList(
                    ImageQueryConfig.Get(
                        query,
                        count,
                        ImageSearchOptions.Build(QueryAdultValues.OFF, imageFilterColor: ImageFilterColorValues.MONOCHROME, imageFilterAspectValue: ImageFilterAspectValues.SQUARE)),
                    debug);

                // serialize it for temporary storage for any usage
                // mostly to prevent extra queries when debugging.
                ImageResultXmlProcessor.Serialize(imageList);
            }
            else
            {
                Console.WriteLine("Getting ImageQueryResults from XML");
                imageList = ImageResultXmlProcessor.Desirialize();
            }

            if (GlobalConfig._download_run_download)
            {
                Console.WriteLine("Redownloading images");
                // Try and download images
                var imageDownloader = new ImageDownloader();

                imageDownloader.DownloadImages(imageList, DownloadOptions.Build(true, "thumb_"), debug);
            }
            else
            {
                Console.WriteLine("Using Predownloaded images");
                // do not download image and run the composer from what is
                // already in the folder
            }

            var imageComposer = new ImageComposer();
            var composedImage = imageComposer.CombineImagesInFolder(GlobalConfig._download_imageDownloadPath, debug);

            composedImage.Save(GlobalConfig.ComposedImagePath);
            composedImage.Dispose();

            Console.WriteLine("DONE!");
            Console.ReadLine();
        }
コード例 #2
0
        public List <ImageQueryResult> GetImageUrlList(ImageQueryConfig config, bool isDebug = false)
        {
            //set the debug state
            _debugFlag = isDebug;

            _debug_OpenFileDebug();

            // create the bing search container
            var bingContainer = new BingSearchContainer(new Uri(GlobalConfig._search_baseUrl));

            bingContainer.Credentials = new NetworkCredential(GlobalConfig._search_accountKey, GlobalConfig._search_accountKey);

            var executionFlowObject = QueryFlowConfig.Build(config.Count);

            var total_requested = 0;

            var images = new List <ImageQueryResult>();

            for (int i = 0; i < executionFlowObject.NumberOfFullExecutions + 1; i++)
            {
                // crate a new query for each request as for now I dont know how to actually
                // modify query parameters
                var query = bingContainer.Image(config.Query, null, null, config.SearchOptions.Adult, null, null, config.SearchOptions.ImageFilter);

                // i will be checked to determine $top. if its reqced the total number of executions
                // we will set $top to the remainder
                if (i == executionFlowObject.NumberOfFullExecutions)
                {
                    query = query.AddQueryOption("$top", executionFlowObject.PartialExecutionCount);
                }
                else
                {
                    query = query.AddQueryOption("$top", GlobalConfig._search_maxQueryCount + (i * GlobalConfig._search_maxQueryCount));
                }

                query = query.AddQueryOption("$skip", total_requested);

                _debug_PrintConsoleQuery(query);

                var results = query.Execute();

                // if we got nothing in this query we will just
                // return what we have so far
                if (results == null)
                {
                    return(images);
                }

                var listResults = results.ToList();

                _debug_WriteImageResults(listResults, total_requested);

                total_requested += listResults.Count();

                images.AddRange(listResults.Select(ImageResultMappings.MapImageQueryResultFromImageResult));
            }

            _debug_CloseFileDebug();

            return(images);
        }