Exemplo n.º 1
0
        internal static void ReadFromDisk(PDFDocument_ThreadUnsafe pdf_document, ref PDFAnnotationList annotations, Dictionary <string, byte[]> library_items_annotations_cache)
        {
            byte[] annotations_data = null;

            // Try the cache
            if (null != library_items_annotations_cache)
            {
                library_items_annotations_cache.TryGetValue(pdf_document.Fingerprint, out annotations_data);
            }
            else // Try to load the annotations from file if they exist
            {
                var items = pdf_document.Library.LibraryDB.GetLibraryItems(pdf_document.Fingerprint, PDFDocumentFileLocations.ANNOTATIONS);
                if (0 < items.Count)
                {
                    annotations_data = items[0].data;
                }
            }

            // If we actually have some annotations, load them
            if (null != annotations_data)
            {
                List <DictionaryBasedObject> annotation_dictionaries = null;
                try
                {
                    annotation_dictionaries = ReadFromStream_JSON(annotations_data);
                }
                catch (Exception)
                {
                    annotation_dictionaries = ReadFromStream_BINARY(annotations_data);
                }
            }
        }
Exemplo n.º 2
0
        internal static void WriteToDisk(PDFDocument_ThreadUnsafe pdf_document)
        {
            string json = pdf_document.GetAnnotationsAsJSON();

            if (!String.IsNullOrEmpty(json))
            {
                pdf_document.Library.LibraryDB.PutString(pdf_document.Fingerprint, PDFDocumentFileLocations.ANNOTATIONS, json);
            }
        }
        internal static void WriteToDisk(PDFDocument_ThreadUnsafe pdf_document)
        {
            byte[] data = pdf_document.GetInksAsJSON();

            if (null != data)
            {
                pdf_document.Library.LibraryDB.PutBlob(pdf_document.Fingerprint, PDFDocumentFileLocations.INKS, data);
            }
        }
        internal static void WriteToDisk(PDFDocument_ThreadUnsafe pdf_document)
        {
            // A little hack to make sure the legacies are updated...
            pdf_document.Tags = pdf_document.Tags;
            pdf_document.DateAddedToDatabase = pdf_document.DateAddedToDatabase;
            pdf_document.DateLastModified    = pdf_document.DateLastModified;
            pdf_document.DateLastRead        = pdf_document.DateLastRead;
            // A little hack to make sure the legacies are updated...

            string json = pdf_document.GetAttributesAsJSON();

            pdf_document.Library.LibraryDB.PutString(pdf_document.Fingerprint, PDFDocumentFileLocations.METADATA, json);
            Logging.Debug("Update metadata DB for PDF document {1}: JSON =\n{0}", json, pdf_document.Fingerprint);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the password associated with the PDFDocument.  Returns null if there is no associated password.
        /// </summary>
        /// <param name="pdf_document"></param>
        /// <returns></returns>
        public string GetPassword(PDFDocument_ThreadUnsafe pdf_document)
        {
            string fingerprint = pdf_document.Fingerprint;

            if (Passwords.ContainsKey(fingerprint))
            {
                ReversibleEncryption re = new ReversibleEncryption();
                return(re.DecryptString(Passwords[fingerprint]));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 6
0
        internal static void ReadFromStream(PDFDocument_ThreadUnsafe pdf_document, PDFHightlightList highlights, Dictionary <string, byte[]> /* can be null */ library_items_highlights_cache)
        {
            byte[] highlights_data = null;

            if (null != library_items_highlights_cache)
            {
                library_items_highlights_cache.TryGetValue(pdf_document.Fingerprint, out highlights_data);
            }
            else
            {
                List <LibraryDB.LibraryItem> library_items = pdf_document.Library.LibraryDB.GetLibraryItems(pdf_document.Fingerprint, PDFDocumentFileLocations.HIGHLIGHTS);
                if (0 < library_items.Count)
                {
                    highlights_data = library_items[0].data;
                }
            }

            if (null != highlights_data)
            {
                try
                {
                    List <PDFHighlight> highlights_list = null;

                    // First try normal
                    try
                    {
                        highlights_list = ReadFromStream_JSON(highlights_data);
                    }
                    catch (Exception)
                    {
                        highlights_list = ReadFromStream_PROTOBUF(highlights_data);
                        FeatureTrackingManager.Instance.UseFeature(Features.Legacy_Highlights_ProtoBuf);
                    }

                    if (null != highlights_list)
                    {
                        foreach (PDFHighlight highlight in highlights_list)
                        {
                            highlights.AddUpdatedHighlight(highlight);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "There was a problem loading the Highlights for document {0}", pdf_document.Fingerprint);
                }
            }
        }
Exemplo n.º 7
0
        // ------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Associates a password with the PDFDocument.
        /// Pass in numm or empty string to clear the password.
        /// </summary>
        /// <param name="pdf_document"></param>
        /// <param name="password"></param>
        public void AddPassword(PDFDocument_ThreadUnsafe pdf_document, string password)
        {
            if (null == pdf_document)
            {
                Logging.Warn("Can't associate a password with a null PDFDocument.");
            }

            if (String.IsNullOrEmpty(password))
            {
                RemovePassword(pdf_document);
            }
            else
            {
                ReversibleEncryption re = new ReversibleEncryption();
                Passwords[pdf_document.Fingerprint] = re.EncryptString(password);
                WritePasswordFile(Filename_Store, Passwords);
            }
        }
        internal static void ReadFromDisk(PDFDocument_ThreadUnsafe pdf_document, PDFInkList inks, Dictionary <string, byte[]> library_items_inks_cache)
        {
            try
            {
                byte[] inks_data = null;
                if (null != library_items_inks_cache)
                {
                    library_items_inks_cache.TryGetValue(pdf_document.Fingerprint, out inks_data);
                }
                else
                {
                    List <LibraryDB.LibraryItem> library_items = pdf_document.Library.LibraryDB.GetLibraryItems(pdf_document.Fingerprint, PDFDocumentFileLocations.INKS);
                    if (0 < library_items.Count)
                    {
                        inks_data = library_items[0].data;
                    }
                }


                if (null != inks_data)
                {
                    Dictionary <int, byte[]> page_ink_blobs = SerializeFile.ProtoLoadFromByteArray <Dictionary <int, byte[]> >(inks_data);

                    if (null != page_ink_blobs)
                    {
                        foreach (var pair in page_ink_blobs)
                        {
                            inks.AddPageInkBlob(pair.Key, pair.Value);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem loading the Inks for document {0}", pdf_document.Fingerprint);
            }
        }
Exemplo n.º 9
0
 public void RemovePassword(PDFDocument_ThreadUnsafe pdf_document)
 {
     Passwords.Remove(pdf_document.Fingerprint);
     WritePasswordFile(Filename_Store, Passwords);
 }