Exemple #1
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);
                }
            }
        }
Exemple #2
0
        private static void PullNotesWork(Book book)
        {
            List <Note> sNotes = null;

            if (String.IsNullOrEmpty(URL.MultipleNoteURL))
            {
                sNotes = SaveMyStuff.GetMyNotes(book.ID);
            }
            else
            {
                sNotes = SaveMyStuff.GetMyNotes(book.ID, book.LastSyncedDate);
            }

            if (sNotes != null && sNotes.Count > 0)
            {
                foreach (var sNote in sNotes)
                {
                    Note dNote = null;
                    if (String.IsNullOrEmpty(URL.MultipleNoteURL))
                    {
                        dNote = BooksOnDeviceAccessor.GetNote(book.ID, sNote.PageID);
                    }
                    else
                    {
                        dNote = BooksOnDeviceAccessor.GetNote(book.ID, sNote.NoteID);
                    }

                    if (dNote == null)
                    {
                        // This is a new note from the server
                        BooksOnDeviceAccessor.AddNote(sNote);
                    }
                    else
                    {
                        if (dNote.ModifiedUtc <= sNote.ModifiedUtc)
                        {
                            if (sNote.Removed)
                            {
                                // Remove note if the note on the cloud has 'Removed' checked
                                if (String.IsNullOrEmpty(URL.MultipleNoteURL))
                                {
                                    BooksOnDeviceAccessor.RemoveNote(dNote.BookID, dNote.PageID);
                                }
                                else
                                {
                                    BooksOnDeviceAccessor.RemoveNote(dNote.BookID, dNote.NoteID);
                                }
                            }
                            else
                            {
                                BooksOnDeviceAccessor.UpdateNote(sNote);
                            }
                        }
                    }
                }
            }

            // Update the last time synced for this book
            book.LastSyncedDate = DateTime.UtcNow;
            BooksOnDeviceAccessor.UpdateBook(book);
        }
Exemple #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());
            }
        }