示例#1
0
        private static void PullAnnotationsWork(Book book)
        {
            List <Annotation> sAnnotations = SaveMyStuff.GetMyAnnotations(book.ID);

            if (sAnnotations != null && sAnnotations.Count > 0)
            {
                foreach (var sAnn in sAnnotations)
                {
                    Annotation dAnn = BooksOnDeviceAccessor.GetAnnotation(book.ID, sAnn.PageID);
                    if (dAnn == null)
                    {
                        // This is a new note from the server
                        BooksOnDeviceAccessor.AddAnnotation(sAnn);
                    }
                    else
                    {
                        if (dAnn.ModifiedUtc <= sAnn.ModifiedUtc)
                        {
                            if (sAnn.Removed)
                            {
                                // Remove annotation if the annotation on the cloud has 'Removed' checked
                                BooksOnDeviceAccessor.RemoveAnnotation(dAnn.BookID, dAnn.PageID);
                            }
                            else
                            {
                                BooksOnDeviceAccessor.UpdateAnnotation(sAnn);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
 public void AddAnnotations()
 {
     try
     {
         for (nint i = 0; i < (nint)this.Document.PageCount; i++)
         {
             Page page = BooksOnDeviceAccessor.GetPage(book.ID, i + 1);
             if (page != null)
             {
                 Annotation annotation = BooksOnDeviceAccessor.GetAnnotation(book.ID, page.ID);
                 if (annotation != null)
                 {
                     Dictionary <String, PSPDFInkAnnotation> dictionary = AnnotationsDataAccessor.GenerateAnnDictionary((nuint)i, annotation);
                     if (dictionary != null)
                     {
                         List <PSPDFAnnotation> annList = new List <PSPDFAnnotation>();
                         foreach (KeyValuePair <String, PSPDFInkAnnotation> item in dictionary)
                         {
                             annList.Add(item.Value);
                         }
                         this.Document.AddAnnotations(annList.ToArray());
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Logger.WriteLineDebugging("CustomPSPDFViewController - AddAnnotations: {0}", ex.ToString());
     }
 }
示例#3
0
        public bool Generate()
        {
            try
            {
                dict1 = new Dictionary <Page, eBriefingMobile.Annotation>();
                dict2 = new Dictionary <Page, List <eBriefingMobile.Note> >();

                foreach (var page in pageList)
                {
                    // Add annotations to dictionary if necessary
                    if (Annotation == ANNOTATION.WITH)
                    {
                        Annotation ann = BooksOnDeviceAccessor.GetAnnotation(bookID, page.ID);
                        dict1.Add(page, ann);
                    }

                    // Add notes to dictionary if necessary
                    if (Note == NOTE.WITH)
                    {
                        List <Note> noteList = new List <eBriefingMobile.Note>();
                        Note        note     = null;
                        if (String.IsNullOrEmpty(URL.MultipleNoteURL))
                        {
                            note = BooksOnDeviceAccessor.GetNote(bookID, page.ID);
                            if (note != null)
                            {
                                noteList.Add(note);
                                dict2.Add(page, noteList);
                            }
                        }
                        else
                        {
                            noteList = BooksOnDeviceAccessor.GetNotes(bookID, page.ID);
                            if (noteList != null && noteList.Count > 0)
                            {
                                dict2.Add(page, noteList);
                            }
                        }
                    }
                }

                return(GenerateImage(dict1, dict2));
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("PrintHelper - Generate: {0}", ex.ToString());
                return(false);
            }
        }
示例#4
0
        private void GenerateThumbnail(String bookID, String pageID, String text, bool bookmark = false)
        {
            try
            {
                // activityIndicator
                UIActivityIndicatorView activityIndicator = new UIActivityIndicatorView();
                activityIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.White;
                activityIndicator.StartAnimating();
                activityIndicator.HidesWhenStopped = true;
                activityIndicator.Frame            = new RectangleF((this.Frame.Width / 2) - 10, (this.Frame.Height / 2) - 10, 20, 20);
                this.AddSubview(activityIndicator);

                // Generate pdf thumbnail
                Page             page       = null;
                Annotation       annotation = null;
                BackgroundWorker worker     = new BackgroundWorker();
                worker.DoWork += delegate
                {
                    page = BooksOnDeviceAccessor.GetPage(bookID, pageID);

                    if (String.IsNullOrEmpty(text))
                    {
                        annotation = BooksOnDeviceAccessor.GetAnnotation(bookID, pageID);
                    }
                };
                worker.RunWorkerCompleted += delegate
                {
                    this.InvokeOnMainThread(delegate
                    {
                        activityIndicator.StopAnimating();

                        if (page != null)
                        {
                            String localPath = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                            if (!String.IsNullOrEmpty(localPath))
                            {
                                CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localPath);
                                if (pdfDoc != null)
                                {
                                    CGPDFPage pdfPage = pdfDoc.GetPage(1);
                                    if (pdfPage != null)
                                    {
                                        UIImage pdfImg = PDFConverter.Transform2Image(pdfPage, this.Frame.Width);

                                        // pageView
                                        UIImageView pageView = new UIImageView();
                                        pageView.Frame       = new RectangleF(0, (this.Frame.Height / 2) - (pdfImg.Size.Height / 2), pdfImg.Size.Width, pdfImg.Size.Height);

                                        // If this is annotation thumbnail, draw annotation overlay on top of pdf
                                        if (annotation != null)
                                        {
                                            Dictionary <String, PSPDFInkAnnotation> dictionary = AnnotationsDataAccessor.GenerateAnnDictionary((UInt32)page.PageNumber - 1, annotation);
                                            if (dictionary != null)
                                            {
                                                foreach (KeyValuePair <String, PSPDFInkAnnotation> item in dictionary)
                                                {
                                                    // Create full size annotation
                                                    UIImage annImg = DrawAnnotation(item.Key, item.Value);

                                                    if (annImg != null)
                                                    {
                                                        // Scale down the annotation image
                                                        annImg = annImg.Scale(new SizeF(pdfImg.Size.Width, pdfImg.Size.Height));

                                                        // Overlap pdfImg and annImg
                                                        pdfImg = Overlap(pdfImg, annImg);
                                                    }
                                                }
                                            }
                                        }

                                        pageView.Image = pdfImg;
                                        this.AddSubview(pageView);

                                        // THIS IS REQUIRED TO SKIP iCLOUD BACKUP
                                        SkipBackup2iCloud.SetAttribute(localPath);

                                        // Add ribbon if this is bookmark thumbnail
                                        if (bookmark)
                                        {
                                            UIImageView ribbon = new UIImageView();
                                            ribbon.Image       = UIImage.FromBundle("Assets/Buttons/bookmark_solid.png");
                                            ribbon.Frame       = new RectangleF(pageView.Frame.Right - 35, pageView.Frame.Y, 25, 33.78f);
                                            this.AddSubview(ribbon);
                                        }

                                        // Do not add text if this is annotation thumbnail
                                        if (!String.IsNullOrEmpty(text))
                                        {
                                            // titleLabel
                                            UILabel titleLabel         = new UILabel();
                                            titleLabel.Frame           = new RectangleF(0, pageView.Frame.Bottom + 4, this.Frame.Width, 42);
                                            titleLabel.Font            = UIFont.SystemFontOfSize(16f);
                                            titleLabel.BackgroundColor = UIColor.Clear;
                                            titleLabel.TextColor       = eBriefingAppearance.DarkGrayColor;
                                            titleLabel.Lines           = 2;
                                            titleLabel.LineBreakMode   = UILineBreakMode.TailTruncation;
                                            titleLabel.TextAlignment   = UITextAlignment.Center;
                                            titleLabel.Text            = text;
                                            this.AddSubview(titleLabel);
                                        }
                                    }
                                }
                            }
                        }
                    });
                };
                worker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("ThumbnailView - GenerateThumbnail: {0}", ex.ToString());
            }
        }
示例#5
0
        async private void GenerateThumbnail(String bookID, String pageID, String text, bool bookmark = false)
        {
            try
            {
                // spinner
                RTSpinKitView spinner = eBriefingAppearance.GenerateBounceSpinner();
                spinner.Center = this.Center;
                this.AddSubview(spinner);

                // Generate pdf thumbnail
                Page page = await eBriefingService.Run(() => BooksOnDeviceAccessor.GetPage(bookID, pageID));

                Annotation annotation = null;
                if (String.IsNullOrEmpty(text))
                {
                    annotation = await eBriefingService.Run(() => BooksOnDeviceAccessor.GetAnnotation(bookID, pageID));
                }

                spinner.StopAnimating();

                if (page != null)
                {
                    String localPath = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                    if (!String.IsNullOrEmpty(localPath))
                    {
                        CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localPath);
                        if (pdfDoc != null)
                        {
                            CGPDFPage pdfPage = pdfDoc.GetPage(1);
                            if (pdfPage != null)
                            {
                                UIImage pdfImg = ImageHelper.PDF2Image(pdfPage, this.Frame.Width, UIScreen.MainScreen.Scale);

                                // pageView
                                UIImageView pageView = new UIImageView();
                                pageView.Frame = new CGRect(0, (this.Frame.Height / 2) - (pdfImg.Size.Height / 2), pdfImg.Size.Width, pdfImg.Size.Height);

                                // If this is annotation thumbnail, draw annotation overlay on top of pdf
                                if (annotation != null)
                                {
                                    Dictionary <String, PSPDFInkAnnotation> dictionary = AnnotationsDataAccessor.GenerateAnnDictionary((nuint)page.PageNumber - 1, annotation);
                                    if (dictionary != null)
                                    {
                                        foreach (KeyValuePair <String, PSPDFInkAnnotation> item in dictionary)
                                        {
                                            // Create full size annotation
                                            UIImage annImg = ImageHelper.DrawPSPDFAnnotation(item.Key, item.Value);

                                            if (annImg != null)
                                            {
                                                // Scale down the annotation image
                                                annImg = annImg.Scale(new CGSize(pdfImg.Size.Width, pdfImg.Size.Height));

                                                // Overlap pdfImg and annImg
                                                pdfImg = ImageHelper.Overlap(pdfImg, annImg, CGPoint.Empty, CGPoint.Empty, UIScreen.MainScreen.Scale);
                                            }
                                        }
                                    }
                                }

                                pageView.Image = pdfImg;
                                this.AddSubview(pageView);

                                if (pdfImg.Size.Height < this.Frame.Height)
                                {
                                    this.BackgroundColor = UIColor.Clear;
                                }

                                // THIS IS REQUIRED TO SKIP iCLOUD BACKUP
                                SkipBackup2iCloud.SetAttribute(localPath);

                                // Add ribbon if this is bookmark thumbnail
                                if (bookmark)
                                {
                                    UIImageView ribbon = new UIImageView();
                                    ribbon.Image = UIImage.FromBundle("Assets/Buttons/bookmark_solid.png");
                                    ribbon.Frame = new CGRect(pageView.Frame.Right - 35, pageView.Frame.Y, 25, 33.78f);
                                    this.AddSubview(ribbon);
                                }

                                // Do not add text if this is annotation thumbnail
                                if (!String.IsNullOrEmpty(text))
                                {
                                    // titleLabel
                                    UILabel titleLabel = eBriefingAppearance.GenerateLabel(16);
                                    titleLabel.Frame         = new CGRect(0, pageView.Frame.Bottom + 4, this.Frame.Width, 42);
                                    titleLabel.Lines         = 2;
                                    titleLabel.LineBreakMode = UILineBreakMode.TailTruncation;
                                    titleLabel.TextAlignment = UITextAlignment.Center;
                                    titleLabel.Text          = text;
                                    this.AddSubview(titleLabel);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("ThumbnailView - GenerateThumbnail: {0}", ex.ToString());
            }
        }
示例#6
0
        static void HandleGetMyAnnotationsEvent(String bookID, List <Annotation> sAnnotations, bool lastItem)
        {
            try
            {
                List <Annotation> dAnnotations = BooksOnDeviceAccessor.GetAnnotations(bookID);
                if (dAnnotations != null && dAnnotations.Count > 0)
                {
                    foreach (Annotation dAnnotation in dAnnotations)
                    {
                        if (sAnnotations != null && sAnnotations.Count > 0)
                        {
                            foreach (Annotation sAnnotation in sAnnotations)
                            {
                                if (dAnnotation.PageID == sAnnotation.PageID)
                                {
                                    if (dAnnotation.ModifiedUtc < sAnnotation.ModifiedUtc)
                                    {
                                        if (sAnnotation.Removed)
                                        {
                                            // Remove annotation if annotation on the cloud has 'Removed' checked
                                            BooksOnDeviceAccessor.RemoveAnnotation(dAnnotation.BookID, dAnnotation.PageID);
                                        }
                                        else
                                        {
                                            // Update annotation if annotation on the cloud has the latest ModifiedUtc
                                            dAnnotation.BookVersion = sAnnotation.BookVersion;
                                            dAnnotation.Items       = sAnnotation.Items;
                                            dAnnotation.ModifiedUtc = sAnnotation.ModifiedUtc;

                                            BooksOnDeviceAccessor.UpdateAnnotation(dAnnotation);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }

                // Add annotation if the annotation is not on the device
                if (sAnnotations != null && sAnnotations.Count > 0)
                {
                    foreach (Annotation sAnnotation in sAnnotations)
                    {
                        if (!sAnnotation.Removed)
                        {
                            if (BooksOnDeviceAccessor.GetAnnotation(sAnnotation.BookID, sAnnotation.PageID) == null)
                            {
                                BooksOnDeviceAccessor.AddAnnotation(sAnnotation);
                            }
                        }
                    }
                }

                // Check if syncing is done
                if (cancelled)
                {
                    SetReceive(true);

                    CheckReceiveDone();
                }
                else
                {
                    if (lastItem)
                    {
                        SaveMyStuff.GetMyAnnotationsEvent -= HandleGetMyAnnotationsEvent;
                        receiveAnnotations = true;

                        CheckReceiveDone();
                    }
                }
            }
            catch (Exception ex)
            {
                SetReceive(true);

                CheckReceiveDone();

                Logger.WriteLineDebugging("CloudSync - HandleGetMyAnnotationsEvent: {0}", ex.ToString());
            }
        }