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