Example #1
0
        public void DownloadImages(System.ComponentModel.BackgroundWorker worker,
        System.ComponentModel.DoWorkEventArgs e, String tags, bool r18, ImageSearchOptions imageSearchOptions, int currentPage, int maximumPagesToDownload)
        {
            List<Illustration> illusts = new List<Illustration>();
            int resultsFound = getNumberOfResultsFound(tags, r18, imageSearchOptions);   
            int totalPages = resultsFound / ImagesPerPage + (resultsFound % 20 == 0 ? 0 : 1);
            int imagesDownloaded = 0;

            if (resultsFound <= 0)
            {
                state.Status = "No results found!";
                worker.ReportProgress(0, state);
                return;
            }

            state.Status = resultsFound + " results found.";
            worker.ReportProgress(0, state);

            for (int x = 0; x <= maximumPagesToDownload && x <= totalPages; x++)
            {
                foreach (Illustration i in IllustrationsOnPage(tags, r18, imageSearchOptions, currentPage))
                {
                    state.Status = "Images downloaded: " + imagesDownloaded++ + "  Downloading image id: " + i.IllustrationID;
                    worker.ReportProgress(0, state);
                    i.DownloadImage();
                }
                currentPage++;
            }
        }
        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();
        }
        /// <summary>
        /// Delete Image signature from the document.
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Basic Usage] # DeleteImage : Delete Image signature from the document \n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_SIGNED_MULTI;
            string fileName = Path.GetFileName(filePath);
            // copy source file since Delete method works with same Document
            string outputFilePath = Path.Combine(Constants.OutputPath, "DeleteImage", fileName);

            Constants.CheckDir(outputFilePath);
            File.Copy(filePath, outputFilePath, true);
            using (Signature signature = new Signature(outputFilePath))
            {
                ImageSearchOptions options = new ImageSearchOptions();

                // search for image signatures in document
                List <ImageSignature> signatures = signature.Search <ImageSignature>(options);
                if (signatures.Count > 0)
                {
                    ImageSignature imageSignature = signatures[0];
                    bool           result         = signature.Delete(imageSignature);
                    if (result)
                    {
                        Console.WriteLine($"Image signature at location {imageSignature.Left}x{imageSignature.Top} and Size {imageSignature.Size}' was deleted from document ['{fileName}'].");
                    }
                    else
                    {
                        Helper.WriteError($"Signature was not deleted from the document! Signature at location {imageSignature.Left}x{imageSignature.Top} and Size {imageSignature.Size} was not found!");
                    }
                }
            }
        }
Example #4
0
        public PageBasedPhilomenaImageSearch(PhilomenaApi api, string query, ImageSearchOptions?options = null)
        {
            _logger = Logger.Factory.CreateLogger(GetType());

            _api     = api;
            _query   = query;
            _options = options ?? new ImageSearchOptions();
        }
        /// <summary>
        /// Delete multiple signatures from the document
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Basic Usage] # DeleteMultiple : Delete multiple signatures from the document \n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_SIGNED_MULTI;
            string fileName = Path.GetFileName(filePath);
            // copy source file since Delete method works with same Document
            string outputFilePath = Path.Combine(Constants.OutputPath, "DeleteMultiple", fileName);

            Constants.CheckDir(outputFilePath);
            File.Copy(filePath, outputFilePath, true);
            // processing signatures
            using (Signature signature = new Signature(outputFilePath))
            {
                // define few search options
                TextSearchOptions    textSearchOptions  = new TextSearchOptions();
                ImageSearchOptions   imageSearchOptions = new ImageSearchOptions();
                BarcodeSearchOptions barcodeOptions     = new BarcodeSearchOptions();
                QrCodeSearchOptions  qrCodeOptions      = new QrCodeSearchOptions();

                // add options to list
                List <SearchOptions> listOptions = new List <SearchOptions>();
                listOptions.Add(textSearchOptions);
                listOptions.Add(imageSearchOptions);
                listOptions.Add(barcodeOptions);
                listOptions.Add(qrCodeOptions);

                // search for signatures in document
                SearchResult result = signature.Search(listOptions);
                if (result.Signatures.Count > 0)
                {
                    Console.WriteLine("\nTrying to delete all signatures...");
                    DeleteResult deleteResult = signature.Delete(result.Signatures);
                    if (deleteResult.Succeeded.Count == result.Signatures.Count)
                    {
                        Console.WriteLine("\nAll signatures were successfully deleted!");
                    }
                    else
                    {
                        Console.WriteLine($"Successfully deleted signatures : {deleteResult.Succeeded.Count}");
                        Helper.WriteError($"Not deleted signatures : {deleteResult.Failed.Count}");
                    }
                    Console.WriteLine("\nList of deleted signatures:");
                    int number = 1;
                    foreach (BaseSignature temp in deleteResult.Succeeded)
                    {
                        Console.WriteLine($"Signature #{number++}: Type: {temp.SignatureType} Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
                    }
                }
                else
                {
                    Helper.WriteError("No one signature was found.");
                }
            }
        }
 public static ImageQueryConfig Get(string query, int count, ImageSearchOptions imageSearchOptions)
 {
     return(new ImageQueryConfig
     {
         Query = query,
         Count = count,
         SearchOptions = imageSearchOptions
     });
 }
 public static ImageQueryConfig Get(string query, int count,  ImageSearchOptions imageSearchOptions)
 {
     return new ImageQueryConfig
            {
                Query = query,
                Count = count,
                SearchOptions =  imageSearchOptions
            };
 }
Example #8
0
        /// <summary>
        /// Search document for Barcode signature with applying specific options
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Advanced Usage] # SearchForImageAdvanced : Search document for Barcode signature with applying specific options\n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_SIGNED_MULTI;
            string fileName = Path.GetFileName(filePath);

            using (Signature signature = new Signature(filePath))
            {
                // setup search options
                ImageSearchOptions searchOptions = new ImageSearchOptions()
                {
                    // enable grabbing image content feature
                    ReturnContent = true,
                    // set minimum size if needed
                    MinContentSize = 0,
                    // set maximum size if needed
                    MaxContentSize = 0,
                    // specify exact image type to be returned
                    ReturnContentType = FileType.JPEG,
                };

                // search document
                List <ImageSignature> signatures = signature.Search <ImageSignature>(searchOptions);
                Console.WriteLine($"\nSource document ['{fileName}'] contains following image signature(s).");
                // output signatures
                foreach (ImageSignature imageSignature in signatures)
                {
                    Console.Write($"Found Image signature at page {imageSignature.PageNumber} and size {imageSignature.Size}.");
                    Console.WriteLine($"Location at {imageSignature.Left}-{imageSignature.Top}. Size is {imageSignature.Width}x{imageSignature.Height}.");
                }

                //Save signature images
                string outputPath = System.IO.Path.Combine(Constants.OutputPath, "SearchForImageAdvanced");
                if (!Directory.Exists(outputPath))
                {
                    Directory.CreateDirectory(outputPath);
                }
                int i = 0;
                foreach (ImageSignature imageSignature in signatures)
                {
                    Console.Write($"Found Image signature at page {imageSignature.PageNumber} and size {imageSignature.Size}.");
                    Console.WriteLine($"Location at {imageSignature.Left}-{imageSignature.Top}. Size is {imageSignature.Width}x{imageSignature.Height}.");

                    string outputFilePath = System.IO.Path.Combine(outputPath, $"image{i}{imageSignature.Format.Extension}");

                    using (FileStream fs = new FileStream(outputFilePath, FileMode.Create))
                    {
                        fs.Write(imageSignature.Content, 0, imageSignature.Content.Length);
                    }
                    i++;
                }
            }
        }
        /// <summary>
        /// Update Image signature in the document.
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Advanced Usage] # UpdateImageAfterSearch : Update Image signature in the document\n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_SIGNED_MULTI;
            // copy source file since Update method works with same Document
            string fileName       = Path.GetFileName(filePath);
            string outputFilePath = Path.Combine(Constants.OutputPath, "UpdateImageAfterSearch", fileName);

            Constants.CheckDir(outputFilePath);
            File.Copy(filePath, outputFilePath, true);
            //
            using (Signature signature = new Signature(outputFilePath))
            {
                ImageSearchOptions options = new ImageSearchOptions();
                // search for image signatures in document
                List <ImageSignature> signatures = signature.Search <ImageSignature>(options);
                // adjust signature properties
                foreach (ImageSignature temp in signatures)
                {
                    // apply some condition to adjust signature properties
                    temp.Left = temp.Left + 100;
                    temp.Top  = temp.Top + 100;
                    if (temp.Size > 10000)
                    {
                        temp.IsSignature = false;
                    }
                }
                // update all found signatures
                UpdateResult updateResult = signature.Update(signatures.ConvertAll(p => (BaseSignature)p));
                if (updateResult.Succeeded.Count == signatures.Count)
                {
                    Console.WriteLine("\nAll signatures were successfully updated!");
                }
                else
                {
                    Console.WriteLine($"Successfully updated signatures : {updateResult.Succeeded.Count}");
                    Helper.WriteError($"Not updated signatures : {updateResult.Failed.Count}");
                }
                Console.WriteLine("List of updated signatures:");
                foreach (BaseSignature temp in updateResult.Succeeded)
                {
                    Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
                }
            }
        }
Example #10
0
        /// <summary>
        /// Delete Image signature from the document.
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Advanced Usage] # DeleteImageAfterSearch : Delete Image signature from the document\n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_SIGNED_MULTI;
            // copy source file since Delete method works with same Document
            string fileName       = Path.GetFileName(filePath);
            string outputFilePath = Path.Combine(Constants.OutputPath, "DeleteImageAfterSearch", fileName);

            Constants.CheckDir(outputFilePath);
            File.Copy(filePath, outputFilePath, true);
            // initialize Signature instance
            using (Signature signature = new Signature(outputFilePath))
            {
                ImageSearchOptions options = new ImageSearchOptions();

                List <ImageSignature> signatures         = signature.Search <ImageSignature>(options);
                List <BaseSignature>  signaturesToDelete = new List <BaseSignature>();
                // collect signatures to delete
                foreach (ImageSignature temp in signatures)
                {
                    if (temp.Size > 10000)
                    {
                        signaturesToDelete.Add(temp);
                    }
                }
                // delete signatures
                DeleteResult deleteResult = signature.Delete(signaturesToDelete);
                if (deleteResult.Succeeded.Count == signaturesToDelete.Count)
                {
                    Console.WriteLine("All signatures were successfully deleted!");
                }
                else
                {
                    Console.WriteLine($"Successfully deleted signatures : {deleteResult.Succeeded.Count}");
                    Helper.WriteError($"Not deleted signatures : {deleteResult.Failed.Count}");
                }
                Console.WriteLine("List of deleted signatures:");
                foreach (BaseSignature temp in deleteResult.Succeeded)
                {
                    Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
                }
            }
        }
Example #11
0
        /// <summary>
        /// Update Image signature from the document.
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Basic Usage] # UpdateImage : Update Image signature from the document \n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_SIGNED_MULTI;
            // copy source file since Update method works with same Document
            string fileName       = Path.GetFileName(filePath);
            string outputFilePath = Path.Combine(Constants.OutputPath, "UpdateImage", fileName);

            Constants.CheckDir(outputFilePath);
            File.Copy(filePath, outputFilePath, true);
            // initialize Signature instance
            using (Signature signature = new Signature(outputFilePath))
            {
                ImageSearchOptions options = new ImageSearchOptions();

                // search for image signatures in document
                List <ImageSignature> signatures = signature.Search <ImageSignature>(options);
                if (signatures.Count > 0)
                {
                    ImageSignature imageSignature = signatures[0];
                    // change position
                    imageSignature.Left = 200;
                    imageSignature.Top  = 250;
                    // change size. Please note not all documents support changing signature size
                    imageSignature.Width  = 200;
                    imageSignature.Height = 200;

                    bool result = signature.Update(imageSignature);
                    if (result)
                    {
                        Console.WriteLine($"Image signature at location {imageSignature.Left}x{imageSignature.Top} and Size {imageSignature.Size}' was updated in the document ['{fileName}'].");
                    }
                    else
                    {
                        Helper.WriteError($"Signature was not updated in the document! Signature at location {imageSignature.Left}x{imageSignature.Top} and Size {imageSignature.Size} was not found!");
                    }
                }
            }
        }
Example #12
0
 public IPhilomenaImageSearch GetImageSearch(string query, ImageSearchOptions searchOptions)
 {
     return(new PageBasedPhilomenaImageSearch(_api, query, searchOptions));
 }
        internal static void SetPluginProperties(CORE.FileImporter fileImporter, IMeedioItem properties)
        {
            if (properties["ImporterSettings"] != null)
            {
                CustomProperty.SetProperties(properties, "ImporterSettings");
            }

            if ((properties["RootFolders2"] != null) && !(properties["RootFolders2"] is DBNull))
            {
                fileImporter.RootFolders = (string[]) properties["RootFolders2"];
                fileImporter.LogMessages.Enqueue(
                    new LogMessage("debug", "RootFolders: " + String.Join(Environment.NewLine, fileImporter.RootFolders)));
            }

            if ((properties["RootFolders"] != null) && !(properties["RootFolders"] is DBNull))
            {
                if (fileImporter.RootFolders == null)
                {
                    fileImporter.RootFolders = (string[]) properties["RootFolders"];
                    for (int rootFolderPos = 0; rootFolderPos < fileImporter.RootFolders.Length; rootFolderPos++)
                    {
                        fileImporter.RootFolders[rootFolderPos] = fileImporter.RootFolders[rootFolderPos].ToLowerInvariant();
                    }

                    fileImporter.LogMessages.Enqueue(
                        new LogMessage(
                            "debug", "RootFolders: " + String.Join(Environment.NewLine, fileImporter.RootFolders)));
                }
                else
                {
                    List<string> rootFoldersList = new List<string>(fileImporter.RootFolders);
                    rootFoldersList.AddRange((string[]) properties["RootFolders"]);
                    fileImporter.RootFolders =
                        new string[rootFoldersList.Select(rf => rf.ToLowerInvariant()).Distinct().Count()];
                    rootFoldersList.Select(rf => rf.ToLowerInvariant()).Distinct().ToArray().CopyTo(
                        fileImporter.RootFolders, 0);
                    fileImporter.LogMessages.Enqueue(
                        new LogMessage(
                            "debug", "RootFolders: " + String.Join(Environment.NewLine, fileImporter.RootFolders)));
                }
            }

            fileImporter.TagMasks = new List<TagMask>();
            if ((properties["TagMasks"] != null) && !(properties["TagMasks"] is DBNull))
            {
                fileImporter.TagMasksStrings = (string[]) properties["TagMasks"];
                fileImporter.LogMessages.Enqueue(new LogMessage("debug", "TagMasks:"));
                foreach (string tagMask in fileImporter.TagMasksStrings)
                {
                    fileImporter.TagMasks.Add(new TagMask(tagMask ?? String.Empty));
                    fileImporter.LogMessages.Enqueue(
                        new LogMessage("debug", "  Mask:  " + fileImporter.TagMasks[fileImporter.TagMasks.Count - 1].Mask));
                    fileImporter.LogMessages.Enqueue(
                        new LogMessage("debug", "  RegEx: " + fileImporter.TagMasks[fileImporter.TagMasks.Count - 1].RegExp));
                }
            }

            if ((properties["ChainFiles"] != null) && !(properties["ChainFiles"] is DBNull))
            {
                fileImporter.ChainFiles = (bool) properties["ChainFiles"];
            }

            if ((properties["ChainingOptions"] != null)
                && !(properties["ChainingOptions"] is DBNull))
            {
                fileImporter.ChainingOption = (ChainOption) Convert.ToInt32((string) properties["ChainingOptions"]);
            }

            if ((properties["ChainingTags"] != null)
                && !(properties["ChainingTags"] is DBNull))
            {
                fileImporter.TagsToChainBy = (string[]) properties["ChainingTags"];
            }

            if ((properties["DeleteNonExistentFiles"] != null)
                && !(properties["DeleteNonExistentFiles"] is DBNull))
            {
                fileImporter.DeleteNonExistentFiles = (bool) properties["DeleteNonExistentFiles"];
            }

            if ((properties["AlwaysUpdate"] != null)
                && !(properties["AlwaysUpdate"] is DBNull))
            {
                fileImporter.AlwaysUpdate = (bool) properties["AlwaysUpdate"];
            }

            fileImporter.TagValuesReplacementRules = new ReplacementRules(properties["TagValuesReplacement"] as string[]);

            if ((properties["IncludeFileMasks"] != null)
                && !(properties["IncludeFileMasks"] is DBNull))
            {
                fileImporter.IncludeFileMasks = (string) properties["IncludeFileMasks"];
            }

            if (String.IsNullOrEmpty(fileImporter.IncludeFileMasks))
            {
                fileImporter.IncludeFileMasks = "*.*";
            }

            if ((properties["ExcludeFileMasks"] != null)
                && !(properties["ExcludeFileMasks"] is DBNull))
            {
                fileImporter.ExcludeFileMasks = (string) properties["ExcludeFileMasks"];
            }

            if ((properties["IncludeHiddenFiles"] != null)
                && !(properties["IncludeHiddenFiles"] is DBNull))
            {
                fileImporter.IncludeHiddenFiles = (bool) properties["IncludeHiddenFiles"];
            }

            if ((properties["ExcludeUnmatchedFiles"] != null)
                && !(properties["ExcludeUnmatchedFiles"] is DBNull))
            {
                fileImporter.ExcludeUnmatchedFiles = (bool) properties["ExcludeUnmatchedFiles"];
            }

            if ((properties["MinFileSize"] != null)
                && !(properties["MinFileSize"] is DBNull))
            {
                fileImporter.MinFileSize = (int) properties["MinFileSize"];
            }

            fileImporter.ImageLinker.ImageSearches.Clear();

            var iso = new ImageSearchOptions();

            bool addThisImageSearch = false;

            if ((properties["ImageFileMasks"] != null)
                && !(properties["ImageFileMasks"] is DBNull))
            {
                var imageFileMasks
                    = (string) properties
                                   ["ImageFileMasks"];

                if (imageFileMasks.Contains(':'))
                {
                    iso.ImageFolderSearchPattern = imageFileMasks.Split(new[] {':'})[0];
                    iso.FileFolderSearchPattern = imageFileMasks.Split(new[] {':'})[1];
                }
                else
                {
                    iso.ImageFolderSearchPattern = imageFileMasks;
                    iso.FileFolderSearchPattern = imageFileMasks;
                }
            }

            if ((properties["ImageFolder"] != null) && !(properties["ImageFolder"] is DBNull))
            {
                iso.ImageFolder = (string) properties["ImageFolder"];
            }

            if ((properties["FileFolderImage"] != null) && !(properties["FileFolderImage"] is DBNull))
            {
                iso.SearchFileFolderOptions = (string) properties["FileFolderImage"];
                fileImporter.ImportImages = !String.IsNullOrEmpty(iso.ImageFolder) ||
                                            iso.SearchFileFolderOptions != "Never".Translate();
                addThisImageSearch = !String.IsNullOrEmpty(iso.ImageFolder) ||
                                     iso.SearchFileFolderOptions != "Never".Translate();
            }

            if ((properties["ImageCount"] != null) && !(properties["ImageCount"] is DBNull))
            {
                iso.MaxImages = (int) properties["ImageCount"];
            }

            if ((properties["ImageTagName"] != null) && !(properties["ImageTagName"] is DBNull))
            {
                iso.ImageTagName = (string) properties["ImageTagName"];
            }

            if ((properties["AlwaysUpdateImages"] != null) && !(properties["AlwaysUpdateImages"] is DBNull))
            {
                fileImporter.alwaysUpdateImages = (bool) properties["AlwaysUpdateImages"];
            }

            if ((properties["SaveInImageBaseTag"] != null) && !(properties["SaveInImageBaseTag"] is DBNull))
            {
                iso.SaveInImageBaseTag = (bool) properties["SaveInImageBaseTag"];
            }

            if (addThisImageSearch)
            {
                fileImporter.ImageLinker.ImageSearches.Add(iso);
            }

            bool doNextImageSearch = false;
            if ((properties["ImageSearchActive2"] != null) && !(properties["ImageSearchActive2"] is DBNull))
            {
                doNextImageSearch = (bool) properties["ImageSearchActive2"];
            }

            if (doNextImageSearch)
            {
                iso = new ImageSearchOptions();
                if ((properties["ImageFileMasks2"] != null) && !(properties["ImageFileMasks2"] is DBNull))
                {
                    string imageFileMasks = (string) properties["ImageFileMasks2"];
                    if (imageFileMasks.Contains(':'))
                    {
                        iso.ImageFolderSearchPattern = imageFileMasks.Split(new[] {':'})[0];
                        iso.FileFolderSearchPattern = imageFileMasks.Split(new[] {':'})[1];
                    }
                    else
                    {
                        iso.ImageFolderSearchPattern = imageFileMasks;
                        iso.FileFolderSearchPattern = imageFileMasks;
                    }
                }

                if ((properties["ImageFolder2"] != null) && !(properties["ImageFolder2"] is DBNull))
                {
                    iso.ImageFolder = (string) properties["ImageFolder2"];
                }

                if ((properties["FileFolderImage2"] != null) && !(properties["FileFolderImage2"] is DBNull))
                {
                    iso.SearchFileFolderOptions = (string) properties["FileFolderImage2"];
                    addThisImageSearch = !String.IsNullOrEmpty(iso.ImageFolder) ||
                                         iso.SearchFileFolderOptions != "Never".Translate();
                    fileImporter.ImportImages = fileImporter.ImportImages || addThisImageSearch;
                }

                if ((properties["ImageCount2"] != null) && !(properties["ImageCount2"] is DBNull))
                {
                    iso.MaxImages = (int) properties["ImageCount2"];
                }

                if ((properties["ImageTagName2"] != null) && !(properties["ImageTagName2"] is DBNull))
                {
                    iso.ImageTagName = (string) properties["ImageTagName2"];
                }

                if ((properties["SaveInImageBaseTag2"] != null) && !(properties["SaveInImageBaseTag2"] is DBNull))
                {
                    iso.SaveInImageBaseTag = (bool) properties["SaveInImageBaseTag2"];
                }

                if (addThisImageSearch)
                {
                    fileImporter.ImageLinker.ImageSearches.Add(iso);
                }
            }

            if ((properties["ImageSearchActive3"] != null) && !(properties["ImageSearchActive3"] is DBNull))
            {
                doNextImageSearch = (bool) properties["ImageSearchActive3"];
            }

            if (doNextImageSearch)
            {
                iso = new ImageSearchOptions();
                if ((properties["ImageFileMasks3"] != null) && !(properties["ImageFileMasks3"] is DBNull))
                {
                    string imageFileMasks = (string) properties["ImageFileMasks3"];
                    if (imageFileMasks.Contains(':'))
                    {
                        iso.ImageFolderSearchPattern = imageFileMasks.Split(new[] {':'})[0];
                        iso.FileFolderSearchPattern = imageFileMasks.Split(new[] {':'})[1];
                    }
                    else
                    {
                        iso.ImageFolderSearchPattern = imageFileMasks;
                        iso.FileFolderSearchPattern = imageFileMasks;
                    }
                }

                if ((properties["ImageFolder3"] != null) && !(properties["ImageFolder3"] is DBNull))
                {
                    iso.ImageFolder = (string) properties["ImageFolder3"];
                }

                if ((properties["FileFolderImage3"] != null) && !(properties["FileFolderImage3"] is DBNull))
                {
                    iso.SearchFileFolderOptions = (string) properties["FileFolderImage3"];
                    addThisImageSearch = fileImporter.ImportImages || !String.IsNullOrEmpty(iso.ImageFolder) ||
                                         iso.SearchFileFolderOptions != "Never".Translate();
                    fileImporter.ImportImages = fileImporter.ImportImages || addThisImageSearch;
                }

                if ((properties["ImageCount3"] != null) && !(properties["ImageCount3"] is DBNull))
                {
                    iso.MaxImages = (int) properties["ImageCount3"];
                }

                if ((properties["ImageTagName3"] != null) && !(properties["ImageTagName3"] is DBNull))
                {
                    iso.ImageTagName = (string) properties["ImageTagName3"];
                }

                if ((properties["SaveInImageBaseTag3"] != null) && !(properties["SaveInImageBaseTag3"] is DBNull))
                {
                    iso.SaveInImageBaseTag = (bool) properties["SaveInImageBaseTag3"];
                }

                if (addThisImageSearch)
                {
                    fileImporter.ImageLinker.ImageSearches.Add(iso);
                }
            }

            if ((properties["ImageSearchActive4"] != null) && !(properties["ImageSearchActive4"] is DBNull))
            {
                doNextImageSearch = (bool) properties["ImageSearchActive4"];
            }

            if (doNextImageSearch)
            {
                iso = new ImageSearchOptions();
                if ((properties["ImageFileMasks4"] != null) && !(properties["ImageFileMasks4"] is DBNull))
                {
                    string imageFileMasks = (string) properties["ImageFileMasks4"];
                    if (imageFileMasks.Contains(':'))
                    {
                        iso.ImageFolderSearchPattern = imageFileMasks.Split(new[] {':'})[0];
                        iso.FileFolderSearchPattern = imageFileMasks.Split(new[] {':'})[1];
                    }
                    else
                    {
                        iso.ImageFolderSearchPattern = imageFileMasks;
                        iso.FileFolderSearchPattern = imageFileMasks;
                    }
                }

                if ((properties["ImageFolder4"] != null) && !(properties["ImageFolder4"] is DBNull))
                {
                    iso.ImageFolder = (string) properties["ImageFolder4"];
                }

                if ((properties["FileFolderImage4"] != null) && !(properties["FileFolderImage4"] is DBNull))
                {
                    iso.SearchFileFolderOptions = (string) properties["FileFolderImage4"];
                    addThisImageSearch = fileImporter.ImportImages || !String.IsNullOrEmpty(iso.ImageFolder) ||
                                         iso.SearchFileFolderOptions != "Never".Translate();
                    fileImporter.ImportImages = fileImporter.ImportImages || addThisImageSearch;
                }

                if ((properties["ImageCount4"] != null) && !(properties["ImageCount4"] is DBNull))
                {
                    iso.MaxImages = (int) properties["ImageCount4"];
                }

                if ((properties["ImageTagName4"] != null) && !(properties["ImageTagName4"] is DBNull))
                {
                    iso.ImageTagName = (string) properties["ImageTagName4"];
                }

                if ((properties["SaveInImageBaseTag4"] != null) && !(properties["SaveInImageBaseTag4"] is DBNull))
                {
                    iso.SaveInImageBaseTag = (bool) properties["SaveInImageBaseTag4"];
                }

                if (addThisImageSearch)
                {
                    fileImporter.ImageLinker.ImageSearches.Add(iso);
                }
            }

            if ((properties["ImageSearchActive5"] != null) && !(properties["ImageSearchActive5"] is DBNull))
            {
                doNextImageSearch = (bool) properties["ImageSearchActive5"];
            }

            if (doNextImageSearch)
            {
                iso = new ImageSearchOptions();
                if ((properties["ImageFileMasks5"] != null) && !(properties["ImageFileMasks5"] is DBNull))
                {
                    string imageFileMasks = (string) properties["ImageFileMasks5"];
                    if (imageFileMasks.Contains(':'))
                    {
                        iso.ImageFolderSearchPattern = imageFileMasks.Split(new[] {':'})[0];
                        iso.FileFolderSearchPattern = imageFileMasks.Split(new[] {':'})[1];
                    }
                    else
                    {
                        iso.ImageFolderSearchPattern = imageFileMasks;
                        iso.FileFolderSearchPattern = imageFileMasks;
                    }
                }

                if ((properties["ImageFolder5"] != null) && !(properties["ImageFolder5"] is DBNull))
                {
                    iso.ImageFolder = (string) properties["ImageFolder5"];
                }

                if ((properties["FileFolderImage5"] != null) && !(properties["FileFolderImage5"] is DBNull))
                {
                    iso.SearchFileFolderOptions = (string) properties["FileFolderImage5"];
                    addThisImageSearch = fileImporter.ImportImages || !String.IsNullOrEmpty(iso.ImageFolder) ||
                                         iso.SearchFileFolderOptions != "Never".Translate();
                    fileImporter.ImportImages = fileImporter.ImportImages || addThisImageSearch;
                }

                if ((properties["ImageCount5"] != null) && !(properties["ImageCount5"] is DBNull))
                {
                    iso.MaxImages = (int) properties["ImageCount5"];
                }

                if ((properties["ImageTagName5"] != null) && !(properties["ImageTagName5"] is DBNull))
                {
                    iso.ImageTagName = (string) properties["ImageTagName5"];
                }

                if ((properties["SaveInImageBaseTag5"] != null) && !(properties["SaveInImageBaseTag5"] is DBNull))
                {
                    iso.SaveInImageBaseTag = (bool) properties["SaveInImageBaseTag5"];
                }

                if (addThisImageSearch)
                {
                    fileImporter.ImageLinker.ImageSearches.Add(iso);
                }
            }

            /*
                if (properties["FollowShortcuts"] != null)
                {
                    FollowShortcuts = (Boolean)properties["FollowShortcuts"];
                }
                */
            if ((properties["FileSizeTagName"] != null) && !(properties["FileSizeTagName"] is DBNull))
            {
                fileImporter.FileSizeTagName = (string) properties["FileSizeTagName"];
                fileImporter.FileSize = fileImporter.FileSizeTagName.Length > 0;
            }

            if ((properties["CreationDateTagName"] != null) && !(properties["CreationDateTagName"] is DBNull))
            {
                fileImporter.CreationDateTagName = (string) properties["CreationDateTagName"];
                fileImporter.CreationDate = fileImporter.CreationDateTagName.Length > 0;
            }

            if ((properties["LastModificationDateTagName"] != null) &&
                !(properties["LastModificationDateTagName"] is DBNull))
            {
                fileImporter.LastModificationDateTagName = (string) properties["LastModificationDateTagName"];
                fileImporter.LastModificationDate = fileImporter.LastModificationDateTagName.Length > 0;
            }

            if ((properties["LastAccessDateTagName"] != null) && !(properties["LastAccessDateTagName"] is DBNull))
            {
                fileImporter.LastAccessDateTagName = (string) properties["LastAccessDateTagName"];
                fileImporter.LastAccessDate = fileImporter.LastAccessDateTagName.Length > 0;
            }

            if ((properties["SerialNumberTagName"] != null) && !(properties["SerialNumberTagName"] is DBNull))
            {
                fileImporter.SerialNumberTagName = (string) properties["SerialNumberTagName"];
                fileImporter.SerialNumber = fileImporter.SerialNumberTagName.Length > 0;
            }

            /*
                if (properties["DiscIDTagName"] != null)
                {
                    DiscIDTagName = (string)properties["DiscIDTagName"];
                }
                */
            if ((properties["VolumeNameTagName"] != null) && !(properties["VolumeNameTagName"] is DBNull))
            {
                fileImporter.VolumeNameTagName = (string) properties["VolumeNameTagName"];
                fileImporter.VolumeName = fileImporter.VolumeNameTagName.Length > 0;
            }

            if ((properties["SingleFilename"] != null) && !(properties["SingleFilename"] is DBNull))
            {
                fileImporter.SingleFilename = (string) properties["SingleFilename"];
            }

            if (!String.IsNullOrEmpty(fileImporter.SingleFilename))
            {
                fileImporter.RootFolders = new[] {Path.GetDirectoryName(fileImporter.SingleFilename)};
                fileImporter.IncludeFileMasks = String.Empty;
                fileImporter.IncludeFileMasks = Path.GetFileName(fileImporter.SingleFilename);
            }

            if ((properties["ImportFromADS"] != null) && !(properties["ImportFromADS"] is DBNull))
            {
                fileImporter.ImportFromAlternateDataStream = (bool) properties["ImportFromADS"];
            }

            if ((properties["ExportToADS"] != null) && !(properties["ExportToADS"] is DBNull))
            {
                fileImporter.ExportToAlternateDataStream = (bool) properties["ExportToADS"];
            }

            if ((properties["DebugLevel"] != null) && !(properties["DebugLevel"] is DBNull))
            {
                fileImporter.DebugLevel = (string) properties["DebugLevel"];
            }
        }
        /// <summary>
        /// Following example shows how to process Image Signature over all signature life-cycle.
        /// First document is being signed with Image Signature, then verified for it, searched for same, updating and finally deleting this signature.
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Advanced Usage] # ProcessingImageSignatureOverCRUD : Process Image Signature over all signature life-cycle\n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_WORDPROCESSING;
            string fileName = Path.GetFileName(filePath);

            string        outputFilePath = Path.Combine(Constants.OutputPath, "ProcessingImageSignatureOverCRUD", fileName);
            List <string> signatureIds   = new List <string>();

            // -----------------------------------------------------------------------------------------------------------------------------
            // STEP 1. Sign document with Image Signature
            // -----------------------------------------------------------------------------------------------------------------------------
            using (Signature signature = new Signature(filePath))
            {
                ImageSignOptions signOptions = new ImageSignOptions(Constants.ImageStamp)
                {
                    VerticalAlignment   = VerticalAlignment.Top,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Width  = 100,
                    Height = 40,
                    Margin = new Padding(20)
                };
                // sign document to file
                SignResult signResult = signature.Sign(outputFilePath, signOptions);
                Console.WriteLine("\nDocument {filePath} was signed with following signatures:");
                foreach (BaseSignature temp in signResult.Succeeded)
                {
                    // collect newly created signature' Id
                    signatureIds.Add(temp.SignatureId);
                    Console.WriteLine($"Signature : {temp.SignatureType} Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
                }
            }
            // -----------------------------------------------------------------------------------------------------------------------------
            // STEP 2. Search document for Image Signature
            // -----------------------------------------------------------------------------------------------------------------------------
            using (Signature signature = new Signature(outputFilePath))
            {
                ImageSearchOptions searchOptions = new ImageSearchOptions()
                {
                    // specify special pages to search on
                    AllPages = true
                };
                // search for image signatures in document
                List <ImageSignature> signatures = signature.Search <ImageSignature>(searchOptions);
                Console.WriteLine("\nSource document contains following Image signature(s).");
                // enumerate all signature for output
                foreach (ImageSignature imageSignature in signatures)
                {
                    if (imageSignature != null)
                    {
                        Console.WriteLine($"Found Image signature at page {imageSignature.PageNumber} and Image Size '{imageSignature.Size}'.");
                        Console.WriteLine($"Location at {imageSignature.Left}-{imageSignature.Top}. Size is {imageSignature.Width}x{imageSignature.Height}.");
                    }
                }
                // -----------------------------------------------------------------------------------------------------------------------------
                // STEP 3. Update document Image Signature after searching it
                // -----------------------------------------------------------------------------------------------------------------------------
                foreach (ImageSignature imageSignature in signatures)
                {
                    // change position
                    imageSignature.Left = imageSignature.Left + 100;
                    imageSignature.Top  = imageSignature.Top + 100;
                    // change size. Please note not all documents support changing signature size
                    imageSignature.Width  = 200;
                    imageSignature.Height = 50;
                }
                List <BaseSignature> signaturesToUpdate = signatures.ConvertAll(p => (BaseSignature)p);
                UpdateResult         updateResult;
                updateResult = signature.Update(signaturesToUpdate);
                if (updateResult.Succeeded.Count == signatures.Count)
                {
                    Console.WriteLine("\nAll signatures were successfully updated!");
                }
                else
                {
                    Console.WriteLine($"Successfully updated signatures : {updateResult.Succeeded.Count}");
                    Helper.WriteError($"Not updated signatures : {updateResult.Failed.Count}");
                }
                Console.WriteLine("List of updated signatures:");
                foreach (BaseSignature temp in updateResult.Succeeded)
                {
                    Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
                }
                // -----------------------------------------------------------------------------------------------------------------------------
                // STEP 4. Update document Image Signature on saved SignatureId
                // create list of Image Signature by known SignatureId
                // -----------------------------------------------------------------------------------------------------------------------------
                signaturesToUpdate.Clear();
                foreach (var item in signatureIds)
                {
                    ImageSignature temp = new ImageSignature(item)
                    {
                        Width  = 150,
                        Height = 30,
                        Left   = 100,
                        Top    = 100
                    };
                    signaturesToUpdate.Add(temp);
                }
                // update all found signatures
                updateResult = signature.Update(signaturesToUpdate);
                if (updateResult.Succeeded.Count == signatures.Count)
                {
                    Console.WriteLine("\nAll signatures were successfully updated!");
                }
                else
                {
                    Console.WriteLine($"Successfully updated signatures : {updateResult.Succeeded.Count}");
                    Helper.WriteError($"Not updated signatures : {updateResult.Failed.Count}");
                }
                Console.WriteLine("List of updated signatures:");
                foreach (BaseSignature temp in updateResult.Succeeded)
                {
                    Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
                }
                // -----------------------------------------------------------------------------------------------------------------------------
                // STEP 5. Delete document Image Signature by id
                // create list of Image Signature by known SignatureId
                signaturesToUpdate.Clear();
                foreach (var item in signatureIds)
                {
                    ImageSignature temp = new ImageSignature(item);
                    signaturesToUpdate.Add(temp);
                }
                // delete all signatures
                DeleteResult deleteResult = signature.Delete(signaturesToUpdate);
                if (deleteResult.Succeeded.Count == signaturesToUpdate.Count)
                {
                    Console.WriteLine("\nAll signatures were successfully deleted!");
                }
                else
                {
                    Console.WriteLine($"Successfully deleted signatures : {deleteResult.Succeeded.Count}");
                    Helper.WriteError($"Not deleted signatures : {deleteResult.Failed.Count}");
                }
                Console.WriteLine("List of deleted signatures:");
                foreach (BaseSignature temp in deleteResult.Succeeded)
                {
                    Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
                }
            }
        }
Example #15
0
        public HtmlAgilityPack.HtmlDocument Search(String tags, bool r18, ImageSearchOptions imageSearchOptions, int currentPage)
        {
            string result = "";
            string url = "search.php?" + "word=" + tags + "&order=date_d" + (r18 ? "&r18=1" : "");

            if (imageSearchOptions == ImageSearchOptions.ILLUSTRATIONS)
            {
                result = client.DownloadString(url + "&type=illust&p=" + currentPage);
            }
            else if (imageSearchOptions == ImageSearchOptions.ALL)
            {
                result = client.DownloadString(url + "&type=0&p=" + currentPage);
            }
            else if (imageSearchOptions == ImageSearchOptions.MANGA)
            {
                result = client.DownloadString(url + "&type=manga&p=" + currentPage);
            }

            HtmlAgilityPack.HtmlDocument page = new HtmlAgilityPack.HtmlDocument();
            page.LoadHtml(result);

            return page;
        }
Example #16
0
        //Returns a list of illustrations on a given page
        public List<Illustration> IllustrationsOnPage(String tags, bool r18, ImageSearchOptions imageSearchOptions, int currentPage)
        {
            HtmlAgilityPack.HtmlDocument HTMLParser = Search(tags, r18, imageSearchOptions, currentPage);

            String s = "http://spapi.pixiv.net/iphone/illust.php?illust_id=";

            var imageAttributes = GetImageAttributes(HTMLParser).ToArray();
            List<Illustration> illustrations = new List<Illustration>();

            foreach (ImageAttributes i in imageAttributes)
            {
                illustrations.Add(new Illustration(client.DownloadString(s + i.IllustrationID + "&" + client.getPHPSESSID())));
            }

            return illustrations;
        }
Example #17
0
        public int getNumberOfResultsFound(String tags, bool r18, ImageSearchOptions imageSearchOptions)
        {
            HtmlAgilityPack.HtmlDocument HTMLParser = Search(tags, r18, imageSearchOptions, 1);

            var metaTags = HTMLParser.DocumentNode.SelectNodes("//span");

            foreach (HtmlNode h in metaTags)
            {
                if (h.InnerText.Contains("result") && !h.InnerText.Contains(" "))
                {
                    return Convert.ToInt32(h.InnerText.Replace("results", ""));
                }
            }
            return -1;
        }