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); } }
internal void NotifyLibraryThatDocumentHasChangedExternally(string fingerprint) { Logging.Info("Library has been notified that {0} has changed", fingerprint); try { LibraryDB.LibraryItem library_item = library_db.GetLibraryItem(fingerprint, PDFDocumentFileLocations.METADATA); LoadDocumentFromMetadata(library_item, null, true); } catch (Exception ex) { Logging.Warn(ex, "We were told that something had changed, but could not find it on looking..."); } }
void BuildFromDocumentRepository() { try { library_is_loaded = false; Logging.Debug("+Build library from repository"); List <LibraryDB.LibraryItem> library_items = this.library_db.GetLibraryItems(null, PDFDocumentFileLocations.METADATA); // Get the annotations cache Dictionary <string, byte[]> library_items_annotations_cache = this.library_db.GetLibraryItemsAsCache(PDFDocumentFileLocations.ANNOTATIONS); Logging.Info("Loading {0} files from repository at {1}", library_items.Count, LIBRARY_DOCUMENTS_BASE_PATH); for (int i = 0; i < library_items.Count; ++i) { LibraryDB.LibraryItem library_item = library_items[i]; // Track progress of how long this is taking to load if (0 == i % 250) { StatusManager.Instance.UpdateStatus("LibraryInitialLoad", "Loading your library", i, library_items.Count); } try { LoadDocumentFromMetadata(library_item, library_items_annotations_cache, false); } catch (Exception ex) { Logging.Error(ex, "There was a problem loading document {0}", library_item); } } StatusManager.Instance.ClearStatus("LibraryInitialLoad"); Logging.Debug("-Build library from repository"); } catch (Exception ex) { Logging.Error(ex, "There was a problem while building the document library"); } finally { library_is_loaded = true; } }
// NOTE: this function is executed ASYNCHRONOUSLY. // // Once completed, an event will be fired to // help the main application update any relevant views. private void BuildFromDocumentRepository() { try { LibraryIsLoaded = false; // abort work when this library instance has already been Dispose()d in the main UI thread: if (LibraryIsKilled) { Logging.Info("Building the library has been SKIPPED/ABORTED as the library {0} has already been killed.", WebLibraryDetail.Id); return; } Stopwatch clk = Stopwatch.StartNew(); long prev_clk = 0; long elapsed = 0; Logging.Debug特("+Build library from repository"); List <LibraryDB.LibraryItem> library_items = library_db.GetLibraryItems(null, PDFDocumentFileLocations.METADATA); // abort work when this library instance has already been Dispose()d in the main UI thread: if (LibraryIsKilled) { Logging.Info("Building the library has been SKIPPED/ABORTED as the library {0} has already been killed.", WebLibraryDetail.Id); return; } elapsed = clk.ElapsedMilliseconds; Logging.Debug特(":Build library '{2}' from repository -- time spent: {0} ms on fetching {1} records from SQLite DB.", elapsed, library_items.Count, WebLibraryDetail.DescriptiveTitle); prev_clk = elapsed; // Get the annotations cache Dictionary <string, byte[]> library_items_annotations_cache = library_db.GetLibraryItemsAsCache(PDFDocumentFileLocations.ANNOTATIONS); // abort work when this library instance has already been Dispose()d in the main UI thread: if (LibraryIsKilled) { Logging.Info("Building the library has been SKIPPED/ABORTED as the library {0} has already been killed.", WebLibraryDetail.Id); return; } elapsed = clk.ElapsedMilliseconds; Logging.Debug特(":Build library '{2}' from repository -- time spent: {0} ms on fetching annotation cache for {1} records.", elapsed - prev_clk, library_items.Count, WebLibraryDetail.DescriptiveTitle); prev_clk = elapsed; Logging.Info("Library '{2}': Loading {0} files from repository at {1}", library_items.Count, LIBRARY_DOCUMENTS_BASE_PATH, WebLibraryDetail.DescriptiveTitle); for (int i = 0; i < library_items.Count; ++i) { LibraryDB.LibraryItem library_item = library_items[i]; // Track progress of how long this is taking to load elapsed = clk.ElapsedMilliseconds; if (prev_clk + 1000 <= elapsed) { StatusManager.Instance.UpdateStatus("LibraryInitialLoad", String.Format("Loading your library '{0}'", WebLibraryDetail.DescriptiveTitle), i, library_items.Count); Logging.Info("Library '{2}': Loaded {0}/{1} documents", i, library_items.Count, WebLibraryDetail.DescriptiveTitle); prev_clk = elapsed; System.Threading.Thread.Yield(); } if (LibraryIsKilled) { // abort work when this library instance has already been Dispose()d in the main UI thread: Logging.Info("Building the library has been SKIPPED/ABORTED as the library {0} has already been killed.", WebLibraryDetail.Id); break; } try { LoadDocumentFromMetadata(library_item, library_items_annotations_cache, false); } catch (Exception ex) { Logging.Error(ex, "Library '{1}': There was a problem loading document {0}", library_item, WebLibraryDetail.DescriptiveTitle); } } StatusManager.Instance.ClearStatus("LibraryInitialLoad"); Logging.Debug特("-Build library '{2}' from repository -- time spent: {0} ms on {1} library records.", clk.ElapsedMilliseconds, library_items.Count, WebLibraryDetail.DescriptiveTitle); } catch (Exception ex) { if (LibraryIsKilled) { Logging.Warn(ex, "There was a failure while building the *KILLED* document library instance for library {0} ({1})", WebLibraryDetail.DescriptiveTitle, WebLibraryDetail.Id); } else { Logging.Error(ex, "There was a problem while building the document library {0} ({1})", WebLibraryDetail.DescriptiveTitle, WebLibraryDetail.Id); } } finally { LibraryIsLoaded = true; if (!LibraryIsKilled) { // fire the event ASYNC OnLibraryLoaded?.BeginInvoke(this, null, null); } } }