private static List <Chapter> DownloadChaptersWork(String bookID, List <String> fileUrlsToDownload) { // If chapters are not downloaded yet or expired, download them again List <Chapter> chapterList = null; if (!BooksOnServerAccessor.HasChapters(bookID) || CurrentBook.Status == Book.BookStatus.UPDATING) { chapterList = eBriefingService.StartDownloadChapters(bookID); if (chapterList != null) { BooksOnServerAccessor.SaveChapters(bookID, chapterList); } } else { // Or get them from the cache chapterList = BooksOnServerAccessor.GetChapters(bookID); } // Queue up cover images for the chapter only if the image version is different if (chapterList != null) { foreach (Chapter serverCh in chapterList) { // Remove cover image if this is an update bool download = false; if (CurrentBook.Status == Book.BookStatus.UPDATING) { Chapter deviceCh = BooksOnDeviceAccessor.GetChapter(CurrentBook.ID, serverCh.ID); if (deviceCh == null) { download = true; } else if (serverCh.ImageVersion != deviceCh.ImageVersion) { DownloadedFilesCache.RemoveFile(deviceCh.LargeImageURL); DownloadedFilesCache.RemoveFile(deviceCh.SmallImageURL); download = true; } } else { download = true; } if (download) { fileUrlsToDownload.Add(serverCh.LargeImageURL); fileUrlsToDownload.Add(serverCh.SmallImageURL); } } } return(chapterList); }
public static void RemoveBookFromDevice(Book book) { if (book != null) { if (book.Status == Book.BookStatus.DOWNLOADING || book.Status == Book.BookStatus.PENDING2DOWNLOAD) { if (book.Status == Book.BookStatus.DOWNLOADING) { // Remove page images from the file system List <Page> pageList = BooksOnServerAccessor.GetPages(book.ID); if (pageList != null) { foreach (Page page in pageList) { DownloadedFilesCache.RemoveFile(page.URL); } } BooksOnServerAccessor.RemovePages(book.ID); // Remove chapter images from the file system List <Chapter> chapterList = BooksOnServerAccessor.GetChapters(book.ID); if (chapterList != null) { foreach (Chapter chapter in chapterList) { DownloadedFilesCache.RemoveFile(chapter.SmallImageURL); DownloadedFilesCache.RemoveFile(chapter.LargeImageURL); } } BooksOnServerAccessor.RemoveChapters(book.ID); } // Remove book images from the file system DownloadedFilesCache.RemoveFile(book.SmallImageURL); DownloadedFilesCache.RemoveFile(book.LargeImageURL); BooksOnDeviceAccessor.RemoveBook(book.ID); // Initialize CurrentBook InitializeFailedURLs(); } else if (book.Status == Book.BookStatus.PENDING2UPDATE || book.Status == Book.BookStatus.UPDATING) { RemoveBookFromBooks2Update(book.ID); BooksOnServerAccessor.RemovePages(book.ID); BooksOnServerAccessor.RemoveChapters(book.ID); } } }
private void UpdateUI() { if (segmentedControl.SelectedSegment == 0) { tableView.Hidden = true; textView.Hidden = false; } else { textView.Hidden = true; tableView.Hidden = false; // tableView if (tableView.Source == null) { tableView.Source = new BookOverviewDataSource(BooksOnServerAccessor.GetChapters(book.ID)); tableView.ReloadData(); } } }
private static void UpdateDatabase(Book book) { try { List <Chapter> chapterList = BooksOnServerAccessor.GetChapters(book.ID); List <Page> pageList = BooksOnServerAccessor.GetPages(book.ID); // Update notes if (BooksOnDeviceAccessor.GetNotes(book.ID) != null) { // Remove orphans BooksOnDeviceAccessor.RemoveOrphanNotes(book.ID, pageList); } // Update bookmarks if (BooksOnDeviceAccessor.GetBookmarks(book.ID) != null) { // Remove orphans BooksOnDeviceAccessor.RemoveOrphanBookmarks(book.ID, pageList); } // Update new chapters if (BooksOnDeviceAccessor.GetChapters(book.ID) == null) { BooksOnDeviceAccessor.AddChapters(book.ID, chapterList); } else { BooksOnDeviceAccessor.UpdateChapters(book.ID, chapterList); } BooksOnDeviceAccessor.MapPagesToChapter(chapterList, pageList); // ML: 4/9/2013 We need to map them after each update // Update new pages if (BooksOnDeviceAccessor.GetPages(book.ID) == null) { BooksOnDeviceAccessor.AddPages(book.ID, pageList); } else { BooksOnDeviceAccessor.UpdatePages(book.ID, pageList); } // Remove chapters and pages list from BooksOnServer because they now exist on the device BooksOnServerAccessor.RemoveChapters(book.ID); BooksOnServerAccessor.RemovePages(book.ID); // Update new book book.New = true; book.Status = Book.BookStatus.DOWNLOADED; book.UserAddedDate = DateTime.UtcNow; if (BooksOnDeviceAccessor.GetBook(book.ID) == null) { BooksOnDeviceAccessor.AddBook(book); } else { if (BooksDataAccessor.IsFavorite(book.ID)) { book.IsFavorite = true; } BooksOnDeviceAccessor.UpdateBook(book); } } catch (Exception ex) { Logger.WriteLineDebugging("BookUpdater - UpdateDatabase: {0}", ex.ToString()); } }