private void ButtonBibTexAutoFind_Click(object sender, RoutedEventArgs e) { AugmentedBindable <PDFDocument> pdf_document_bindable = DataContext as AugmentedBindable <PDFDocument>; if (null == pdf_document_bindable) { return; } bool found_bibtex = PDFMetadataInferenceFromBibTeXSearch.InferBibTeX(pdf_document_bindable.Underlying, true); if (!found_bibtex) { if (MessageBoxes.AskQuestion("Qiqqa was unable to automatically find BibTeX for this document. Do you want to try using the BibTeX Sniffer?")) { GoogleBibTexSnifferControl sniffer = new GoogleBibTexSnifferControl(); sniffer.Show(pdf_document_bindable.Underlying); } } }
void ButtonEZProxy_Click(object sender, RoutedEventArgs e) { string current_url = active_wbc.CurrentUri.ToString(); string ezproxy = ConfigurationManager.Instance.ConfigurationRecord.Proxy_EZProxy; if (!String.IsNullOrEmpty(ezproxy)) { string new_url = ezproxy.Replace("$@", Uri.EscapeUriString(current_url)); active_wbc.Navigate(new_url); } else { if (MessageBoxes.AskQuestion("Do you not have an EZProxy set. Do you want to open the Config Screen to set one?")) { MainWindowServiceDispatcher.Instance.OpenControlPanel(); } } e.Handled = true; }
void MenuOpenOutside_Click(object sender, RoutedEventArgs e) { popup.Close(); FeatureTrackingManager.Instance.UseFeature(Features.Library_OpenOutsideQiqqa); if (5 < pdf_documents.Count) { if (!MessageBoxes.AskQuestion("Are you sure you wish to open {0} document(s)?", pdf_documents.Count)) { return; } } foreach (var pdf_document in pdf_documents) { if (pdf_document.DocumentExists) { Process.Start(pdf_document.DocumentPath); } } }
void MenuRemoveAllBibTeX_Click(object sender, RoutedEventArgs e) { popup.Close(); FeatureTrackingManager.Instance.UseFeature(Features.Library_RemoveAllBibTeX); string warning_message = String.Format("You are about to remove EVERY BibTeX record from {0} document(s). This is irreversible and may lead to tears. Are you sure you want to do this?", pdf_documents.Count); if (MessageBoxes.AskQuestion("{0}", warning_message)) { if (MessageBoxes.AskQuestion("Are you REALLY sure?")) { foreach (var pdf_document in pdf_documents) { pdf_document.BibTex = ""; pdf_document.Bindable.NotifyPropertyChanged(() => pdf_document.BibTex); } MessageBoxes.Info("Your BibTeX records have been cleared."); } } }
private void ButtonApplyReview_Click(object sender, RoutedEventArgs e) { List <PDFDocument> selected_pdf_documents = SelectedPDFDocuments; if (null == selected_pdf_documents) { return; } if (!MessageBoxes.AskQuestion("Are you sure you want to mass-edit {0} documents?", selected_pdf_documents.Count)) { return; } foreach (var pdf_document in selected_pdf_documents) { if (!String.IsNullOrEmpty(review_stub.ReadingStage)) { pdf_document.ReadingStage = review_stub.ReadingStage; pdf_document.Bindable.NotifyPropertyChanged(() => pdf_document.ReadingStage); } if (!String.IsNullOrEmpty(review_stub.Rating)) { pdf_document.Rating = review_stub.Rating; pdf_document.Bindable.NotifyPropertyChanged(() => pdf_document.Rating); } if (review_stub.IsFavourite.HasValue) { pdf_document.IsFavourite = review_stub.IsFavourite; pdf_document.Bindable.NotifyPropertyChanged(() => pdf_document.IsFavourite); } if (review_stub.Color != NULL_COLOR) { pdf_document.Color = review_stub.Color; pdf_document.Bindable.NotifyPropertyChanged(() => pdf_document.Color); } } }
private void ButtonApplyTagsAdd_Click(object sender, RoutedEventArgs e) { List <PDFDocument> selected_pdf_documents = SelectedPDFDocuments; if (null == selected_pdf_documents) { return; } HashSet <string> new_tags = TagTools.ConvertTagBundleToTags(tags_add_stub.Tags); if (!MessageBoxes.AskQuestion("Are you sure you want to add {0} tags to {1} documents?" , new_tags.Count , selected_pdf_documents.Count)) { return; } foreach (var pdf_document in selected_pdf_documents) { pdf_document.AddTag(tags_add_stub.Tags); } }
private static string GetLastStyleFilename() { string style_filename = ConfigurationManager.Instance.ConfigurationRecord.InCite_LastStyleFile; string new_style_filename = FindValidStyleFilename(style_filename); if (0 != String.Compare(new_style_filename, style_filename)) { Logging.Warn("Using suggested CSL file {0} instead of missing file {1}", new_style_filename, style_filename); } if (!String.IsNullOrEmpty(new_style_filename)) { return(new_style_filename); } else { if (MessageBoxes.AskQuestion("You need to please select a CSL style file for your citations.\nDo you want to open InCite to choose one now?")) { MainWindowServiceDispatcher.Instance.OpenInCite(); } return(null); } }
public void Regenerate(AsyncCallback callback) { Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start(); lock (in_progress_lock) { l1_clk.LockPerfTimerStop(); if (regenerating_in_progress) { Logging.Info("Not regenerating AutoTags because a regeneration is already in progress."); return; } regenerating_in_progress = true; } Stopwatch clk = Stopwatch.StartNew(); try { Logging.Info("+AITagManager is starting regenerating"); StatusManager.Instance.UpdateStatusBusy("AITags", "Loading documents"); List <PDFDocument> pdf_documents = library.PDFDocuments; int count_title_by_user = 0; int could_title_by_suggest = 0; StatusManager.Instance.UpdateStatusBusy("AITags", "Deciding whether to use suggested titles"); foreach (PDFDocument pdf_document in pdf_documents) { if (pdf_document.IsTitleGeneratedByUser) { ++count_title_by_user; } else { ++could_title_by_suggest; } } bool use_suggested_titles = could_title_by_suggest > count_title_by_user; StatusManager.Instance.UpdateStatusBusy("AITags", "Scanning titles"); List <string> titles = new List <string>(); foreach (PDFDocument pdf_document in pdf_documents) { if (use_suggested_titles || pdf_document.IsTitleGeneratedByUser) { titles.Add(pdf_document.TitleCombined); } } StatusManager.Instance.UpdateStatusBusy("AITags", "Generating AutoTags"); // Get the black/whitelists List <string> words_blacklist = new List <string>(); List <string> words_whitelist = new List <string>(); { List <BlackWhiteListEntry> entries = library.BlackWhiteListManager.ReadList(); foreach (var entry in entries) { if (entry.is_deleted) { continue; } switch (entry.list_type) { case BlackWhiteListEntry.ListType.White: words_whitelist.Add(entry.word); break; case BlackWhiteListEntry.ListType.Black: words_blacklist.Add(entry.word); break; default: Logging.Warn("Unknown black/whitelist type " + entry.list_type); break; } } } // Generate them CountingDictionary <NGram> ai_tags = BuzzwordGenerator.GenerateBuzzwords(titles, words_blacklist, words_whitelist, true); Logging.Info("Generated {0} autotags", ai_tags.Count); if (ai_tags.Count < 20) { Logging.Warn("There are too few autotags (only {0}), so not supressing Scrabble words...", ai_tags.Count); ai_tags = BuzzwordGenerator.GenerateBuzzwords(titles, words_blacklist, words_whitelist, false); Logging.Info("Generated {0} autotags without Scrabble suppression", ai_tags.Count); } StatusManager.Instance.UpdateStatusBusy("AITags", "AutoTagging documents"); AITags ai_tags_record = new AITags(); // Go through each ngram and see what documents contain it StatusManager.Instance.ClearCancelled("AITags"); List <NGram> ai_tags_list = new List <NGram>(ai_tags.Keys); for (int i = 0; i < ai_tags_list.Count; ++i) { try { NGram ai_tag = ai_tags_list[i]; string tag = ai_tag.text; if (StatusManager.Instance.IsCancelled("AITags")) { break; } StatusManager.Instance.UpdateStatusBusy("AITags", String.Format("AutoTagging papers with '{0}'", tag), i, ai_tags_list.Count, true); // Surround the tag with quotes and search the index string search_tag = "\"" + tag + "\""; List <IndexPageResult> fingerprints_potential = LibrarySearcher.FindAllPagesMatchingQuery(library, search_tag); if (null != fingerprints_potential) { // Skip this tag if too many documents have it... if (ai_tag.is_acronym && fingerprints_potential.Count > 0.05 * pdf_documents.Count) { Logging.Info("Skipping AutoTag {0} because too many documents have it...", tag); continue; } foreach (var fingerprint_potential in fingerprints_potential) { // Non-acronyms are definitely tagged if (!ai_tag.is_acronym) { ai_tags_record.Associate(tag, fingerprint_potential.fingerprint); } else { // Acronyms need to be done manually because we only want the upper case ones... PDFDocument pdf_document = library.GetDocumentByFingerprint(fingerprint_potential.fingerprint); if (null != pdf_document && !pdf_document.Deleted) { bool have_tag = false; if (!have_tag) { string doc_title = pdf_document.TitleCombined; if (!String.IsNullOrEmpty(doc_title)) { if (!ai_tag.is_acronym) { doc_title = doc_title.ToLower(); } if (doc_title.Contains(tag)) { have_tag = true; } } } if (!have_tag) { string doc_comment = pdf_document.Comments; if (!String.IsNullOrEmpty(doc_comment)) { if (!ai_tag.is_acronym) { doc_comment = doc_comment.ToLower(); } if (doc_comment.Contains(tag)) { have_tag = true; } } } if (!have_tag && pdf_document.DocumentExists) { foreach (var page_result in fingerprint_potential.page_results) { if (have_tag) { break; } int page = page_result.page; WordList page_word_list = pdf_document.PDFRenderer.GetOCRText(page); if (null != page_word_list) { foreach (Word word in page_word_list) { if (tag == word.Text) { have_tag = true; break; } } } } } // If we have this tag, record it if (have_tag) { ai_tags_record.Associate(tag, fingerprint_potential.fingerprint); } } else { Logging.Warn("Could not find a document matching fingerprint {0}", fingerprint_potential); } } } } } catch (Exception ex) { Logging.Error(ex, "There was an exception while processing one of the autotags"); } } bool use_new_autotags = true; if (StatusManager.Instance.IsCancelled("AITags")) { if (!MessageBoxes.AskQuestion("You cancelled the generation of your AutoTags. Do you want to use the partially generated AutoTags (YES) or keep your old AutoTags (NO)?")) { use_new_autotags = false; } } if (use_new_autotags) { StatusManager.Instance.UpdateStatusBusy("AITags", "Saving AutoTags"); SerializeFile.ProtoSave <AITags>(Filename_Store, ai_tags_record); current_ai_tags_record = ai_tags_record; } StatusManager.Instance.UpdateStatus("AITags", "AutoTags generated!"); } finally { Utilities.LockPerfTimer l2_clk = Utilities.LockPerfChecker.Start(); lock (in_progress_lock) { l2_clk.LockPerfTimerStop(); regenerating_in_progress = false; } Logging.Info("-AITagManager is finished regenerating (time spent: {0} ms)", clk.ElapsedMilliseconds); } // Call any callback that might be interested callback?.Invoke(null); }
internal static void Export(Library library, List <PDFDocument> pdf_documents) { StatusManager.Instance.UpdateStatusBusy("CitationMatrix", "Exporting Citation Maxtrix"); // Ask the user what they want bool export_inbound_citations = MessageBoxes.AskQuestion("Do you want to follow one layer of INBOUND citations?"); bool export_outbound_citations = MessageBoxes.AskQuestion("Do you want to follow one layer of OUTBOUND citations?"); bool export_bibtex_keys = MessageBoxes.AskQuestion("Do you want to use BibTeX keys instead of Qiqqa fingerprints where possible?"); SaveFileDialog save_file_dialog = new SaveFileDialog(); { save_file_dialog.AddExtension = true; save_file_dialog.CheckPathExists = true; save_file_dialog.DereferenceLinks = true; save_file_dialog.OverwritePrompt = true; save_file_dialog.ValidateNames = true; save_file_dialog.DefaultExt = "txt"; save_file_dialog.Filter = "Text files (*.txt)|*.zip|All files (*.*)|*.*"; save_file_dialog.FileName = "Qiqqa Citation Matrix.txt"; if (false == save_file_dialog.ShowDialog()) { Logging.Info("User cancelled export of citation matrix."); StatusManager.Instance.UpdateStatus("CitationMatrix", "Cancelled export of Citation Maxtrix"); return; } } // Build the list of papers we want to list StatusManager.Instance.UpdateStatusBusy("CitationMatrix", "Widening export set."); HashSet <string> working_set_fingerprint = new HashSet <string>(); foreach (PDFDocument pdf_document in pdf_documents) { working_set_fingerprint.Add(pdf_document.Fingerprint); if (export_inbound_citations) { foreach (var citation in pdf_document.PDFDocumentCitationManager.GetInboundCitations()) { working_set_fingerprint.Add(citation.fingerprint_outbound); } } if (export_outbound_citations) { foreach (var citation in pdf_document.PDFDocumentCitationManager.GetOutboundCitations()) { working_set_fingerprint.Add(citation.fingerprint_inbound); } } } // The bibtex mapper FingerprintToBibTeXMap map = new FingerprintToBibTeXMap(library); // Build the result StatusManager.Instance.UpdateStatusBusy("CitationMatrix", "Building Citation Matrix."); DateTime start_time = DateTime.Now; StringBuilder sb = new StringBuilder(); sb.AppendLine("------------------------------------------------------------------------"); sb.AppendLine("Cross citation report"); sb.AppendLine("------------------------------------------------------------------------"); sb.AppendLine(String.Format("Generated by Qiqqa ({0})", Common.Configuration.WebsiteAccess.Url_Documentation4Qiqqa)); sb.AppendLine(String.Format("On {0} {1}", start_time.ToLongDateString(), start_time.ToLongTimeString())); sb.AppendLine("------------------------------------------------------------------------"); sb.AppendLine("Format is:"); sb.AppendLine(" source1,target1,target2,target3,"); sb.AppendLine(" source2,target1,target4,"); sb.AppendLine(" source3,target1,target3,target5,target6,"); sb.AppendLine("------------------------------------------------------------------------"); sb.AppendLine(); foreach (var fingerprint in working_set_fingerprint) { PDFDocument pdf_document = library.GetDocumentByFingerprint(fingerprint); if (null != pdf_document) { List <Citation> citations = pdf_document.PDFDocumentCitationManager.GetOutboundCitations(); sb.AppendFormat("{0}", map.Map(pdf_document.Fingerprint, export_bibtex_keys)); sb.AppendFormat(","); foreach (Citation citation in citations) { sb.AppendFormat("{0},", map.Map(citation.fingerprint_inbound, export_bibtex_keys)); } sb.AppendFormat("\r\n"); } else { Logging.Warn("While exporting cocitations, couldn't locate document {0} in library {1}.", fingerprint, library.WebLibraryDetail.Title); } } StatusManager.Instance.UpdateStatusBusy("CitationMatrix", "Writing Citation Matrix."); string target_filename = save_file_dialog.FileName; File.WriteAllText(target_filename, sb.ToString()); StatusManager.Instance.UpdateStatus("CitationMatrix", "Exported Citation Maxtrix"); }
public PDFReadingControl OpenDocument(PDFDocument pdf_document, int?page, string search_terms, bool open_again) { if (pdf_document.IsVanillaReference) { var dialog = new AssociatePDFWithVanillaReferenceWindow(pdf_document); dialog.ShowDialog(); return(null); } FeatureTrackingManager.Instance.UseFeature( Features.Document_Open, "DocumentFingerprint", pdf_document.Fingerprint, "LibraryId", pdf_document.Library.WebLibraryDetail.Id ); // If the document doesn't exist, check if it has a url bibtex field. If so, prompt to go there to find the doc if (!File.Exists(pdf_document.DocumentPath)) { string URL_FIELD = "url"; if (null != pdf_document.BibTexItem && pdf_document.BibTexItem.ContainsField(URL_FIELD)) { if (MessageBoxes.AskQuestion("You do not have the PDF file associated with this document. However the document metadata has a URL link. Do you want to visit that web page to perhaps download it?")) { string url = pdf_document.BibTexItem[URL_FIELD]; Instance.OpenUrlInBrowser(url); } } else { MessageBoxes.Info("You do not have the PDF file associated with this document. Perhaps you need to sync with your Web/Intranet Library to fetch it?"); } return(null); } // Mark as recently read pdf_document.Library.RecentlyReadManager.AddRecentlyRead(pdf_document); // Add to most recently used pdf_document.DateLastRead = DateTime.UtcNow; pdf_document.Bindable.NotifyPropertyChanged(() => pdf_document.DateLastRead); // Set the opening page, if necessary if (page.HasValue) { pdf_document.PageLastRead = page.Value; } // Cause all pages to be OCRed pdf_document.PDFRenderer.CauseAllPDFPagesToBeOCRed(); // Create a title for the window string title = "PDF " + pdf_document.Fingerprint; { StringBuilder sb = new StringBuilder(); List <NameTools.Name> names = NameTools.SplitAuthors(pdf_document.AuthorsCombined, PDFDocument.UNKNOWN_AUTHORS); if (0 < names.Count && names[0] != NameTools.Name.UNKNOWN_NAME) { sb.Append(names[0].last_name); } if (!String.IsNullOrEmpty(pdf_document.YearCombined)) { sb.Append(pdf_document.YearCombined); } if (!String.IsNullOrEmpty(pdf_document.TitleCombined)) { if (0 < sb.Length) { sb.Append(", "); } sb.Append(pdf_document.TitleCombined); } if (0 < sb.Length) { title = sb.ToString(); } } // Open the window PDFReadingControl pdf_reading_control = null; if (!open_again && main_window.DockingManager.Contains(pdf_document.UniqueId)) { Logging.Info("Activating existing PDF viewer for '{0}' with fingerprint {1}", title, pdf_document.Fingerprint); FrameworkElement fe = main_window.DockingManager.MakeActive(pdf_document.UniqueId); pdf_reading_control = fe as PDFReadingControl; } else { Logging.Info("Opening new PDF viewer for {0}", title); pdf_reading_control = new PDFReadingControl(pdf_document); // Shall we colour the tab header? Color?header_color = pdf_document.Color; main_window.DockingManager.AddContent(pdf_document.UniqueId, title, Icons.GetAppIcon(Icons.ModulePDFViewer), true, true, pdf_reading_control, header_color); } // Select the current search terms if (null != pdf_reading_control) { if (!String.IsNullOrEmpty(search_terms)) { pdf_reading_control.SetSearchKeywords(search_terms); } if (page.HasValue) { pdf_reading_control.SelectPage(page.Value); } } return(pdf_reading_control); }