private void RetrieveData()
        {
            chapterList  = BooksOnDeviceAccessor.GetChapters(book.ID);
            bookmarkList = BooksOnDeviceAccessor.GetBookmarks(book.ID);
            noteList     = BooksOnDeviceAccessor.GetNotes(book.ID);
            annList      = BooksOnDeviceAccessor.GetAnnotations(book.ID);

            // Update chapter number for backward compatibililty
            if (chapterList != null && chapterList.Count > 0)
            {
                for (int i = 0; i < chapterList.Count; i++)
                {
                    chapterList[i].ChapterNumber = i + 1;
                }

                BooksOnDeviceAccessor.UpdateChapters(book.ID, chapterList);
            }
        }
Exemple #2
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());
            }
        }