private static List <Citation> ReadFromDisk(PDFDocument pdf_document) { WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread(); List <Citation> citations = new List <Citation>(); List <LibraryDB.LibraryItem> library_items = pdf_document.Library.LibraryDB.GetLibraryItems(pdf_document.Fingerprint, PDFDocumentFileLocations.CITATIONS); if (0 < library_items.Count) { LibraryDB.LibraryItem library_item = library_items[0]; string lines_all = Encoding.UTF8.GetString(library_item.data); StringArray lines = StringTools.splitAtNewline(lines_all); foreach (string line in lines) { string[] chunks = line.Split(','); Citation citation = new Citation(); citation.fingerprint_outbound = chunks[0]; citation.fingerprint_inbound = chunks[1]; citation.type = (Citation.Type)Convert.ToInt32(chunks[2]); citations.Add(citation); } } return(citations); }
public static PDFDocument CreateFromVanillaReference(Library library) { PDFDocument pdf_document = new PDFDocument(library); // Store the most important information pdf_document.FileType = VanillaReferenceFileType; pdf_document.Fingerprint = VanillaReferenceCreating.CreateVanillaReferenceFingerprint(); pdf_document.DateAddedToDatabase = DateTime.UtcNow; pdf_document.DateLastModified = DateTime.UtcNow; Directory.CreateDirectory(pdf_document.DocumentBasePath); List <LibraryDB.LibraryItem> library_items = library.LibraryDB.GetLibraryItems(pdf_document.Fingerprint, PDFDocumentFileLocations.METADATA); if (0 == library_items.Count) { DocumentQueuedStorer.Instance.Queue(pdf_document); } else { try { LibraryDB.LibraryItem library_item = library_items[0]; pdf_document = LoadFromMetaData(library, library_item.data, null); } catch (Exception ex) { Logging.Error(ex, "There was a problem reloading an existing PDF from existing metadata, so overwriting it!"); DocumentQueuedStorer.Instance.Queue(pdf_document); } } return(pdf_document); }
public static PDFDocument CreateFromPDF(WebLibraryDetail web_library_detail, string filename, string precalculated_fingerprint__can_be_null) { string fingerprint = precalculated_fingerprint__can_be_null; if (String.IsNullOrEmpty(fingerprint)) { fingerprint = StreamFingerprint.FromFile(filename); } PDFDocument pdf_document = new PDFDocument(web_library_detail); // Store the most important information // // thread-UNSAFE access is permitted as the PDF has just been created so there's no thread-safety risk yet. pdf_document.FileType = Path.GetExtension(filename).TrimStart('.'); pdf_document.Fingerprint = fingerprint; pdf_document.DateAddedToDatabase = DateTime.UtcNow; pdf_document.DateLastModified = DateTime.UtcNow; Directory.CreateDirectory(pdf_document.DocumentBasePath); pdf_document.StoreAssociatedPDFInRepository(filename); List <LibraryDB.LibraryItem> library_items = web_library_detail.Xlibrary.LibraryDB.GetLibraryItems(PDFDocumentFileLocations.METADATA, new List <string>() { pdf_document.Fingerprint }); ASSERT.Test(library_items.Count < 2); if (0 == library_items.Count) { pdf_document.QueueToStorage(); } else { LibraryDB.LibraryItem library_item = null; try { library_item = library_items[0]; pdf_document = LoadFromMetaData(web_library_detail, pdf_document.Fingerprint, library_item.data); } catch (Exception ex) { // keep the unrecognized data around so we may fix it later... Logging.Error(ex, "There was a problem reloading an existing PDF from existing metadata, so overwriting it! (document fingerprint: {0}, data: {1})", pdf_document.Fingerprint, library_item?.MetadataAsString() ?? "???"); // TODO: WARNING: overwriting old (possibly corrupted) records like this can loose you old/corrupted/unsupported metadata content! pdf_document.QueueToStorage(); //pdf_document.SaveToMetaData(); } } return(pdf_document); }
public static PDFDocument CreateFromPDF(Library library, string filename, string precalculated_fingerprint__can_be_null) { string fingerprint = precalculated_fingerprint__can_be_null; if (String.IsNullOrEmpty(fingerprint)) { fingerprint = StreamFingerprint.FromFile(filename); } LockObject _lock = new LockObject(); PDFDocument pdf_document = new PDFDocument(_lock, library); // Store the most important information // // thread-UNSAFE access is permitted as the PDF has just been created so there's no thread-safety risk yet. pdf_document.doc.FileType = Path.GetExtension(filename).TrimStart('.'); pdf_document.doc.Fingerprint = fingerprint; pdf_document.doc.DateAddedToDatabase = DateTime.UtcNow; pdf_document.doc.DateLastModified = DateTime.UtcNow; Directory.CreateDirectory(pdf_document.DocumentBasePath); pdf_document.doc.StoreAssociatedPDFInRepository(filename); List <LibraryDB.LibraryItem> library_items = library.LibraryDB.GetLibraryItems(pdf_document.doc.Fingerprint, PDFDocumentFileLocations.METADATA); if (0 == library_items.Count) { pdf_document.QueueToStorage(); } else { try { LibraryDB.LibraryItem library_item = library_items[0]; pdf_document = LoadFromMetaData(library, library_item.data, null); } catch (Exception ex) { Logging.Error(ex, "There was a problem reloading an existing PDF from existing metadata, so overwriting it!"); // TODO: WARNING: overwriting old (possibly corrupted) records like this can loose you old/corrupted/unsupported metadata content! pdf_document.QueueToStorage(); //pdf_document.SaveToMetaData(); } } return(pdf_document); }
public static PDFDocument CreateFromPDF(Library library, string filename, string precalculated_fingerprint__can_be_null) { string fingerprint = precalculated_fingerprint__can_be_null; if (String.IsNullOrEmpty(fingerprint)) { fingerprint = StreamFingerprint.FromFile(filename); } PDFDocument pdf_document = new PDFDocument(library); // Store the most important information pdf_document.FileType = Path.GetExtension(filename).TrimStart('.'); pdf_document.Fingerprint = fingerprint; pdf_document.DateAddedToDatabase = DateTime.UtcNow; pdf_document.DateLastModified = DateTime.UtcNow; Directory.CreateDirectory(pdf_document.DocumentBasePath); pdf_document.StoreAssociatedPDFInRepository(filename); List <LibraryDB.LibraryItem> library_items = library.LibraryDB.GetLibraryItems(pdf_document.Fingerprint, PDFDocumentFileLocations.METADATA); if (0 == library_items.Count) { DocumentQueuedStorer.Instance.Queue(pdf_document); } else { try { LibraryDB.LibraryItem library_item = library_items[0]; pdf_document = LoadFromMetaData(library, library_item.data, null); } catch (Exception ex) { Logging.Error(ex, "There was a problem reloading an existing PDF from existing metadata, so overwriting it!"); DocumentQueuedStorer.Instance.Queue(pdf_document); //pdf_document.SaveToMetaData(); } } return(pdf_document); }
public static PDFDocument CreateFromVanillaReference(WebLibraryDetail web_library_detail) { PDFDocument pdf_document = new PDFDocument(web_library_detail); // Store the most important information // // thread-UNSAFE access is permitted as the PDF has just been created so there's no thread-safety risk yet. pdf_document.FileType = Constants.VanillaReferenceFileType; pdf_document.Fingerprint = VanillaReferenceCreating.CreateVanillaReferenceFingerprint(); pdf_document.DateAddedToDatabase = DateTime.UtcNow; pdf_document.DateLastModified = DateTime.UtcNow; Directory.CreateDirectory(pdf_document.DocumentBasePath); List <LibraryDB.LibraryItem> library_items = web_library_detail.Xlibrary.LibraryDB.GetLibraryItems(PDFDocumentFileLocations.METADATA, new List <string>() { pdf_document.Fingerprint }); ASSERT.Test(library_items.Count < 2); if (0 == library_items.Count) { pdf_document.QueueToStorage(); } else { LibraryDB.LibraryItem library_item = null; try { library_item = library_items[0]; pdf_document = LoadFromMetaData(web_library_detail, pdf_document.Fingerprint, library_item.data); } catch (Exception ex) { Logging.Error(ex, "There was a problem reloading an existing PDF from existing metadata, so overwriting it! (document fingerprint: {0}, data: {1})", pdf_document.Fingerprint, library_item?.MetadataAsString() ?? "???"); // TODO: WARNING: overwriting old (possibly corrupted) records like this can loose you old/corrupted/unsupported metadata content! pdf_document.QueueToStorage(); } } return(pdf_document); }
public static PDFDocument CreateFromVanillaReference(Library library) { LockObject _lock = new LockObject(); PDFDocument pdf_document = new PDFDocument(_lock, library); // Store the most important information // // thread-UNSAFE access is permitted as the PDF has just been created so there's no thread-safety risk yet. pdf_document.FileType = Constants.VanillaReferenceFileType; pdf_document.Fingerprint = VanillaReferenceCreating.CreateVanillaReferenceFingerprint(); pdf_document.DateAddedToDatabase = DateTime.UtcNow; pdf_document.DateLastModified = DateTime.UtcNow; Directory.CreateDirectory(pdf_document.DocumentBasePath); List <LibraryDB.LibraryItem> library_items = library.LibraryDB.GetLibraryItems(pdf_document.Fingerprint, PDFDocumentFileLocations.METADATA); if (0 == library_items.Count) { pdf_document.QueueToStorage(); } else { try { LibraryDB.LibraryItem library_item = library_items[0]; pdf_document = LoadFromMetaData(library, library_item.data, null); } catch (Exception ex) { Logging.Error(ex, "There was a problem reloading an existing PDF from existing metadata, so overwriting it!"); // TODO: WARNING: overwriting old (possibly corrupted) records like this can loose you old/corrupted/unsupported metadata content! pdf_document.QueueToStorage(); } } return(pdf_document); }
private void ButtonGet_Click(object sender, RoutedEventArgs e) { if (null == library) { MessageBoxes.Error("You must choose a library..."); return; } TxtData.Text = ""; int MaxRecordCount; if (!int.TryParse(MaxNumberOfRecords.Text, out MaxRecordCount)) { MaxRecordCount = 0; } var items = library.LibraryDB.GetLibraryItems(TxtFingerprint.Text, TxtExtension.Text, MaxRecordCount); if (0 == items.Count) { MessageBoxes.Warn("No entry was found."); } else if (1 == items.Count) { byte[] data = items[0].data; string json = Encoding.UTF8.GetString(data); TxtData.Text = json; } else { MessageBoxes.Warn("{0} entries were found; we're showing them all but you'll only be able to PUT/WRITE the first one!", items.Count); StringBuilder allstr = new StringBuilder(); for (int i = 0; i < items.Count; i++) { if (i > 0) { allstr.Append("\n\n==========================================================\n\n"); } LibraryDB.LibraryItem item = items[i]; byte[] data = item.data; string json = Encoding.UTF8.GetString(data); allstr.AppendLine(json); allstr.Append("\n--------------(decoded metadata)--------------------------\n"); allstr.AppendLine(string.Format("fingerprint: {0}", item.fingerprint)); allstr.AppendLine(string.Format("extension: {0}", item.extension)); allstr.AppendLine(string.Format("MD5 hash: {0}", item.md5)); try { PDFDocument doc = PDFDocument.LoadFromMetaData(library, item.data, null); string bibtexStr = doc.BibTex; if (null == bibtexStr) { bibtexStr = "--(NULL)--"; } else if (String.IsNullOrWhiteSpace(bibtexStr)) { bibtexStr = "--(EMPTY)--"; } else { BibTexItem bibtex = doc.BibTexItem; string bibtexParseErrors; string formattedBibStr; string rawStr; if (bibtex != null) { if (bibtex.Exceptions.Count > 0 || bibtex.Warnings.Count > 0) { bibtexParseErrors = bibtex.GetExceptionsAndMessagesString(); } else { bibtexParseErrors = String.Empty; } formattedBibStr = bibtex.ToBibTex(); if (String.IsNullOrEmpty(formattedBibStr)) { formattedBibStr = "--(EMPTY)--"; } rawStr = bibtex.ToString(); if (String.IsNullOrEmpty(rawStr)) { rawStr = "--(EMPTY)--"; } } else { bibtexParseErrors = "ERROR: This content is utterly INVALID BibTeX as far as the BibTeX parser is concerned!"; formattedBibStr = String.Empty; rawStr = String.Empty; } if (!String.IsNullOrEmpty(formattedBibStr)) { allstr.AppendLine(string.Format("\nBibTeX Formatted:\n {0}", formattedBibStr.Replace("\n", "\n "))); } if (!String.IsNullOrEmpty(rawStr)) { allstr.AppendLine(string.Format("\nBibTeX RAW FMT:\n {0}", rawStr.Replace("\n", "\n "))); } if (!String.IsNullOrEmpty(bibtexParseErrors)) { allstr.AppendLine(string.Format("\nBibTeX Parse Diagnostics:\n {0}", bibtexParseErrors.Replace("\n", "\n "))); } } allstr.AppendLine(string.Format("\nBibTeX RAW INPUT:\n {0}", bibtexStr.Replace("\n", "\n "))); } catch (Exception ex) { allstr.AppendLine(string.Format("*** PARSE ERROR ***:\n {0}", ex.ToString().Replace("\n", "\n "))); } } // also dump the output to file (for diagnostics) string path = Path.GetFullPath(Path.Combine(library.LIBRARY_BASE_PATH, @"Qiqqa.DBexplorer.QueryDump.txt")); // overwrite previous query dump: using (StreamWriter sr = new StreamWriter(path, false /* overwrite */)) { sr.WriteLine(allstr); } TxtData.Text = allstr.ToString(); } }
private void ButtonGet_Click(object sender, RoutedEventArgs e) { if (null == web_library_detail) { MessageBoxes.Error("You must choose a library..."); return; } TxtData.Text = ""; int MaxRecordCount; if (!int.TryParse(MaxNumberOfRecords.Text, out MaxRecordCount)) { MaxRecordCount = 0; } var items = web_library_detail.Xlibrary.LibraryDB.GetLibraryItems(TxtExtension.Text, new List <string>() { TxtFingerprint.Text }, MaxRecordCount); if (0 == items.Count) { MessageBoxes.Warn("No entry was found."); } else if (1 == items.Count) { byte[] data = items[0].data; string json = Encoding.UTF8.GetString(data); TxtData.Text = json; } else { MessageBoxes.Warn("{0} entries were found; we're showing them all but you'll only be able to PUT/WRITE the first one!", items.Count); StringBuilder allstr = new StringBuilder(); for (int i = 0; i < items.Count; i++) { if (i > 0) { allstr.Append("\n\n==========================================================\n\n"); } LibraryDB.LibraryItem item = items[i]; byte[] data = item.data; string json = Encoding.UTF8.GetString(data); allstr.AppendLine(json); allstr.Append("\n--------------(decoded metadata)--------------------------\n"); allstr.AppendLine(string.Format("fingerprint: {0}", item.fingerprint)); allstr.AppendLine(string.Format("extension: {0}", item.extension)); allstr.AppendLine(string.Format("MD5 hash: {0}", item.md5)); if (item.data.Length > 0) { switch (item.extension) { case "citations": try { string citations = Encoding.UTF8.GetString(data); // format: (hash, hash_REF, unknown_int) on every line. e.g. // // 99D81E4872BD14C8766C57B298175B92C9CA749,024F6E48744443D5B7D22DE2007EFA7C_REF,0 // E62116BFF03E2D6AF99D596C8EB5C3D3B6111B5,024F6E48744443D5B7D22DE2007EFA7C_REF,0 // EB9BAE68C451CEEC70E4FE352078AEA4050A427,024F6E48744443D5B7D22DE2007EFA7C_REF,0 // ... allstr.AppendLine(string.Format("citations = [\n{0}\n]", citations)); } catch (Exception ex) { allstr.AppendLine(string.Format("*** CITATIONS RECORD PARSE ERROR ***:\n {0}", ex.ToString().Replace("\n", "\n "))); } break; // highlights format: JSON: // // [ // { // "P": 3, // "L": 0.21154, // "T": 0.1395, // "W": 0.09829, // "H": 0.01615, // "C": 0 // }, // ... // /* * example annotation: JSON format: * * [ * { * "Guid": "329abf6b-59b4-450a-b015-65402c25068d", * "DocumentFingerprint": "0E294EABE45DD6B903A3F6EEF964D80645F272C", * "Page": 4, * "DateCreated": "20120427153803358", * "Deleted": false, * "ColorWrapper": "#FF87CEEB", * "Left": 0.11479289940828402, * "Top": 0.06685699621479417, * "Width": 0.41301775147928993, * "Height": 0.25688073394495414, * "FollowUpDate": "00010101000000000", * "Text": "rgrgdrgdrgdrgdrgdrgdrdrgdrg" * } * ] */ case "annotations": try { string s = Encoding.UTF8.GetString(data); allstr.AppendLine(string.Format("{1} = [\n{0}\n]", s, item.extension)); } catch (Exception ex) { allstr.AppendLine(string.Format("*** {1} RECORD PARSE ERROR ***:\n {0}", ex.ToString().Replace("\n", "\n "), item.extension)); } break; case "highlights": try { string s = Encoding.UTF8.GetString(data); allstr.AppendLine(string.Format("{1} = [\n{0}\n]", s, item.extension)); } catch (Exception ex) { allstr.AppendLine(string.Format("*** {1} RECORD PARSE ERROR ***:\n {0}", ex.ToString().Replace("\n", "\n "), item.extension)); } break; // inks format: binary serialized // case "inks": try { string s = Encoding.UTF8.GetString(data); allstr.AppendLine(string.Format("{1} = [\n{0}\n]", s, item.extension)); } catch (Exception ex) { allstr.AppendLine(string.Format("*** {1} RECORD PARSE ERROR ***:\n {0}", ex.ToString().Replace("\n", "\n "), item.extension)); } break; case "metadata": try { PDFDocument doc = PDFDocument.LoadFromMetaData(web_library_detail, item.fingerprint, item.data); string bibtexStr = doc.BibTex; if (null == bibtexStr) { bibtexStr = "--(NULL)--"; } else if (String.IsNullOrWhiteSpace(bibtexStr)) { bibtexStr = "--(EMPTY)--"; } else { BibTexItem bibtex = doc.BibTexItem; string bibtexParseErrors; string formattedBibStr; string rawStr; if (bibtex != null) { if (bibtex.Exceptions.Count > 0 || bibtex.Warnings.Count > 0) { bibtexParseErrors = bibtex.GetExceptionsAndMessagesString(); } else { bibtexParseErrors = String.Empty; } formattedBibStr = bibtex.ToBibTex(); if (String.IsNullOrEmpty(formattedBibStr)) { formattedBibStr = "--(EMPTY)--"; } rawStr = bibtex.ToString(); if (String.IsNullOrEmpty(rawStr)) { rawStr = "--(EMPTY)--"; } } else { bibtexParseErrors = "ERROR: This content is utterly INVALID BibTeX as far as the BibTeX parser is concerned!"; formattedBibStr = String.Empty; rawStr = String.Empty; } if (!String.IsNullOrEmpty(formattedBibStr)) { allstr.AppendLine(string.Format("\nBibTeX Formatted:\n {0}", formattedBibStr.Replace("\n", "\n "))); } if (!String.IsNullOrEmpty(rawStr)) { allstr.AppendLine(string.Format("\nBibTeX RAW FMT:\n {0}", rawStr.Replace("\n", "\n "))); } if (!String.IsNullOrEmpty(bibtexParseErrors)) { allstr.AppendLine(string.Format("\nBibTeX Parse Diagnostics:\n {0}", bibtexParseErrors.Replace("\n", "\n "))); } } allstr.AppendLine(string.Format("\nBibTeX RAW INPUT:\n {0}", bibtexStr.Replace("\n", "\n "))); } catch (Exception ex) { allstr.AppendLine(string.Format("*** PARSE ERROR ***:\n {0}", ex.ToString().Replace("\n", "\n "))); } break; default: try { string s = Encoding.UTF8.GetString(data); allstr.AppendLine(string.Format("{1} = [\n{0}\n]", s, item.extension)); } catch (Exception ex) { allstr.AppendLine(string.Format("*** XXX = {1} RECORD PARSE ERROR ***:\n {0}", ex.ToString().Replace("\n", "\n "), item.extension)); } break; } } } // also dump the output to file (for diagnostics) string path = Path.GetFullPath(Path.Combine(web_library_detail.LIBRARY_BASE_PATH, @"Qiqqa.DBexplorer.QueryDump.txt")); // overwrite previous query dump: using (StreamWriter sr = new StreamWriter(path, false /* overwrite */)) { sr.WriteLine(allstr); } TxtData.Text = allstr.ToString(); } }