Exemplo n.º 1
0
        private static void PullBookmarksWork(Book book)
        {
            List <Bookmark> sBookmarks = SaveMyStuff.GetMyBookmarks(book.ID);

            if (sBookmarks != null && sBookmarks.Count > 0)
            {
                foreach (var sBookmark in sBookmarks)
                {
                    Bookmark dBookmark = BooksOnDeviceAccessor.GetBookmark(book.ID, sBookmark.PageID);
                    if (dBookmark == null)
                    {
                        // This is a new bookmark from the server
                        BooksOnDeviceAccessor.AddBookmark(sBookmark);
                    }
                    else
                    {
                        if (dBookmark.ModifiedUtc <= sBookmark.ModifiedUtc)
                        {
                            if (sBookmark.Removed)
                            {
                                // Remove bookmark if the bookmark on the cloud has 'Removed' checked
                                BooksOnDeviceAccessor.RemoveBookmark(dBookmark.BookID, dBookmark.PageID);
                            }
                            else
                            {
                                BooksOnDeviceAccessor.UpdateBookmark(sBookmark);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void GetMyStuff(String bookID)
        {
            if (Settings.SyncOn)
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    SaveMyStuff.GetMyBookmarksEvent   += HandleGetMyBookmarksEvent;
                    SaveMyStuff.GetMyNotesEvent       += HandleGetMyNotesEvent;
                    SaveMyStuff.GetMyAnnotationsEvent += HandleGetMyAnnotationsEvent;

                    SaveMyStuff.GetMyBookmarks(bookID, true);
                    SaveMyStuff.GetMyNotes(bookID, true);
                    SaveMyStuff.GetMyAnnotations(bookID, true);
                }
            }
        }
Exemplo n.º 3
0
        static void HandleGetMyBooksEvent(List <Book> sBooks)
        {
            try
            {
                SaveMyStuff.GetMyBooksEvent -= HandleGetMyBooksEvent;

                if (sBooks == null)
                {
                    receiveBookmarks = receiveNotes = receiveAnnotations = true;

                    CheckReceiveDone();
                }
                else
                {
                    List <Book> dBooks = BooksOnDeviceAccessor.GetBooks();
                    if (dBooks != null && dBooks.Count > 0)
                    {
                        foreach (Book dBook in dBooks)
                        {
                            if (sBooks != null && sBooks.Count > 0)
                            {
                                foreach (Book sBook in sBooks)
                                {
                                    if (dBook.ID == sBook.ID)
                                    {
                                        if (dBook.UserModifiedDate < sBook.UserModifiedDate)
                                        {
                                            if (sBook.Removed)
                                            {
                                                // Remove book if book on the cloud has 'Removed' checked
                                                BookRemover.RemoveBook(dBook);
                                            }
                                            else
                                            {
                                                // Update book if book on the cloud has the latest ModifiedUtc
                                                dBook.Version          = sBook.Version;
                                                dBook.IsFavorite       = sBook.IsFavorite;
                                                dBook.UserModifiedDate = sBook.UserModifiedDate;
                                                dBook.UserAddedDate    = DateTime.UtcNow;
                                                dBook.New = true;

                                                BooksOnDeviceAccessor.UpdateBook(dBook);
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    // Add book if the book is not on the device
                    if (sBooks != null && sBooks.Count > 0)
                    {
                        foreach (Book sBook in sBooks)
                        {
                            if (!sBook.Removed)
                            {
                                if (BooksOnDeviceAccessor.GetBook(sBook.ID) == null)
                                {
                                    BooksOnDeviceAccessor.AddBook(sBook);
                                }
                            }
                        }
                    }

                    // Add book details for new books
                    BookDownloader bd = new BookDownloader();
                    bd.DownloadedEvent += (List <Book> bookList) =>
                    {
                        if (bookList != null)
                        {
                            dBooks = BooksOnDeviceAccessor.GetBooks();
                            if (dBooks != null)
                            {
                                foreach (Book dBook in dBooks)
                                {
                                    if (dBook.Status == Book.BookStatus.NONE)
                                    {
                                        foreach (Book nBook in bookList)
                                        {
                                            if (dBook.ID == nBook.ID)
                                            {
                                                dBook.Title              = nBook.Title;
                                                dBook.Description        = nBook.Description;
                                                dBook.ChapterCount       = nBook.ChapterCount;
                                                dBook.PageCount          = nBook.PageCount;
                                                dBook.SmallImageURL      = nBook.SmallImageURL;
                                                dBook.LargeImageURL      = nBook.LargeImageURL;
                                                dBook.ImageVersion       = nBook.ImageVersion;
                                                dBook.ServerAddedDate    = nBook.ServerAddedDate;
                                                dBook.ServerModifiedDate = nBook.ServerModifiedDate;
                                                dBook.UserAddedDate      = nBook.UserAddedDate;
                                                dBook.UserModifiedDate   = nBook.UserModifiedDate;
                                                dBook.Status             = Book.BookStatus.PENDING2DOWNLOAD;
                                                dBook.Removed            = false;
                                                dBook.New    = true;
                                                dBook.Viewed = false;

                                                BooksOnDeviceAccessor.UpdateBook(dBook);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (currentSyncType == SyncType.PULL)
                        {
                            receiveBookmarks = receiveNotes = receiveAnnotations = true;

                            CheckReceiveDone();
                        }
                        else
                        {
                            // Receive Bookmarks, Notes, and Annotations
                            if (sBooks != null)
                            {
                                SaveMyStuff.GetMyBookmarksEvent   += HandleGetMyBookmarksEvent;
                                SaveMyStuff.GetMyNotesEvent       += HandleGetMyNotesEvent;
                                SaveMyStuff.GetMyAnnotationsEvent += HandleGetMyAnnotationsEvent;

                                for (Int32 i = 0; i < sBooks.Count; i++)
                                {
                                    bool lastItem = false;
                                    if (i == sBooks.Count - 1)
                                    {
                                        lastItem = true;
                                    }

                                    SaveMyStuff.GetMyBookmarks(sBooks[i].ID, lastItem);
                                    SaveMyStuff.GetMyNotes(sBooks[i].ID, lastItem);
                                    SaveMyStuff.GetMyAnnotations(sBooks[i].ID, lastItem);
                                }
                            }
                        }
                    };
                    bd.StartDownload();
                }
            }
            catch (Exception ex)
            {
                SetReceive(true);

                CheckReceiveDone();

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