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()); } }
void HandleShowMenuEvent(BookshelfBookView bookView, bool isFavorite) { PopoverMenuController pmc = new PopoverMenuController(bookView, isFavorite); if (bookView.BookshelfBook.Status == Book.BookStatus.DOWNLOADED) { pmc.View.Frame = new CGRect(0, 0, bookView.Frame.Width, 88); } else { pmc.View.Frame = new CGRect(0, 0, bookView.Frame.Width, 44); } pmc.FavoriteEvent += delegate { HideMenuPopover(); dataSource.UpdateFavorite(bookView.BookshelfBook.ID, !isFavorite); if (this.Title != StringRef.myBooks) { UpdateCollectionView(bookView); } }; pmc.RemoveBookEvent += delegate { HideMenuPopover(); UIAlertView alert = new UIAlertView(StringRef.confirmation, "Are you sure you want to remove this book from the Bookshelf?", null, StringRef.no, StringRef.yes); alert.Dismissed += (object sender, UIButtonEventArgs e) => { if (e.ButtonIndex == 1) { BooksOnDeviceAccessor.MarkAsRemovedBook(bookView.BookshelfBook); BookRemover.RemoveBookInCache(bookView.BookshelfBook); BookRemover.RemoveBook(bookView.BookshelfBook); UpdateCollectionView(bookView); } }; alert.Show(); }; pmc.CancelDownloadEvent += delegate { HideMenuPopover(); UIAlertView alert = new UIAlertView(StringRef.confirmation, "Are you sure you want to cancel the download for this book?", null, StringRef.no, StringRef.yes); alert.Dismissed += (object sender, UIButtonEventArgs e) => { if (e.ButtonIndex == 1) { if (bookView.BookshelfBook.Status != Book.BookStatus.DOWNLOADED) { CancelDownload(bookView.BookshelfBook); } } }; alert.Show(); }; menuViewController = new UIPopoverController(pmc); menuViewController.DidDismiss += (object sender, EventArgs e) => { HideMenuPopover(); }; menuViewController.SetPopoverContentSize(new CGSize(pmc.View.Frame.Width, pmc.View.Frame.Height), true); menuViewController.PresentFromRect(bookView.Frame, bookView, UIPopoverArrowDirection.Any, true); }
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()); } }