Пример #1
0
        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);
                }
            }
        }
Пример #2
0
        public static void RemoveBook(Book book)
        {
            // Remove page images from the file system
            List <Page> pageList = BooksOnDeviceAccessor.GetPages(book.ID);

            if (pageList != null)
            {
                foreach (Page page in pageList)
                {
                    BooksOnDeviceAccessor.RemoveBookmark(book.ID, page.ID);
                    BooksOnDeviceAccessor.RemoveAllNotesForThisPage(book.ID, page.ID);
                    BooksOnDeviceAccessor.RemoveAnnotation(book.ID, page.ID);

                    DownloadedFilesCache.RemoveFile(page.URL);
                }
            }
            BooksOnServerAccessor.RemovePages(book.ID);
            BooksOnDeviceAccessor.RemovePages(book.ID);

            // Remove chapter images from the file system
            List <Chapter> chapterList = BooksOnDeviceAccessor.GetChapters(book.ID);

            if (chapterList != null)
            {
                foreach (Chapter chapter in chapterList)
                {
                    DownloadedFilesCache.RemoveFile(chapter.SmallImageURL);
                    DownloadedFilesCache.RemoveFile(chapter.LargeImageURL);
                }
            }
            BooksOnServerAccessor.RemoveChapters(book.ID);
            BooksOnDeviceAccessor.RemoveChapters(book.ID);

            // Remove book images from the file system
            DownloadedFilesCache.RemoveFile(book.SmallImageURL);
            DownloadedFilesCache.RemoveFile(book.LargeImageURL);

            BooksOnDeviceAccessor.RemoveBook(book.ID);
        }
Пример #3
0
        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());
            }
        }