Exemplo n.º 1
0
        private static void PullStart()
        {
            if (cancelled)
            {
                SetReceive(true);

                CheckReceiveDone();
            }
            else
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    SaveMyStuff.GetMyBooksEvent += HandleGetMyBooksEvent;
                    SaveMyStuff.GetMyBooks();
                }
                else
                {
                    if (currentSyncType == SyncType.PUSH_AND_PULL)
                    {
                        if (SyncDoneEvent != null)
                        {
                            SyncDoneEvent();
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void PushNotesWork(Book book)
        {
            List <Note> noteList = BooksOnDeviceAccessor.GetAllNotes(book.ID);

            if (noteList != null && noteList.Count > 0)
            {
                if (String.IsNullOrEmpty(URL.MultipleNoteURL))
                {
                    foreach (var note in noteList)
                    {
                        SaveMyStuff.SetMyNote(note);

                        // Remove note marked as Removed
                        if (note.Removed)
                        {
                            BooksOnDeviceAccessor.RemoveNote(note.BookID, note.PageID);
                        }
                    }
                }
                else
                {
                    SaveMyStuff.SetMyNotes(noteList);

                    // Remove notes that are marked as Removed
                    foreach (var note in noteList)
                    {
                        if (note.Removed)
                        {
                            BooksOnDeviceAccessor.RemoveNote(note.BookID, note.NoteID);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
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);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
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.º 5
0
        private static void SendMyAnnotations(List <Book> bookList)
        {
            if (cancelled)
            {
                SetSent(true);

                CheckSentDone();
            }
            else
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    SaveMyStuff.SetMyAnnotationEvent += HandleSetMyAnnotationEvent;

                    foreach (Book book in bookList)
                    {
                        List <Annotation> annotationList = BooksOnDeviceAccessor.GetAllAnnotations(book.ID);
                        if (annotationList != null && annotationList.Count > 0)
                        {
                            for (Int32 i = 0; i < annotationList.Count; i++)
                            {
                                bool lastItem = false;
                                if (i == annotationList.Count - 1)
                                {
                                    lastItem = true;
                                }

                                if (annotationList[i].Removed)
                                {
                                    SaveMyStuff.RemoveMyAnnotation(annotationList[i], lastItem);
                                }
                                else
                                {
                                    SaveMyStuff.SetMyAnnotation(annotationList[i], lastItem);
                                }
                            }
                        }
                        else
                        {
                            sentAnnotations = true;
                        }
                    }

                    // Remove annotation that are marked as removed
                    foreach (Book book in bookList)
                    {
                        List <Annotation> annotationList = BooksOnDeviceAccessor.GetRemovedAnnotations(book.ID);
                        if (annotationList != null && annotationList.Count > 0)
                        {
                            foreach (Annotation annotation in annotationList)
                            {
                                BooksOnDeviceAccessor.RemoveAnnotation(annotation.BookID, annotation.PageID);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        private static void SendMyNotes(List <Book> bookList)
        {
            if (cancelled)
            {
                SetSent(true);

                CheckSentDone();
            }
            else
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    SaveMyStuff.SetMyNoteEvent += HandleSetMyNoteEvent;

                    foreach (Book book in bookList)
                    {
                        List <Note> noteList = BooksOnDeviceAccessor.GetAllNotes(book.ID);
                        if (noteList != null && noteList.Count > 0)
                        {
                            for (Int32 i = 0; i < noteList.Count; i++)
                            {
                                bool lastItem = false;
                                if (i == noteList.Count - 1)
                                {
                                    lastItem = true;
                                }

                                if (noteList[i].Removed)
                                {
                                    SaveMyStuff.RemoveMyNote(noteList[i], lastItem);
                                }
                                else
                                {
                                    SaveMyStuff.SetMyNote(noteList[i], lastItem);
                                }
                            }
                        }
                        else
                        {
                            sentNotes = true;
                        }
                    }

                    // Remove notes that are marked as removed
                    foreach (Book book in bookList)
                    {
                        List <Note> noteList = BooksOnDeviceAccessor.GetRemovedNotes(book.ID);
                        if (noteList != null && noteList.Count > 0)
                        {
                            foreach (Note note in noteList)
                            {
                                BooksOnDeviceAccessor.RemoveNote(note.BookID, note.PageID);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 7
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.º 8
0
        private static void PushBookmarksWork(Book book)
        {
            List <Bookmark> bookmarkList = BooksOnDeviceAccessor.GetAllBookmarks(book.ID);

            if (bookmarkList != null && bookmarkList.Count > 0)
            {
                SaveMyStuff.SetMyBookmarks(bookmarkList);

                // Remove bookmarks that are marked as Removed
                foreach (var bookmark in bookmarkList)
                {
                    if (bookmark.Removed)
                    {
                        BooksOnDeviceAccessor.RemoveBookmark(bookmark.BookID, bookmark.PageID);
                    }
                }
            }
        }
Exemplo n.º 9
0
        private static void SendMyBookmarks(List <Book> bookList)
        {
            if (cancelled)
            {
                SetSent(true);

                CheckSentDone();
            }
            else
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    SaveMyStuff.SetMyBookmarksEvent += HandleSetMyBookmarksEvent;

                    foreach (Book book in bookList)
                    {
                        List <Bookmark> bookmarkList = BooksOnDeviceAccessor.GetAllBookmarks(book.ID);
                        if (bookmarkList != null && bookmarkList.Count > 0)
                        {
                            SaveMyStuff.SetMyBookmarks(bookmarkList);
                        }
                        else
                        {
                            sentBookmarks = true;
                        }
                    }

                    // Remove bookmarks that are marked as removed
                    foreach (Book book in bookList)
                    {
                        List <Bookmark> bookmarkList = BooksOnDeviceAccessor.GetRemovedBookmarks(book.ID);
                        if (bookmarkList != null && bookmarkList.Count > 0)
                        {
                            foreach (Bookmark bookmark in bookmarkList)
                            {
                                BooksOnDeviceAccessor.RemoveBookmark(bookmark.BookID, bookmark.PageID);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        private static void PushAnnotationsWork(Book book)
        {
            List <Annotation> annList = BooksOnDeviceAccessor.GetAllAnnotations(book.ID);

            if (annList != null && annList.Count > 0)
            {
                foreach (var ann in annList)
                {
                    if (ann.Removed)
                    {
                        SaveMyStuff.RemoveMyAnnotation(ann);

                        // Remove annotations that are marked as Removed
                        BooksOnDeviceAccessor.RemoveAnnotation(ann.BookID, ann.PageID);
                    }
                    else
                    {
                        SaveMyStuff.SetMyAnnotation(ann);
                    }
                }
            }
        }
Exemplo n.º 11
0
        private static void PushMyBooksWork()
        {
            try
            {
                List <Book> bookList = BooksOnDeviceAccessor.GetAllBooks();
                if (bookList != null && bookList.Count > 0)
                {
                    SaveMyStuff.SetMyBooks(bookList);

                    // Remove books that are marked as removed
                    List <Book> removeList = BooksOnDeviceAccessor.GetRemovedBooks();
                    if (removeList != null && removeList.Count > 0)
                    {
                        BookRemover.RemoveBooks(removeList);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("CloudSync - PushMyBooksWork: {0}", ex.ToString());
            }
        }
Exemplo n.º 12
0
        private static void SendMyBooks(List <Book> bookList)
        {
            if (cancelled)
            {
                SetSent(true);

                CheckSentDone();
            }
            else
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    SaveMyStuff.SetMyBooksEvent += HandleSetMyBooksEvent;
                    SaveMyStuff.SetMyBooks(bookList);

                    // Remove books that are marked as removed
                    List <Book> removeList = BooksOnDeviceAccessor.GetRemovedBooks();
                    if (removeList != null && removeList.Count > 0)
                    {
                        BookRemover.RemoveBooks(removeList);
                    }
                }
            }
        }
Exemplo n.º 13
0
 public static void DeleteMyStuff()
 {
     SaveMyStuff.DeleteMyStuff();
 }
Exemplo n.º 14
0
 public static void DeleteMyAnnotations()
 {
     SaveMyStuff.DeleteMyAnnotations();
 }
Exemplo n.º 15
0
 public static void DeleteMyBookmarks()
 {
     SaveMyStuff.DeleteMyBookmarks();
 }
Exemplo n.º 16
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());
            }
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        private static void PullMyBooksWork()
        {
            try
            {
                List <Book> sBooks = SaveMyStuff.GetMyBooks();
                if (sBooks != null && sBooks.Count > 0)
                {
                    foreach (var sBook in sBooks)
                    {
                        Book dBook = BooksOnDeviceAccessor.GetBook(sBook.ID);
                        if (dBook == null)
                        {
                            // This is a new book from the server
                            BooksOnDeviceAccessor.AddBook(sBook);
                        }
                        else
                        {
                            if (dBook.ServerModifiedDate <= sBook.ServerModifiedDate)
                            {
                                if (sBook.Removed)
                                {
                                    // Remove bookmark if the bookmark on the cloud has 'Removed' checked
                                    BookRemover.RemoveBook(sBook);
                                }
                                else
                                {
                                    sBook.UserAddedDate = DateTime.UtcNow;
                                    sBook.New           = true;

                                    BooksOnDeviceAccessor.UpdateBook(sBook);
                                }
                            }
                        }
                    }
                }

                // Download detail information about these books
                List <Book> bookList = eBriefingService.StartDownloadBooks();
                if (bookList != null && bookList.Count > 0)
                {
                    List <Book> dBooks = BooksOnDeviceAccessor.GetBooks();
                    if (dBooks != null && dBooks.Count > 0)
                    {
                        foreach (var book in bookList)
                        {
                            var item = dBooks.Where(i => i.ID == book.ID && i.Status == Book.BookStatus.NONE).FirstOrDefault();
                            if (item != null)
                            {
                                book.Status = Book.BookStatus.PENDING2DOWNLOAD;
                                book.New    = true;
                                BooksOnDeviceAccessor.UpdateBook(book);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("CloudSync - PullMyBooksWork: {0}", ex.ToString());
            }
        }