예제 #1
0
        private void SaveAnnotation(nuint pageNumber)
        {
            Page page = BooksOnDeviceAccessor.GetPage(book.ID, (nint)pageNumber + 1);

            if (page != null)
            {
                List <AnnotationItem> inkItems = GenerateParseItem(pageNumber, PSPDFAnnotationType.Ink);
                if (inkItems != null && inkItems.Count > 0)
                {
                    Annotation annotation = new Annotation();
                    annotation.BookID      = book.ID;
                    annotation.BookVersion = book.Version;
                    annotation.PageID      = page.ID;
                    annotation.ModifiedUtc = DateTime.UtcNow;
                    annotation.Items       = inkItems;

                    BooksOnDeviceAccessor.AddAnnotation(annotation);
                    BooksOnDeviceAccessor.UpdateUserModifiedDate(book);
                }
                else
                {
                    BooksOnDeviceAccessor.RemoveAnnotation(book.ID, page.ID);
                    BooksOnDeviceAccessor.UpdateUserModifiedDate(book);
                }
            }
        }
예제 #2
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);
                            }
                        }
                    }
                }
            }
        }
예제 #3
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());
            }
        }