예제 #1
0
        public PDFDocument CloneExistingDocumentFromOtherLibrary_SYNCHRONOUS(PDFDocument existing_pdf_document, bool suppress_dialogs, bool suppress_signal_that_docs_have_changed)
        {
            StatusManager.Instance.UpdateStatus("LibraryDocument", String.Format("Copying {0} ({1}) into library", existing_pdf_document.TitleCombined, existing_pdf_document.Fingerprint));

            //  do a normal add (since stored separately)
            var new_pdf_document = AddNewDocumentToLibrary(existing_pdf_document, suppress_dialogs, suppress_signal_that_docs_have_changed);

            // If we were not able to create the PDFDocument from an existing pdf file (i.e. it was a missing reference), then create one from scratch
            if (null == new_pdf_document)
            {
                new_pdf_document = PDFDocument.CreateFromPDF(this, existing_pdf_document.DocumentPath, existing_pdf_document.Fingerprint);
                Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
                lock (pdf_documents_lock)
                {
                    l1_clk.LockPerfTimerStop();
                    pdf_documents[new_pdf_document.Fingerprint] = new_pdf_document;
                }
            }
            else
            {
                Logging.Warn("TODO: MERGE metadata for existing document and document which was copied/moved into this library. Document: {0}, {1}", new_pdf_document.Fingerprint, new_pdf_document.Library.ToString());
            }

            // clone the metadata and switch libraries
            new_pdf_document.CloneMetaData(existing_pdf_document);

            StatusManager.Instance.UpdateStatus("LibraryDocument", String.Format("Copied {0} into your library", existing_pdf_document.TitleCombined));

            return(new_pdf_document);
        }
예제 #2
0
        public void Dispose()
        {
#if DIAG
            Logging.Debug("FolderWatcherManager::Dispose() @{0}", ++dispose_count);
#endif

            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();

                //library.Dispose();
                library = null;
            }

            Utilities.LockPerfTimer l2_clk = Utilities.LockPerfChecker.Start();
            lock (filenames_processed_lock)
            {
                l2_clk.LockPerfTimerStop();
                filenames_processed.Clear();
            }
        }
예제 #3
0
        public void UseFeature(Feature feature, params object[] parameters)
        {
            // when there are parameters, create a feature instance which includes them for serialization:
            if (parameters.Length > 0)
            {
                feature = feature._(parameters);
            }

            // Check that we are not meant to be storing this feature only once...
            if (feature.RecordOnlyOncePerSession)
            {
                Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
                lock (used_once_off_per_session_features_lock)
                {
                    l1_clk.LockPerfTimerStop();
                    if (used_once_off_per_session_features.Contains(feature.Name))
                    {
                        return;
                    }
                    else
                    {
                        used_once_off_per_session_features.Add(feature.Name);
                    }
                }
            }

#if false
            // Send to GA
            GoogleAnalysicsSubmitter.Submit(feature);
#endif
        }
예제 #4
0
        private void BackgroundThread(object thread_object)
        {
            Thread thread = (Thread)thread_object;

            Logging.Debug特("AutoArranger Thread {0} has started", thread.ManagedThreadId);

            while (true)
            {
                Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
                lock (thread_lock)
                {
                    l1_clk.LockPerfTimerStop();
                    if (thread != active_thread)
                    {
                        break;
                    }
                }

                DoLayout();

                Thread.Sleep(30);
            }

            Logging.Debug特("AutoArranger Thread {0} has exited", thread.ManagedThreadId);
        }
예제 #5
0
        public FolderWatcherManager(Library library)
        {
            this.library = 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);
                    }
                }
            }

            Utilities.Maintainable.MaintainableManager.Instance.RegisterHeldOffTask(TaskDaemonEntryPoint, 30 * 1000, System.Threading.ThreadPriority.BelowNormal, extra_descr: $".Lib({library})");
        }
예제 #6
0
        internal static void AlertUserAboutProblematicImports()
        {
            bool do_view = MessageBoxes.AskErrorQuestion("There were problems with some of the documents you were trying to add to Qiqqa.  Do you want to see the problem details?", true);

            // do NOT spend a long time inside the lock!
            // hence we null the report file reference so that other threads can
            // create another report file and continue work while the user takes
            // a slow look at the old one...
            //
            // In short: take `Process.Start(...)` *outside* the lock!
            string report_filename = null;

            Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (problematic_import_documents_lock)
            {
                l1_clk.LockPerfTimerStop();
                if (do_view)
                {
                    report_filename = problematic_import_documents_filename;
                }
                else
                {
                    File.Delete(problematic_import_documents_filename);
                }
                // reset:
                problematic_import_documents_filename      = null;
                problematic_import_documents_alert_showing = 0;
            }

            if (null != report_filename)
            {
                Process.Start(report_filename);
            }
        }
        private void word_connector_ContextChanged_BACKGROUND_FindRecommendations()
        {
            while (true)
            {
                // Get the next context to search for, and if there is none, then exit the background thread
                string context;

                Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
                lock (context_thread_lock)
                {
                    l1_clk.LockPerfTimerStop();
                    context = context_thread_next_context;
                    context_thread_next_context = null;

                    if (null == context)
                    {
                        context_thread_running = false;
                        break;
                    }
                }

                // Now that we have the context, do the query
                List <PDFDocument> context_pdf_documents = new List <PDFDocument>();
                {
                    WebLibraryDetail web_library_detail = this.web_library_detail;
                    if (null != web_library_detail)
                    {
                        string context_search_string = PolishContextForLucene(context);
                        context_search_string = context_search_string.Trim();
                        if (!String.IsNullOrEmpty(context_search_string))
                        {
                            List <IndexResult> fingerprints = LibrarySearcher.FindAllFingerprintsMatchingQuery(web_library_detail.library, context_search_string);
                            if (null != fingerprints && 0 != fingerprints.Count)
                            {
                                foreach (var fingerprint in fingerprints)
                                {
                                    if (20 <= context_pdf_documents.Count)
                                    {
                                        break;
                                    }

                                    PDFDocument pdf_document = web_library_detail.library.GetDocumentByFingerprint(fingerprint.fingerprint);
                                    if (null != pdf_document)
                                    {
                                        context_pdf_documents.Add(pdf_document);
                                    }
                                }
                            }
                        }
                    }
                }

                // And get the GUI to update with the results
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    word_connector_ContextChanged_BACKGROUND_PopulateRecommendations(context_pdf_documents);
                }
                                                  ), DispatcherPriority.Background);
            }
        }
예제 #8
0
        private void GetStatusCounts(out int numerator_documents, out int denominator_documents, out int pages_so_far, out int pages_to_go)
        {
            numerator_documents   = 0;
            denominator_documents = 0;
            pages_so_far          = 0;
            pages_to_go           = 0;

            Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (pdf_documents_in_library_lock)
            {
                l1_clk.LockPerfTimerStop();
                foreach (PDFDocumentInLibrary pdf_document_in_library in pdf_documents_in_library.Values)
                {
                    ++denominator_documents;
                    if (pdf_document_in_library.finished_indexing)
                    {
                        ++numerator_documents;
                        pages_so_far += pdf_document_in_library.total_pages;
                    }
                    else
                    {
                        int finished_pages_count = (pdf_document_in_library.pages_already_indexed != null) ? pdf_document_in_library.pages_already_indexed.Count : 0;
                        pages_so_far += finished_pages_count;
                        pages_to_go  += (pdf_document_in_library.total_pages - finished_pages_count);
                    }
                }
            }
        }
예제 #9
0
        public void LoadDocumentFromMetadata(LibraryDB.LibraryItem library_item, Dictionary <string, byte[]> /* can be null */ library_items_annotations_cache, bool notify_changed_pdf_document)
        {
            try
            {
                PDFDocument pdf_document = PDFDocument.LoadFromMetaData(this, library_item.data, library_items_annotations_cache);

                Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
                lock (pdf_documents_lock)
                {
                    l1_clk.LockPerfTimerStop();
                    pdf_documents[pdf_document.Fingerprint] = pdf_document;
                }

                if (!pdf_document.Deleted)
                {
                    TagManager.Instance.ProcessDocument(pdf_document);
                    ReadingStageManager.Instance.ProcessDocument(pdf_document);
                }

                if (notify_changed_pdf_document)
                {
                    SignalThatDocumentsHaveChanged(pdf_document);
                }
                else
                {
                    SignalThatDocumentsHaveChanged(null);
                }
            }
            catch (Exception ex)
            {
                Logging.Warn(ex, "Couldn't load document from {0}", library_item.fingerprint);
            }
        }
예제 #10
0
 public void Enabled(bool enabled)
 {
     Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (thread_lock)
     {
         l1_clk.LockPerfTimerStop();
         if (enabled)
         {
             // USER WANTS TO ENABLE
             if (null == active_thread)
             {
                 active_thread = new Thread(BackgroundThread);
                 active_thread.IsBackground = true;
                 active_thread.Priority     = ThreadPriority.Lowest;
                 active_thread.Name         = "AutoArranger:Background";
                 active_thread.Start(active_thread);
             }
         }
         else
         {
             // USER WANTS TO DISABLE
             active_thread = null;
         }
     }
 }
예제 #11
0
 internal bool HaveProcessedFile(string filename)
 {
     Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (filenames_processed_lock)
     {
         l1_clk.LockPerfTimerStop();
         return(filenames_processed.Contains(filename));
     }
 }
예제 #12
0
 internal HashSet <string> GetAllDocumentFingerprints()
 {
     Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (pdf_documents_lock)
     {
         l1_clk.LockPerfTimerStop();
         return(new HashSet <string>(pdf_documents.Keys));
     }
 }
 public void Queue(PDFDocument pdf_document)
 {
     Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (documents_to_store_lock)
     {
         l1_clk.LockPerfTimerStop();
         documents_to_store[pdf_document.Library.WebLibraryDetail.Id + "." + pdf_document.Fingerprint] = pdf_document;
     }
 }
예제 #14
0
 public bool IsAlreadyCached(string token)
 {
     Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (tokens_lock)
     {
         l1_clk.LockPerfTimerStop();
         return(tokens.Contains(token));
     }
 }
예제 #15
0
 private static void ClearSyncQueue(List <SyncQueueEntry> fingerprints)
 {
     Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (fingerprints)
     {
         l1_clk.LockPerfTimerStop();
         fingerprints.Clear();
     }
 }
예제 #16
0
 public void Resume()
 {
     Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (read_out_loud_lock)
     {
         l1_clk.LockPerfTimerStop();
         speech_synthesizer.Resume();
     }
 }
예제 #17
0
 // NOTE: this method will be called from various threads.
 internal void RememberProcessedFile(string filename)
 {
     Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (filenames_processed_lock)
     {
         l1_clk.LockPerfTimerStop();
         File.AppendAllText(Filename_Store, filename + "\n");
         filenames_processed.Add(filename);
     }
 }
예제 #18
0
 internal void ResetHistory()
 {
     Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (filenames_processed_lock)
     {
         l1_clk.LockPerfTimerStop();
         FileTools.Delete(Filename_Store);
         filenames_processed.Clear();
     }
 }
예제 #19
0
        public void InvalidateIndex()
        {
            Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (word_index_manager_lock)
            {
                l1_clk.LockPerfTimerStop();

                word_index_manager?.InvalidateIndex();
            }
        }
예제 #20
0
        public int GetDocumentCountForKeyword(string keyword)
        {
            Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (word_index_manager_lock)
            {
                l1_clk.LockPerfTimerStop();

                return(word_index_manager?.GetDocumentCountForKeyword(keyword) ?? 0);
            }
        }
예제 #21
0
 private void OnShutdown()
 {
     Logging.Info("Shutting down ReadOutLoudManager");
     Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (read_out_loud_lock)
     {
         l1_clk.LockPerfTimerStop();
         speech_synthesizer.SpeakAsyncCancelAll();
     }
 }
예제 #22
0
        public List <IndexPageResult> GetPagesForQuery(string query)
        {
            Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (word_index_manager_lock)
            {
                l1_clk.LockPerfTimerStop();

                return(word_index_manager?.GetDocumentPagesWithQuery(query) ?? new List <IndexPageResult>());
            }
        }
예제 #23
0
        public HashSet <string> GetFingerprintsForKeyword(string keyword)
        {
            Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (word_index_manager_lock)
            {
                l1_clk.LockPerfTimerStop();

                return(word_index_manager?.GetDocumentsWithWord(keyword) ?? new HashSet <string>());
            }
        }
예제 #24
0
        public void IncrementalBuildIndex()
        {
            if (Utilities.Shutdownable.ShutdownableManager.Instance.IsShuttingDown)
            {
                Logging.Debug特("LibraryIndex::IncrementalBuildIndex: Breaking out due to application termination");
                return;
            }

            if (Common.Configuration.ConfigurationManager.Instance.ConfigurationRecord.DisableAllBackgroundTasks)
            {
                Logging.Debug特("LibraryIndex::IncrementalBuildIndex: Breaking due to DisableAllBackgroundTasks");
                return;
            }

            Init();

            if (DateTime.UtcNow.Subtract(time_of_last_library_scan).TotalSeconds > LIBRARY_SCAN_PERIOD_SECONDS)
            {
                if (RescanLibrary())
                {
                    time_of_last_library_scan = DateTime.UtcNow;
                }
            }

            bool did_some_work = IncrementalBuildNextDocuments();

            // Flush to disk
            if (did_some_work)
            {
                Stopwatch clk = Stopwatch.StartNew();

                Logging.Info("+Writing the index master list");

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

                    word_index_manager.WriteMasterList();
                }

                Utilities.LockPerfTimer l2_clk = Utilities.LockPerfChecker.Start();
                lock (pdf_documents_in_library_lock)
                {
                    l2_clk.LockPerfTimerStop();
                    SerializeFile.SaveSafely(Filename_DocumentProgressList, pdf_documents_in_library);
                }

                Logging.Info("-Wrote the index master list (time spent: {0} ms", clk.ElapsedMilliseconds);

                // Report to user
                UpdateStatus();
            }
        }
예제 #25
0
        public void FlushCachedTexts()
        {
            Logging.Info("Flushing the cached texts for {0}", document_fingerprint);

            Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (texts_lock)
            {
                l1_clk.LockPerfTimerStop();
                texts.Clear();
            }
        }
        /// <summary>
        /// Flush the queue. Use this call to discard pending work items when the application is terminating.
        /// </summary>
        private void FlushAllJobs()
        {
            Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (queue_lock)
            {
                l1_clk.LockPerfTimerStop();

                job_queue_group.Clear();
                job_queue_single.Clear();
            }
        }
예제 #27
0
        public PDFDocument AddVanillaReferenceDocumentToLibrary(string bibtex, HashSet <string> tags, string comments, bool suppressDialogs, bool suppress_signal_that_docs_have_changed)
        {
            string bibtex_after_key = GetBibTeXAfterKey(bibtex);

            // Check that we are not adding a duplicate
            Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (pdf_documents_lock)
            {
                l1_clk.LockPerfTimerStop();
                foreach (var pdf_document_existing in pdf_documents.Values)
                {
                    if (!String.IsNullOrEmpty(pdf_document_existing.BibTex))
                    {
                        // Identical BibTeX (after the key) will be treated as a duplicate
                        if (GetBibTeXAfterKey(pdf_document_existing.BibTex) == bibtex_after_key)
                        {
                            Logging.Info("Not importing duplicate vanilla reference with identical BibTeX to '{0}' ({1}).", pdf_document_existing.TitleCombined, pdf_document_existing.Fingerprint);
                            return(pdf_document_existing);
                        }
                    }
                }
            }

            // Not a dupe, so create
            PDFDocument pdf_document = PDFDocument.CreateFromVanillaReference(this);

            pdf_document.BibTex = bibtex;
            pdf_document.Bindable.NotifyPropertyChanged(() => pdf_document.BibTex);
            pdf_document.Comments = comments;
            pdf_document.Bindable.NotifyPropertyChanged(() => pdf_document.Comments);

            if (tags != null)
            {
                foreach (string tag in tags)
                {
                    pdf_document.AddTag(tag); // Notify changes called internally
                }
            }

            // Store in our database
            Utilities.LockPerfTimer l2_clk = Utilities.LockPerfChecker.Start();
            lock (pdf_documents_lock)
            {
                l2_clk.LockPerfTimerStop();
                pdf_documents[pdf_document.Fingerprint] = pdf_document;
            }

            if (!suppress_signal_that_docs_have_changed)
            {
                SignalThatDocumentsHaveChanged(pdf_document);
            }

            return(pdf_document);
        }
 public void GetJobCounts(out int job_queue_group_count, out int job_queue_single_count)
 {
     // Get a count of how many jobs are left...
     Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (queue_lock)
     {
         l1_clk.LockPerfTimerStop();
         job_queue_group_count  = job_queue_group.Count;
         job_queue_single_count = job_queue_single.Count;
     }
 }
예제 #29
0
 public void Add(string token)
 {
     Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (tokens_lock)
     {
         l1_clk.LockPerfTimerStop();
         if (tokens.Add(token))
         {
             is_dirty = true;
         }
     }
 }
        private void FlushDocuments(bool force_flush_no_matter_what)
        {
            // use a lock to ensure the time-delayed flush doesn't ever collide with the
            // end-of-execution-run flush initiated by ShutdownableManager.
            ForcedFlushRequested = force_flush_no_matter_what;

            while (true)
            {
                int count_to_go = PendingQueueCount;

                if (0 < count_to_go)
                {
                    StatusManager.Instance.UpdateStatusBusy("DocumentQueuedStorer", String.Format("{0} documents still to flush", count_to_go), 1, count_to_go);
                }
                else
                {
                    StatusManager.Instance.ClearStatus("DocumentQueuedStorer");
                    return;
                }

                if (!ForcedFlushRequested)
                {
                    // No flushing while still adding... unless we're quitting the executable already.
                    if (Library.IsBusyAddingPDFs)
                    {
                        return;
                    }

                    // Relinquish control to the UI thread to make sure responsiveness remains tolerable at 100% CPU load.
                    Utilities.GUI.WPFDoEvents.WaitForUIThreadActivityDone();
                }

                PDFDocument pdf_document_to_flush = null;

                // grab one PDF to save/flush:
                Utilities.LockPerfTimer l2_clk = Utilities.LockPerfChecker.Start();
                lock (documents_to_store_lock)
                {
                    l2_clk.LockPerfTimerStop();
                    foreach (var pair in documents_to_store)
                    {
                        pdf_document_to_flush = pair.Value;
                        documents_to_store.Remove(pair.Key);
                        break;
                    }
                }

                if (null != pdf_document_to_flush)
                {
                    pdf_document_to_flush.SaveToMetaData();
                }
            }
        }