void HandleDownloadStartEvent(String bookID)
 {
     if (dataSource != null)
     {
         Book book = BooksOnDeviceAccessor.GetBook(bookID);
         if (book != null)
         {
             if (book.Status == Book.BookStatus.UPDATING)
             {
                 dataSource.UpdateStatus(bookID, true);
             }
             else
             {
                 dataSource.UpdateStatus(bookID, false);
             }
         }
     }
 }
示例#2
0
        public BookshelfBookView(Book book, bool updateMenu, BookshelfViewController parentVC) : base(new CGRect(0, 0, 280, 280))
        {
            this.BookshelfBook = book;
            this.updateMenu    = updateMenu;

            this.BackgroundColor     = UIColor.White;
            this.Layer.ShadowColor   = UIColor.Black.CGColor;
            this.Layer.ShadowOpacity = 0.3f;
            this.Layer.ShadowRadius  = 2f;
            this.Layer.ShadowOffset  = new CGSize(5f, 5f);

            // imageView
            imageView       = new UIImageView();
            imageView.Frame = new CGRect(0, 0, this.Frame.Width, 150);
            this.AddSubview(imageView);

            // recognizer
            this.AddGestureRecognizer(new UILongPressGestureRecognizer(this, new Selector("HandleLongPress:")));

            if (!String.IsNullOrEmpty(BookshelfBook.LargeImageURL))
            {
                // imageSpinner
                imageSpinner        = eBriefingAppearance.GenerateBounceSpinner();
                imageSpinner.Center = imageView.Center;
                this.AddSubview(imageSpinner);

                // Download image
                bool exist = FileDownloader.Download(BookshelfBook.LargeImageURL, parentVC);
                if (exist)
                {
                    bool outDated = false;
                    var  item     = BooksOnDeviceAccessor.GetBook(BookshelfBook.ID);
                    if (item != null)
                    {
                        if (item.ImageVersion < BookshelfBook.ImageVersion)
                        {
                            DownloadedFilesCache.RemoveFile(item.LargeImageURL);
                            DownloadedFilesCache.RemoveFile(item.SmallImageURL);

                            outDated = true;
                        }
                    }

                    if (outDated)
                    {
                        FileDownloader.Download(BookshelfBook.LargeImageURL, parentVC, true);
                    }
                    else
                    {
                        UpdateImage(BookshelfBook.LargeImageURL);
                    }
                }
            }

            // favoriteView
            if (BooksDataAccessor.IsFavorite(book.ID))
            {
                AddFavorite();
            }

            if (book.New)
            {
                AddRibbon();
            }

            // titleLabel
            titleLabel               = eBriefingAppearance.GenerateLabel(16);
            titleLabel.Frame         = new CGRect(10, imageView.Frame.Bottom + 8, 260, 21);
            titleLabel.Lines         = 2;
            titleLabel.LineBreakMode = UILineBreakMode.WordWrap;
            titleLabel.Text          = book.Title;
            titleLabel.SizeToFit();
            titleLabel.Frame = new CGRect(10, titleLabel.Frame.Y, 260, titleLabel.Frame.Height);
            this.AddSubview(titleLabel);

            UpdateUI();
        }
示例#3
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());
            }
        }
示例#4
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());
            }
        }
示例#5
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());
            }
        }
示例#6
0
        public static void Start()
        {
            if (Books2Download != null && Books2Download.Count > 0)
            {
                try
                {
                    // Check to see if there is any book that was downloading or updating in progress.
                    // If there is, then resume downloading and do not sort
                    bool sortRequired = true;
                    foreach (Book book in Books2Download)
                    {
                        if (book.Status == Book.BookStatus.DOWNLOADING || book.Status == Book.BookStatus.UPDATING)
                        {
                            sortRequired = false;
                        }
                    }

                    if (sortRequired)
                    {
                        SortBooks();
                    }

                    InProgress  = true;
                    CurrentBook = Books2Download[0];

                    if (CurrentBook.Status == Book.BookStatus.PENDING2UPDATE)
                    {
                        CurrentBook.Status = Book.BookStatus.UPDATING;
                    }
                    else if (CurrentBook.Status == Book.BookStatus.PENDING2DOWNLOAD)
                    {
                        CurrentBook.Status = Book.BookStatus.DOWNLOADING;
                    }

                    BackgroundWorker downloadWorker = new BackgroundWorker();
                    downloadWorker.WorkerSupportsCancellation = true;
                    downloadWorker.DoWork += async delegate
                    {
                        // Get my stuff for this book
                        if (CurrentBook.Status == Book.BookStatus.DOWNLOADING)
                        {
                            if (!CloudSync.SyncingInProgress)
                            {
                                await eBriefingService.Run(() => CloudSync.PullMyStuffs(CurrentBook));
                            }
                        }

                        List <String> fileUrlsToDownload = new List <String>();

                        // Notify UI the start of the downloading
                        ParentViewController.InvokeOnMainThread(delegate
                        {
                            if (DownloadStartEvent != null)
                            {
                                DownloadStartEvent(CurrentBook.ID);
                            }
                        });

                        // Queue up cover images for the book only if the image version is different
                        if (CurrentBook.Status == Book.BookStatus.UPDATING)
                        {
                            Book deviceBook = BooksOnDeviceAccessor.GetBook(CurrentBook.ID);
                            if (deviceBook != null && (deviceBook.ImageVersion != CurrentBook.ImageVersion))
                            {
                                DownloadedFilesCache.RemoveFile(deviceBook.LargeImageURL);
                                DownloadedFilesCache.RemoveFile(deviceBook.SmallImageURL);

                                fileUrlsToDownload.Add(CurrentBook.LargeImageURL);
                                fileUrlsToDownload.Add(CurrentBook.SmallImageURL);
                            }
                        }

                        // Download chapters
                        await eBriefingService.Run(() => DownloadChaptersWork(CurrentBook.ID, fileUrlsToDownload));

                        // Download pages
                        List <Page> pageList = await eBriefingService.Run(() => DownloadPagesWork(CurrentBook.ID));

                        if (pageList != null)
                        {
                            List <Page> differentPageList = Pages2Download(CurrentBook.ID, pageList);
                            foreach (Page page in differentPageList)
                            {
                                fileUrlsToDownload.Add(page.URL);
                            }
                        }

                        // Filter out those files that are already downloaded (Only if the status is DOWNLOADING, not UPDATING)
                        // CoreServices 2.0 will check for updates too since we can check for version number for each file
                        fileUrlsToDownload = RemoveAlreadyDownloadedFiles(fileUrlsToDownload);

                        // Download Start
                        if (fileUrlsToDownload.Count == 0)
                        {
                            QueueDidFinish(null);
                        }
                        else
                        {
                            DownloadPDFsWork(CurrentBook.ID, fileUrlsToDownload);
                        }
                    };
                    downloadWorker.RunWorkerAsync();
                }
                catch (Exception ex)
                {
                    Logger.WriteLineDebugging("BookUpdater - Start: {0}", ex.ToString());
                }
            }
        }