/// <summary>
        /// Creates a parallel downloader for a search query
        /// </summary>
        /// <param name="imageSearch">The image search to download</param>
        /// <param name="maxDownloadThreads">The max number of threads to use when downloading</param>
        /// <param name="buildImageDownloader">Configures a sequential image downloader builder</param>
        /// <returns>A parallel downloader for the search query</returns>
        public static ParallelPhilomenaImageSearchDownloader CreateParallelDownloader(this IPhilomenaImageSearch imageSearch, int maxDownloadThreads, Func <SequentialPhilomenaImageDownloaderBuilder, SequentialPhilomenaImageDownloaderBuilder> buildImageDownloader)
        {
            SequentialPhilomenaImageDownloaderBuilder builder         = new SequentialPhilomenaImageDownloaderBuilder();
            SequentialPhilomenaImageDownloader        imageDownloader = buildImageDownloader(builder).Build();

            return(new ParallelPhilomenaImageSearchDownloader(imageSearch, imageDownloader, maxDownloadThreads));
        }
예제 #2
0
        /// <summary>
        /// Adds a conditional downloader
        /// </summary>
        /// <param name="shouldDownloadImage">A delegate that returns true if an image should be downloaded</param>
        /// <param name="buildInnerDownloader">Configures the inner downloader builder</param>
        public SequentialPhilomenaImageDownloaderBuilder WithConditionalDownloader(ShouldDownloadImageDelegate shouldDownloadImage, Func <SequentialPhilomenaImageDownloaderBuilder, SequentialPhilomenaImageDownloaderBuilder> buildInnerDownloader)
        {
            // Build the inner downloader
            SequentialPhilomenaImageDownloaderBuilder builder         = new SequentialPhilomenaImageDownloaderBuilder();
            SequentialPhilomenaImageDownloader        innerDownloader = buildInnerDownloader(builder).Build();

            // Wrap the downloader in a conditional downloader
            var conditionalDownloader = new ConditionalImageDownloader(shouldDownloadImage, innerDownloader);

            return(new
                   (
                       _downloaders.Append(conditionalDownloader)
                   ));
        }