public static PDFDocument AddNewPDFDocumentsToLibrary_SYNCHRONOUS(Library library, bool suppress_notifications, bool suppress_signal_that_docs_have_changed, params string[] filenames) { FilenameWithMetadataImport[] filename_with_metadata_imports = new FilenameWithMetadataImport[filenames.Length]; for (int i = 0; i < filenames.Length; ++i) { filename_with_metadata_imports[i] = new FilenameWithMetadataImport(); filename_with_metadata_imports[i].filename = filenames[i]; } return(AddNewPDFDocumentsToLibraryWithMetadata_SYNCHRONOUS(library, suppress_notifications, suppress_signal_that_docs_have_changed, filename_with_metadata_imports)); }
public static PDFDocument AddNewPDFDocumentsToLibrary_SYNCHRONOUS(WebLibraryDetail web_library_detail, bool suppress_notifications, params string[] filenames) { WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread(); FilenameWithMetadataImport[] filename_with_metadata_imports = new FilenameWithMetadataImport[filenames.Length]; for (int i = 0; i < filenames.Length; ++i) { filename_with_metadata_imports[i] = new FilenameWithMetadataImport(); filename_with_metadata_imports[i].filename = filenames[i]; } return(AddNewPDFDocumentsToLibraryWithMetadata_SYNCHRONOUS(web_library_detail, suppress_notifications, filename_with_metadata_imports)); }
/// <summary> /// Build up the list of <code>FilenameWithMetadataImport</code>'s, including tags. Recurse with all subfolders. /// </summary> private static void BuildFileListFromFolder(List <FilenameWithMetadataImport> file_list, string folder, List <string> tags, bool recurse_subfolders, bool import_tags_from_subfolder_names) { try { // do for this folder foreach (var filename in Directory.GetFiles(folder, "*.pdf")) { var filename_with_metadata_import = new FilenameWithMetadataImport { filename = filename, tags = tags }; file_list.Add(filename_with_metadata_import); Logging.Debug("Registering file import {0} with tags {1}", filename, StringTools.ConcatenateStrings(tags)); } // onto the subfolders (if required) if (!recurse_subfolders) { return; } if (tags == null) { tags = new List <string>(); } foreach (var subfolder in Directory.GetDirectories(folder)) { // build up the new tags list (if required) var subfolder_tags = new List <string>(tags); if (import_tags_from_subfolder_names) { var directory_info = new DirectoryInfo(subfolder); subfolder_tags.Add(directory_info.Name); } // recurse BuildFileListFromFolder(file_list, subfolder, subfolder_tags, true, import_tags_from_subfolder_names); } } catch (Exception ex) { Logging.Warn(ex, "Unable to process folder {0} while importing files", folder); } }
private static PDFDocument AddQiqqaManualToLibrary(Library library) { FilenameWithMetadataImport fwmi = new FilenameWithMetadataImport(); fwmi.filename = QiqqaManualFilename; fwmi.tags.Add("manual"); fwmi.tags.Add("help"); fwmi.bibtex = "@booklet{qiqqa_manual" + "\n" + ", title = {The Qiqqa Manual}"+ "\n" + ", author = {The Qiqqa Team,}"+ "\n" + ", year = {2013}"+ "\n" + "}" ; PDFDocument pdf_document = ImportingIntoLibrary.AddNewPDFDocumentsToLibraryWithMetadata_SYNCHRONOUS(library, true, true, new FilenameWithMetadataImport[] { fwmi }); return(pdf_document); }
private static PDFDocument AddLoexManualToLibrary(Library library) { FilenameWithMetadataImport fwmi = new FilenameWithMetadataImport(); fwmi.filename = LoexManualFilename; fwmi.tags.Add("manual"); fwmi.tags.Add("help"); fwmi.bibtex = "@article{qiqqatechmatters" + "\n" + ", title = {TechMatters: “Qiqqa” than you can say Reference Management: A Tool to Organize the Research Process}"+ "\n" + ", author = {Krista Graham}"+ "\n" + ", year = {2014}"+ "\n" + ", publication = {LOEX Quarterly}"+ "\n" + ", volume = {40}"+ "\n" + ", pages = {4-6}"+ "\n" + "}" ; PDFDocument pdf_document = ImportingIntoLibrary.AddNewPDFDocumentsToLibraryWithMetadata_SYNCHRONOUS(library, true, true, new FilenameWithMetadataImport[] { fwmi }); return(pdf_document); }
public static PDFDocument AddNewPDFDocumentsToLibraryWithMetadata_SYNCHRONOUS(Library library, bool suppress_notifications, bool suppress_signal_that_docs_have_changed, FilenameWithMetadataImport[] filename_with_metadata_imports) { Stopwatch clk = new Stopwatch(); clk.Start(); // Notify if there is just a single doc suppress_notifications = suppress_notifications || (filename_with_metadata_imports.Length > 1); StatusManager.Instance.ClearCancelled("BulkLibraryDocument"); PDFDocument last_added_pdf_document = null; int successful_additions = 0; for (int i = 0; i < filename_with_metadata_imports.Length; ++i) { if (Utilities.Shutdownable.ShutdownableManager.Instance.IsShuttingDown) { Logging.Debug特("ImportingIntoLibrary: Breaking out of outer processing loop due to application termination"); break; } if (StatusManager.Instance.IsCancelled("BulkLibraryDocument")) { Logging.Warn("User chose to stop bulk adding documents to the library"); break; } StatusManager.Instance.UpdateStatus("BulkLibraryDocument", String.Format("Adding document {0} of {1} to your library", i, filename_with_metadata_imports.Length), i, filename_with_metadata_imports.Length, true); // Relinquish control to the UI thread to make sure responsiveness remains tolerable at 100% CPU load. if (i % 10 == 7) // random choice for this heuristic: every tenth ADD should *yield* to the UI { Utilities.GUI.WPFDoEvents.WaitForUIThreadActivityDone(); } FilenameWithMetadataImport filename_with_metadata_import = filename_with_metadata_imports[i]; try { string filename = filename_with_metadata_import.filename; string bibtex = filename_with_metadata_import.bibtex; // Although the outside world may allow us to be signalling, we will not do it unless we are the n-100th doc or the last doc bool local_suppress_signal_that_docs_have_changed = suppress_signal_that_docs_have_changed; if (!local_suppress_signal_that_docs_have_changed) { if ((i != filename_with_metadata_imports.Length - 1) && (0 != i % 100)) { local_suppress_signal_that_docs_have_changed = true; } } PDFDocument pdf_document = library.AddNewDocumentToLibrary_SYNCHRONOUS(filename, filename, filename, bibtex, filename_with_metadata_import.tags, filename_with_metadata_import.notes, suppress_notifications, local_suppress_signal_that_docs_have_changed); if (null != pdf_document) { ++successful_additions; } last_added_pdf_document = pdf_document; } catch (Exception ex) { Logging.Warn(ex, "There was a problem adding a document to the library:\n{0}", filename_with_metadata_import); // if the problem report file doesn't exist yet, we have to create it: Utilities.LockPerfTimer l2_clk = Utilities.LockPerfChecker.Start(); lock (problematic_import_documents_lock) { l2_clk.LockPerfTimerStop(); if (null == problematic_import_documents_filename) { problematic_import_documents_filename = TempFile.GenerateTempFilename("qiqqa-import-problem-report.txt"); } } // then always append the entire report chunk at once as multiple threads MAY // be appending to the report simultaneously! Utilities.LockPerfTimer l3_clk = Utilities.LockPerfChecker.Start(); lock (problematic_import_documents_lock) { l3_clk.LockPerfTimerStop(); File.AppendAllText( problematic_import_documents_filename, "The following files caused problems while being imported into Qiqqa:\r\n\r\n" ); #if DEBUG File.AppendAllText( problematic_import_documents_filename, String.Format( "----------\r\n{0}\r\n{1}\r\n{2}\r\n----------\r\n" , ex.Message , ex.StackTrace , filename_with_metadata_import ) ); #else File.AppendAllText( problematic_import_documents_filename, String.Format( "----------\r\n{0}\r\n{1}\r\n----------\r\n" , ex.Message , filename_with_metadata_import ) ); #endif } } } if (filename_with_metadata_imports.Length > 0) { StatusManager.Instance.UpdateStatus("BulkLibraryDocument", String.Format("Added {0} of {1} document(s) to your library", successful_additions, filename_with_metadata_imports.Length)); } else { StatusManager.Instance.ClearStatus("BulkLibraryDocument"); } // If there have been some import problems, report them to the user. // However, we should not wait for the user response! Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start(); lock (problematic_import_documents_lock) { l1_clk.LockPerfTimerStop(); if (null != problematic_import_documents_filename) { problematic_import_documents_alert_showing++; // only show a single alert, not a plethora of 'em! if (1 == problematic_import_documents_alert_showing) { // once the user has ack'ed or nack'ed the message, that handler // will RESET the 'showing' counter and the party can start all over again! SafeThreadPool.QueueUserWorkItem(o => AlertUserAboutProblematicImports()); } } } Logging.Debug特("AddNewPDFDocumentsToLibraryFromFolder_SYNCHRONOUS: time spent: {0} ms", clk.ElapsedMilliseconds); return(last_added_pdf_document); }
public static PDFDocument AddNewPDFDocumentsToLibraryWithMetadata_SYNCHRONOUS(Library library, bool suppress_notifications, bool suppress_signal_that_docs_have_changed, FilenameWithMetadataImport[] filename_with_metadata_imports) { // Notify if there is just a single doc suppress_notifications = suppress_notifications || (filename_with_metadata_imports.Length > 1); StatusManager.Instance.ClearCancelled("BulkLibraryDocument"); PDFDocument last_added_pdf_document = null; string problematic_import_documents_filename = null; int successful_additions = 0; for (int i = 0; i < filename_with_metadata_imports.Length; ++i) { if (StatusManager.Instance.IsCancelled("BulkLibraryDocument")) { Logging.Warn("User chose to stop bulk adding documents to the library"); break; } StatusManager.Instance.UpdateStatus("BulkLibraryDocument", String.Format("Adding document {0} of {1} to your library", i, filename_with_metadata_imports.Length), i, filename_with_metadata_imports.Length, true); FilenameWithMetadataImport filename_with_metadata_import = filename_with_metadata_imports[i]; try { string filename = filename_with_metadata_import.filename; string bibtex = filename_with_metadata_import.bibtex; // Although the outside world may allow us to be signalling, we will not do it unless we are the n-100th doc or the last doc bool local_suppress_signal_that_docs_have_changed = suppress_signal_that_docs_have_changed; if (!local_suppress_signal_that_docs_have_changed) { if ((i != filename_with_metadata_imports.Length - 1) && (0 != i % 100)) { local_suppress_signal_that_docs_have_changed = true; } } PDFDocument pdf_document = library.AddNewDocumentToLibrary_SYNCHRONOUS(filename, filename, bibtex, filename_with_metadata_import.tags, filename_with_metadata_import.notes, suppress_notifications, local_suppress_signal_that_docs_have_changed); if (null != pdf_document) { ++successful_additions; } last_added_pdf_document = pdf_document; } catch (Exception ex) { Logging.Warn(ex, "There was a problem adding a document to the library:\n{0}", filename_with_metadata_import); if (null == problematic_import_documents_filename) { problematic_import_documents_filename = TempFile.GenerateTempFilename("txt"); File.AppendAllText( problematic_import_documents_filename, "The following files caused problems while being imported into Qiqqa:\r\n\r\n" ); } File.AppendAllText( problematic_import_documents_filename, String.Format( "----------\r\n{0}\r\n{1}\r\n----------\r\n" , ex.Message , filename_with_metadata_import ) ); } } StatusManager.Instance.UpdateStatus("BulkLibraryDocument", String.Format("Added {0} of {1} document(s) to your library", successful_additions, filename_with_metadata_imports.Length)); // If there have been some import problems, report them to the user if (null != problematic_import_documents_filename) { if (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)) { Process.Start(problematic_import_documents_filename); } else { File.Delete(problematic_import_documents_filename); } } return(last_added_pdf_document); }
public static PDFDocument AddNewPDFDocumentsToLibraryWithMetadata_SYNCHRONOUS(WebLibraryDetail web_library_detail, bool suppress_notifications, FilenameWithMetadataImport[] filename_with_metadata_imports) { WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread(); Stopwatch clk = Stopwatch.StartNew(); Stopwatch breathing_time = Stopwatch.StartNew(); // Notify if there is just a single doc suppress_notifications = suppress_notifications || (filename_with_metadata_imports.Length > 1); StatusManager.Instance.ClearCancelled("BulkLibraryDocument"); PDFDocument last_added_pdf_document = null; int successful_additions = 0; for (int i = 0; i < filename_with_metadata_imports.Length; ++i) { if (ShutdownableManager.Instance.IsShuttingDown) { Logging.Debug特("ImportingIntoLibrary: Breaking out of outer processing loop due to application termination"); break; } if (StatusManager.Instance.IsCancelled("BulkLibraryDocument")) { Logging.Warn("User chose to stop bulk adding documents to the library"); break; } StatusManager.Instance.UpdateStatus("BulkLibraryDocument", String.Format("Adding document {0} of {1} to your library", i + 1, filename_with_metadata_imports.Length), i, filename_with_metadata_imports.Length, true); FilenameWithMetadataImport filename_with_metadata_import = filename_with_metadata_imports[i]; try { string filename = filename_with_metadata_import.filename; string bibtex = filename_with_metadata_import.bibtex; PDFDocument pdf_document = web_library_detail.Xlibrary.AddNewDocumentToLibrary_SYNCHRONOUS(filename, web_library_detail, filename, filename, bibtex, filename_with_metadata_import.tags, filename_with_metadata_import.notes, suppress_notifications); if (null != pdf_document) { ++successful_additions; } last_added_pdf_document = pdf_document; } catch (Exception ex) { Logging.Warn(ex, "There was a problem adding a document to the library:\n{0}", filename_with_metadata_import); // if the problem report file doesn't exist yet, we have to create it: // Utilities.LockPerfTimer l2_clk = Utilities.LockPerfChecker.Start(); lock (problematic_import_documents_lock) { // l2_clk.LockPerfTimerStop(); if (null == problematic_import_documents_filename) { problematic_import_documents_filename = TempFile.GenerateTempFilename("qiqqa-import-problem-report.txt"); } } // then always append the entire report chunk at once as multiple threads MAY // be appending to the report simultaneously! // Utilities.LockPerfTimer l3_clk = Utilities.LockPerfChecker.Start(); lock (problematic_import_documents_lock) { // l3_clk.LockPerfTimerStop(); File.AppendAllText( problematic_import_documents_filename, "The following files caused problems while being imported into Qiqqa:\r\n\r\n" ); File.AppendAllText( problematic_import_documents_filename, String.Format( "----------\r\n{0}\r\n{1}\r\n{2}\r\n----------\r\n" , ex.Message , ex.StackTrace , filename_with_metadata_import ) ); } } if (breathing_time.ElapsedMilliseconds >= FolderWatcher.MAX_SECONDS_PER_ITERATION) { Logging.Info("AddNewPDFDocumentsToLibraryWithMetadata_SYNCHRONOUS: Taking a nap due to MAX_SECONDS_PER_ITERATION: {0} seconds consumed", breathing_time.ElapsedMilliseconds / 1E3); ShutdownableManager.Sleep(FolderWatcher.SECONDS_TO_RELAX_PER_ITERATION); breathing_time.Restart(); } } if (filename_with_metadata_imports.Length > 0) { StatusManager.Instance.UpdateStatus("BulkLibraryDocument", String.Format("Added {0} of {1} document(s) to your library", successful_additions, filename_with_metadata_imports.Length)); } else { StatusManager.Instance.ClearStatus("BulkLibraryDocument"); } // If there have been some import problems, report them to the user. // However, we should not wait for the user response! // Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start(); lock (problematic_import_documents_lock) { // l1_clk.LockPerfTimerStop(); if (null != problematic_import_documents_filename) { problematic_import_documents_alert_showing++; // only show a single alert, not a plethora of 'em! if (1 == problematic_import_documents_alert_showing) { // once the user has ack'ed or nack'ed the message, that handler // will RESET the 'showing' counter and the party can start all over again! SafeThreadPool.QueueUserWorkItem(o => AlertUserAboutProblematicImports()); } } } Logging.Debug特("AddNewPDFDocumentsToLibraryFromFolder_SYNCHRONOUS: time spent: {0} ms", clk.ElapsedMilliseconds); return(last_added_pdf_document); }