Пример #1
0
        public FolderWatcherManager(WebLibraryDetail _library)
        {
            web_library_detail = new TypedWeakReference <WebLibraryDetail>(_library);

            // Load any pre-existing watched filenames
            bool file_exists;

            // Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (filenames_processed_lock)
            {
                // l1_clk.LockPerfTimerStop();
                file_exists = File.Exists(Filename_Store);
            }
            if (file_exists)
            {
                Logging.Info("Loading memory of files that we watched previously.");

                // Utilities.LockPerfTimer l2_clk = Utilities.LockPerfChecker.Start();
                lock (filenames_processed_lock)
                {
                    // l2_clk.LockPerfTimerStop();
                    foreach (string filename in File.ReadAllLines(Filename_Store))
                    {
                        filenames_processed.Add(filename);
                    }
                }
            }

            if (ConfigurationManager.IsEnabled(nameof(FolderWatcher)))
            {
                managed_thread_index = Utilities.Maintainable.MaintainableManager.Instance.RegisterHeldOffTask(TaskDaemonEntryPoint, 30 * 1000, extra_descr: $".Lib({LibraryRef})");
            }
        }
        /// <summary>
        /// Removes the entry.
        /// </summary>
        /// <param name="target">The target object.</param>
        public void Remove(DependencyObject target)
        {
            TypedWeakReference <DependencyObject> singleOrDefault =
                _inner.Keys.SingleOrDefault(x => ReferenceEquals(x.Target, target));

            if (singleOrDefault != null)
            {
                if (_inner[singleOrDefault].IsAlive)
                {
                    _inner[singleOrDefault].Target.Dispose();
                }
                _inner.Remove(singleOrDefault);
            }
        }
        internal PDFDocument(WebLibraryDetail web_library_detail, DictionaryBasedObject dictionary, PDFAnnotationList prefetched_annotations_for_document = null)
        {
            this.library    = new TypedWeakReference <WebLibraryDetail>(web_library_detail);
            this.dictionary = dictionary;

            // process any prefetched annotations that we may have as usual:
            if (prefetched_annotations_for_document != null)
            {
                annotations = prefetched_annotations_for_document;
                lock (access_lock)
                {
                    dirtyNeedsReindexing = (prefetched_annotations_for_document.Count > 0);
                }
            }
        }
Пример #4
0
        private static Image GetImage(string name)
        {
            Image result = null;
            TypedWeakReference <Image> reference;

            if (s_imageCache.TryGetValue(name, out reference) && reference.IsAlive)
            {
                result = reference.Target;
            }

            if (result == null)
            {
                result             = Image.FromFile(name, true);
                s_imageCache[name] = new TypedWeakReference <Image>(result);
            }
            return(result);
        }
Пример #5
0
        protected virtual void Dispose(bool disposing)
        {
            Logging.Debug("LibraryIndex::Dispose({0}) @{1}", disposing, dispose_count);

            WPFDoEvents.SafeExec(() =>
            {
                if (dispose_count == 0)
                {
                    // Get rid of managed resources
                    // Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
                    lock (word_index_manager_lock)
                    {
                        // l1_clk.LockPerfTimerStop();

                        word_index_manager?.Dispose();
                        word_index_manager = null;
                    }

                    //this.library?.Dispose();
                }
            });

            WPFDoEvents.SafeExec(() =>
            {
                //this.word_index_manager = null;
                library = null;
            });

            WPFDoEvents.SafeExec(() =>
            {
                //Utilities.LockPerfTimer l4_clk = Utilities.LockPerfChecker.Start();
                lock (pdf_documents_in_library_lock)
                {
                    //l4_clk.LockPerfTimerStop();

                    pdf_documents_in_library?.Clear();
                    pdf_documents_in_library = null;
                }
            });

            ++dispose_count;
        }
Пример #6
0
        public void Dispose()
        {
#if DIAG
            Logging.Debug("FolderWatcherManager::Dispose() @{0}", ++dispose_count);
#endif

            WPFDoEvents.SafeExec(() =>
            {
                //Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
                lock (folder_watcher_records_lock)
                {
                    //l1_clk.LockPerfTimerStop();
                    // Dispose of all the folder watchers
                    foreach (var folder_watcher_record in folder_watcher_records)
                    {
                        folder_watcher_record.Value.folder_watcher.Dispose();
                    }
                    folder_watcher_records.Clear();
                }
            });

            WPFDoEvents.SafeExec(() =>
            {
                Utilities.Maintainable.MaintainableManager.Instance.CleanupEntry(managed_thread_index);
            });

            WPFDoEvents.SafeExec(() =>
            {
                //Library.Dispose();
                web_library_detail = null;
            });

            WPFDoEvents.SafeExec(() =>
            {
                // Utilities.LockPerfTimer l2_clk = Utilities.LockPerfChecker.Start();
                lock (filenames_processed_lock)
                {
                    // l2_clk.LockPerfTimerStop();
                    filenames_processed.Clear();
                }
            });
        }
Пример #7
0
        protected virtual void Dispose(bool disposing)
        {
            Logging.Debug("FolderWatcher::Dispose({0}) @{1}", disposing, dispose_count);

            WPFDoEvents.SafeExec(() =>
            {
                if (dispose_count == 0)
                {
                    // Get rid of managed resources
                    file_system_watcher.EnableRaisingEvents = false;
                    file_system_watcher.Dispose();
                }

                file_system_watcher = null;
            });

            WPFDoEvents.SafeExec(() =>
            {
                folder_watcher_manager = null;
                //library.TypedTarget.Dispose();
                web_library_detail = null;
            });

            WPFDoEvents.SafeExec(() =>
            {
                tags.Clear();
            });

            WPFDoEvents.SafeExec(() =>
            {
                configured_folder_to_watch = null;
                aspiring_folder_to_watch   = null;
            });

            WPFDoEvents.SafeExec(() =>
            {
                watch_stats.Reset(null);
            });

            ++dispose_count;
        }
Пример #8
0
        public FolderWatcher(FolderWatcherManager _folder_watcher_manager, WebLibraryDetail _library, string folder_to_watch, string _tags)
        {
            folder_watcher_manager   = new TypedWeakReference <FolderWatcherManager>(_folder_watcher_manager);
            web_library_detail       = new TypedWeakReference <WebLibraryDetail>(_library);
            aspiring_folder_to_watch = folder_to_watch;
            tags = TagTools.ConvertTagBundleToTags(_tags);
            configured_folder_to_watch = null;

            watch_stats = new WatchStatistics();

            file_system_watcher = new FileSystemWatcher();
            file_system_watcher.IncludeSubdirectories = true;
            file_system_watcher.Filter   = "*.pdf";
            file_system_watcher.Changed += file_system_watcher_Changed;
            file_system_watcher.Created += file_system_watcher_Created;
            configured_folder_to_watch   = null;
            FolderContentsHaveChanged    = false;

            file_system_watcher.Path = null;
            file_system_watcher.EnableRaisingEvents = false;
        }
Пример #9
0
        public AITagManager(Library library)
        {
            this.library = new TypedWeakReference <Library>(library);

            current_ai_tags_record = new AITags();

            // Attempt to load the existing tags
            try
            {
                if (File.Exists(Filename_Store))
                {
                    Stopwatch clk = Stopwatch.StartNew();
                    Logging.Info("+Loading AutoTags");
                    current_ai_tags_record = SerializeFile.ProtoLoad <AITags>(Filename_Store);
                    Logging.Info("-Loading AutoTags (time spent: {0} ms)", clk.ElapsedMilliseconds);
                }
            }
            catch (Exception ex)
            {
                Logging.Warn(ex, "There was a problem loading existing AutoTags");
            }
        }
Пример #10
0
        public AITagManager(WebLibraryDetail web_library_detail)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            this.web_library_detail = new TypedWeakReference <WebLibraryDetail>(web_library_detail);

            current_ai_tags_record = new AITags();

            // Attempt to load the existing tags
            try
            {
                if (File.Exists(Filename_Store))
                {
                    Stopwatch clk = Stopwatch.StartNew();
                    Logging.Info("+Loading AutoTags");
                    current_ai_tags_record = SerializeFile.ProtoLoad <AITags>(Filename_Store);
                    Logging.Info("-Loading AutoTags (time spent: {0} ms)", clk.ElapsedMilliseconds);
                }
            }
            catch (Exception ex)
            {
                Logging.Warn(ex, "There was a problem loading existing AutoTags");
            }
        }
 internal PDFDocument_ThreadUnsafe(Library library, DictionaryBasedObject dictionary)
 {
     this.library    = new TypedWeakReference <Library>(library);
     this.dictionary = dictionary;
 }
 public ExpeditionManager(WebLibraryDetail web_library_detail)
 {
     this.web_library_detail = new TypedWeakReference <WebLibraryDetail>(web_library_detail);
 }
 public RecentlyReadManager(Library library)
 {
     this.library = new TypedWeakReference <Library>(library);
 }
        public WordList GetOCRText(int page, bool queue_for_ocr)
        {
            lock (texts)
            {
                // First check our cache
                {
                    TypedWeakReference <WordList> word_list_weak;
                    texts.TryGetValue(page, out word_list_weak);
                    if (null != word_list_weak)
                    {
                        WordList word_list = word_list_weak.TypedTarget;
                        if (null != word_list)
                        {
                            return(word_list);
                        }
                    }
                }

                // Then check for an existing SINGLE file
                {
                    string filename = pdf_render_file_layer.MakeFilename_TextSingle(page);
                    try
                    {
                        if (File.Exists(filename))
                        {
                            // Get this ONE page
                            Dictionary <int, WordList> word_lists = WordList.ReadFromFile(filename, page);
                            WordList word_list = word_lists[page];
                            texts[page] = new TypedWeakReference <WordList>(word_list);
                            return(word_list);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Warn(ex, "There was an error loading the OCR text for {0} page {1}.", document_fingerprint, page);
                        FileTools.Delete(filename);
                    }
                }

                // Then check for an existing GROUP file
                {
                    string filename = pdf_render_file_layer.MakeFilename_TextGroup(page, TEXT_PAGES_PER_GROUP);
                    try
                    {
                        if (File.Exists(filename))
                        {
                            Dictionary <int, WordList> word_lists = WordList.ReadFromFile(filename);
                            foreach (var pair in word_lists)
                            {
                                texts[pair.Key] = new TypedWeakReference <WordList>(pair.Value);
                            }

                            TypedWeakReference <WordList> word_list_weak;
                            texts.TryGetValue(page, out word_list_weak);
                            if (null != word_list_weak)
                            {
                                WordList word_list = word_list_weak.TypedTarget;
                                if (null != word_list)
                                {
                                    return(word_list);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Warn(ex, "There was an error loading the OCR text group for {0} page {1}.", document_fingerprint, page);
                        FileTools.Delete(filename);
                    }
                }
            }

            // If we get this far then the text was not available so queue extraction
            if (queue_for_ocr)
            {
                // If we have never tried the GROUP version before, queue for it
                string filename = pdf_render_file_layer.MakeFilename_TextGroup(page, TEXT_PAGES_PER_GROUP);
                if (!File.Exists(filename))
                {
                    PDFTextExtractor.Instance.QueueJobGroup(new PDFTextExtractor.Job(this, page, TEXT_PAGES_PER_GROUP));
                }
                else
                {
                    PDFTextExtractor.Instance.QueueJobSingle(new PDFTextExtractor.Job(this, page, TEXT_PAGES_PER_GROUP));
                }
            }

            return(null);
        }
Пример #15
0
        /// <summary>
        /// Returns the OCR words on the page.  Null if the words are not yet available.
        /// The page will be queued for OCRing if they are not available...
        /// Page is 1 based...
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public WordList GetOCRText(int page, bool queue_for_ocr = true)
        {
            //Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (texts_lock)
            {
                //l1_clk.LockPerfTimerStop();

                // First check our cache
                {
                    TypedWeakReference <WordList> word_list_weak;
                    texts.TryGetValue(page, out word_list_weak);
                    if (null != word_list_weak)
                    {
                        WordList word_list = word_list_weak.TypedTarget;
                        if (null != word_list)
                        {
                            return(word_list);
                        }
                    }
                }

                // Then check for an existing SINGLE file
                {
                    string filename = pdf_render_file_layer.MakeFilename_TextSingle(page);
                    try
                    {
                        if (File.Exists(filename))
                        {
                            // Get this ONE page
                            Dictionary <int, WordList> word_lists = WordList.ReadFromFile(filename, page);
                            WordList word_list = word_lists[page];
                            if (null == word_list)
                            {
                                throw new Exception(String.Format("No words on page {0} in OCR file {1}", page, filename));
                            }
                            texts[page] = new TypedWeakReference <WordList>(word_list);
                            return(word_list);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Warn(ex, "There was an error loading the OCR text for {0} page {1}.", document_fingerprint, page);
                        FileTools.Delete(filename);
                    }
                }

                // Then check for an existing GROUP file
                {
                    string filename = pdf_render_file_layer.MakeFilename_TextGroup(page);
                    try
                    {
                        if (File.Exists(filename))
                        {
                            Dictionary <int, WordList> word_lists = WordList.ReadFromFile(filename);
                            foreach (var pair in word_lists)
                            {
                                texts[pair.Key] = new TypedWeakReference <WordList>(pair.Value);
                            }

                            TypedWeakReference <WordList> word_list_weak;
                            texts.TryGetValue(page, out word_list_weak);
                            if (null != word_list_weak)
                            {
                                WordList word_list = word_list_weak.TypedTarget;
                                if (null != word_list)
                                {
                                    return(word_list);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Warn(ex, "There was an error loading the OCR text group for {0} page {1}.", document_fingerprint, page);
                        FileTools.Delete(filename);
                    }
                }
            }

            // If we get this far then the text was not available so queue extraction
            if (queue_for_ocr)
            {
                // If we have never tried the GROUP version before, queue for it
                string filename          = pdf_render_file_layer.MakeFilename_TextGroup(page);
                PDFTextExtractor.Job job = new PDFTextExtractor.Job(this, page);

                if (!File.Exists(filename) && PDFTextExtractor.Instance.JobGroupHasNotFailedBefore(job))
                {
                    PDFTextExtractor.Instance.QueueJobGroup(job);
                }
                else
                {
                    PDFTextExtractor.Instance.QueueJobSingle(job);
                }
            }

            return(null);
        }
 public BlackWhiteListManager(WebLibraryDetail web_library_detail)
 {
     this.web_library_detail = new TypedWeakReference <WebLibraryDetail>(web_library_detail);
 }
Пример #17
0
 public RecentlyReadManager(WebLibraryDetail web_library_detail)
 {
     this.web_library_detail = new TypedWeakReference <WebLibraryDetail>(web_library_detail);
 }
Пример #18
0
        /// <summary>
        /// Returns the OCR words on the page.  Null if the words are not yet available.
        /// The page will be queued for OCRing if they are not available...
        /// Page is 1 based...
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public WordList GetOCRText(int page, bool queue_for_ocr = true)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            if (page > PageCount || page < 1)
            {
                // dump stacktrace with this one so we know who instigated this out-of-bounds request.
                //
                // Boundary issue was discovered during customer log file analysis (log files courtesy of Chris Hicks)
                try
                {
                    throw new ArgumentException($"INTERNAL ERROR: requesting page text for page {page} which lies outside the detected document page range 1..{PageCount} for PDF document {Fingerprint}");
                }
                catch (Exception ex)
                {
                    Logging.Error(ex);
                }
            }

            //Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (texts_lock)
            {
                //l1_clk.LockPerfTimerStop();

                // First check our cache
                {
                    TypedWeakReference <WordList> word_list_weak;
                    texts.TryGetValue(page, out word_list_weak);
                    if (null != word_list_weak)
                    {
                        WordList word_list = word_list_weak.TypedTarget;
                        if (null != word_list)
                        {
                            return(word_list);
                        }
                    }
                }

                // Then check for an existing SINGLE file
                {
                    string filename = MakeFilename_TextSingle(page);
                    try
                    {
                        if (File.Exists(filename))
                        {
                            // Get this ONE page
                            Dictionary <int, WordList> word_lists = WordList.ReadFromFile(filename, page);
                            WordList word_list = word_lists[page];
                            if (null == word_list)
                            {
                                throw new Exception(String.Format("No words on page {0} in OCR file {1}", page, filename));
                            }
                            texts[page] = new TypedWeakReference <WordList>(word_list);
                            return(word_list);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Warn(ex, "There was an error loading the OCR text for {0} page {1}.", Fingerprint, page);
                        FileTools.Delete(filename);
                    }
                }

                // Then check for an existing GROUP file
                {
                    string filename = MakeFilename_TextGroup(page);
                    try
                    {
                        if (File.Exists(filename))
                        {
                            Dictionary <int, WordList> word_lists = WordList.ReadFromFile(filename);
                            foreach (var pair in word_lists)
                            {
                                texts[pair.Key] = new TypedWeakReference <WordList>(pair.Value);
                            }

                            TypedWeakReference <WordList> word_list_weak;
                            texts.TryGetValue(page, out word_list_weak);
                            if (null != word_list_weak)
                            {
                                WordList word_list = word_list_weak.TypedTarget;
                                if (null != word_list)
                                {
                                    return(word_list);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Warn(ex, "There was an error loading the OCR text group for {0} page {1}.", Fingerprint, page);
                        FileTools.Delete(filename);
                    }
                }
            }

            // If we get this far then the text was not available so queue extraction
            if (queue_for_ocr)
            {
                // If we have never tried the GROUP version before, queue for it
                string filename          = MakeFilename_TextGroup(page);
                PDFTextExtractor.Job job = new PDFTextExtractor.Job(this, page);

                if (!File.Exists(filename) && PDFTextExtractor.Instance.JobGroupHasNotFailedBefore(job))
                {
                    PDFTextExtractor.Instance.QueueJobGroup(job);
                }
                else
                {
                    PDFTextExtractor.Instance.QueueJobSingle(job);
                }
            }

            return(null);
        }
 public ExpeditionManager(Library library)
 {
     this.library = new TypedWeakReference <Library>(library);
 }
Пример #20
0
 public PasswordManager(WebLibraryDetail web_library_detail)
 {
     this.web_library_detail = new TypedWeakReference <WebLibraryDetail>(web_library_detail);
 }
Пример #21
0
        public LibraryIndex(Library library)
        {
            this.library = new TypedWeakReference <Library>(library);

            // postpone INIT phase...
        }
 public BlackWhiteListManager(Library library)
 {
     this.library = new TypedWeakReference <Library>(library);
 }
Пример #23
0
 public PasswordManager(Library library)
 {
     this.library = new TypedWeakReference <Library>(library);
 }
Пример #24
0
        public LibraryIndex(WebLibraryDetail web_library_detail)
        {
            this.library = new TypedWeakReference <Library>(library);

            // postpone INIT phase...
        }
 internal PDFDocument(WebLibraryDetail web_library_detail)
 {
     this.library = new TypedWeakReference <WebLibraryDetail>(web_library_detail);
     dictionary   = new DictionaryBasedObject();
 }