private void RescanLibrary()
        {
            // We include the deleted ones because we need to reindex their metadata...
            List <PDFDocument> pdf_documents = library.PDFDocuments_IncludingDeleted;

            int total_new_to_be_indexed = 0;

            lock (pdf_documents_in_library)
            {
                foreach (PDFDocument pdf_document in pdf_documents)
                {
                    try
                    {
                        if (!pdf_documents_in_library.ContainsKey(pdf_document.Fingerprint))
                        {
                            ++total_new_to_be_indexed;

                            PDFDocumentInLibrary pdf_document_in_library = new PDFDocumentInLibrary();
                            pdf_document_in_library.fingerprint           = pdf_document.Fingerprint;
                            pdf_document_in_library.last_indexed          = DateTime.MinValue;
                            pdf_document_in_library.pages_already_indexed = null;

                            if (pdf_document.DocumentExists)
                            {
                                pdf_document_in_library.total_pages       = pdf_document.PDFRenderer.PageCount;
                                pdf_document_in_library.finished_indexing = false;
                            }
                            else
                            {
                                pdf_document_in_library.total_pages       = 0;
                                pdf_document_in_library.finished_indexing = true;
                            }

                            pdf_documents_in_library[pdf_document_in_library.fingerprint] = pdf_document_in_library;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Error(ex, "There was a problem with a document while rescanning the library for indexing");
                    }
                }
            }

            if (total_new_to_be_indexed > 0)
            {
                Logging.Info("There are {0} new document(s) to be indexed", total_new_to_be_indexed);
            }
        }
Beispiel #2
0
        private bool RescanLibrary()
        {
            // We include the deleted ones because we need to reindex their metadata...
            List <PDFDocument> pdf_documents = library.PDFDocuments_IncludingDeleted;

            int total_new_to_be_indexed = 0;

            Stopwatch clk = new Stopwatch();

            clk.Start();

            foreach (PDFDocument pdf_document in pdf_documents)
            {
                if (Utilities.Shutdownable.ShutdownableManager.Instance.IsShuttingDown)
                {
                    Logging.Info("Breaking out of RescanLibrary loop due to application termination");
                    return(false);
                }

                if (library.LibraryIsKilled)
                {
                    Logging.Info("Breaking out of RescanLibrary loop due to forced ABORT/Dispose of library instance.");
                    return(false);
                }

                // Do not index *deleted* documents:
                if (pdf_document.Deleted)
                {
                    continue;
                }

                try
                {
                    bool go;

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

                        go = !pdf_documents_in_library.ContainsKey(pdf_document.Fingerprint);
                    }

                    if (go)
                    {
                        ++total_new_to_be_indexed;

                        PDFDocumentInLibrary pdf_document_in_library = new PDFDocumentInLibrary();
                        pdf_document_in_library.fingerprint           = pdf_document.Fingerprint;
                        pdf_document_in_library.last_indexed          = DateTime.MinValue;
                        pdf_document_in_library.pages_already_indexed = null;

                        if (pdf_document.DocumentExists)
                        {
                            pdf_document_in_library.total_pages       = pdf_document.PDFRenderer.PageCount;
                            pdf_document_in_library.finished_indexing = false;
                        }
                        else
                        {
                            pdf_document_in_library.total_pages       = 0;
                            pdf_document_in_library.finished_indexing = true;
                        }

                        Utilities.LockPerfTimer l2_clk = Utilities.LockPerfChecker.Start();
                        lock (pdf_documents_in_library_lock)
                        {
                            l2_clk.LockPerfTimerStop();
                            pdf_documents_in_library[pdf_document_in_library.fingerprint] = pdf_document_in_library;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "There was a problem with a document while rescanning the library for indexing. Document fingerprint: {0}", pdf_document.Fingerprint);
                }
            }

            long clk_duration = clk.ElapsedMilliseconds;

            Logging.Debug特("Rescan of library {0} for indexing took {1}ms for {2} documents.", library, clk_duration, pdf_documents.Count);

            if (total_new_to_be_indexed > 0)
            {
                Logging.Info("There are {0} new document(s) to be indexed", total_new_to_be_indexed);
            }
            return(true);
        }