Ejemplo n.º 1
0
        public static void RemoveBookInCache(Book book)
        {
            // Remove page images from the file system
            List <Page> pageList = BooksOnDeviceAccessor.GetPages(book.ID);

            if (pageList != null)
            {
                foreach (Page page in pageList)
                {
                    DownloadedFilesCache.RemoveFile(page.URL);
                }
            }

            // 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);
                }
            }

            // Remove book images from the file system
            DownloadedFilesCache.RemoveFile(book.SmallImageURL);
            DownloadedFilesCache.RemoveFile(book.LargeImageURL);
        }
        public void RedownloadFailedURLs()
        {
            if (BookUpdater.CurrentBook != null && BookUpdater.CurrentBook.FailedURLs != null)
            {
                ASINetworkQueue networkQueue = new ASINetworkQueue();
                networkQueue.Reset();
                networkQueue.ShowAccurateProgress             = false;
                networkQueue.ShouldCancelAllRequestsOnFailure = false;
                networkQueue.Delegate = this;

                networkQueue.RequestDidFail   = new Selector("requestDidFail:");
                networkQueue.RequestDidFinish = new Selector("requestDidFinish:");
                networkQueue.QueueDidFinish   = new Selector("queueDidFinish:");

                ASIHTTPRequest request = null;
                foreach (String url in BookUpdater.CurrentBook.FailedURLs)
                {
                    DownloadedFilesCache.RemoveFile(url);

                    request = new ASIHTTPRequest(NSUrl.FromString(url));
                    request.DownloadDestinationPath = DownloadedFilesCache.BuildCachedFilePath(url);
                    request.Username = Settings.UserID;
                    request.Password = KeychainAccessor.Password;
                    request.Domain   = Settings.Domain;

                    networkQueue.AddOperation(request);
                }

                // Clear failedUrls before starting to re-download
                BookUpdater.CurrentBook.FailedURLs.Clear();

                networkQueue.Go();
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 //to remove page that not being use anymore in device.
 private static void RemovePages(List <Page> serverPageList, List <Page> devicePageList)
 {
     foreach (Page devicePage in devicePageList)
     {
         var item = serverPageList.Where(i => i.ID == devicePage.ID).FirstOrDefault();
         if (item == null)
         {
             DownloadedFilesCache.RemoveFile(devicePage.URL);
         }
     }
 }
Ejemplo n.º 5
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);
                }
            }
        }
Ejemplo n.º 6
0
        private static void DownloadPDFsWork(String bookID, List <String> urlList)
        {
            if (urlList.Count > 0)
            {
                networkQueue.Reset();
                networkQueue.ShowAccurateProgress             = false;
                networkQueue.ShouldCancelAllRequestsOnFailure = false;
                networkQueue.Delegate = ParentViewController;

                networkQueue.RequestDidFail   = new Selector("requestDidFail:");
                networkQueue.RequestDidFinish = new Selector("requestDidFinish:");
                networkQueue.QueueDidFinish   = new Selector("queueDidFinish:");

                ASIHTTPRequest request = null;
                foreach (String url in urlList)
                {
                    // Remove page if this is an update
                    if (CurrentBook.Status == Book.BookStatus.UPDATING)
                    {
                        DownloadedFilesCache.RemoveFile(url);
                    }

                    request = new ASIHTTPRequest(NSUrl.FromString(url));
                    request.DownloadDestinationPath = DownloadedFilesCache.BuildCachedFilePath(url);
                    request.Username = Settings.UserID;
                    request.Password = KeychainAccessor.Password;
                    request.Domain   = Settings.Domain;

                    networkQueue.AddOperation(request);
                }

                // Clear failedUrls before starting to re-download
                InitializeFailedURLs();

                networkQueue.Go();
            }
            else
            {
                // Finished downloading
                if (DownloadFinishEvent != null)
                {
                    DownloadFinishEvent(bookID);
                }
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public LibraryBookView(Book book, LibraryViewController parentVC) : base(new CGRect(0, 0, 280, 280))
        {
            this.LibraryBook = book;

            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);

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

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

                            outDated = true;
                        }
                    }

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

            // titleLabel
            UILabel 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);

            // bookInfoView
            BookInfoView bookInfoView = new BookInfoView("0", "0", "0", book.PageCount.ToString(), false, false, this.Frame.Width - 30);

            bookInfoView.Frame = new CGRect(10, this.Frame.Bottom - 44, bookInfoView.Frame.Width, bookInfoView.Frame.Height);
            this.AddSubview(bookInfoView);

            // downloadButton
            UIButton downloadButton = UIButton.FromType(UIButtonType.Custom);

            downloadButton.Font = eBriefingAppearance.ThemeBoldFont(14);
            downloadButton.SetTitleColor(eBriefingAppearance.Color("37b878"), UIControlState.Normal);
            downloadButton.SetTitleColor(UIColor.White, UIControlState.Highlighted);
            downloadButton.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/green_unfilled.png").CreateResizableImage(new UIEdgeInsets(15f, 14f, 15f, 14f)), UIControlState.Normal);
            downloadButton.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/green_filled.png").CreateResizableImage(new UIEdgeInsets(15f, 14f, 15f, 14f)), UIControlState.Highlighted);
            downloadButton.Frame = new CGRect(this.Center.X - 65, bookInfoView.Frame.Top - 28, 130, downloadButton.CurrentBackgroundImage.Size.Height);
            downloadButton.SetTitle("DOWNLOAD", UIControlState.Normal);
            downloadButton.TouchUpInside += HandleDownloadButtonTouchUpInside;
            this.AddSubview(downloadButton);
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
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());
                }
            }
        }