private void RemovePendingBooks()
        {
            // Remove pending books
            List <Book> removeList = null;
            List <Book> bookList   = BooksOnDeviceAccessor.GetBooks();

            if (bookList != null)
            {
                foreach (Book b in bookList)
                {
                    if (b.Status == Book.BookStatus.PENDING2DOWNLOAD || b.Status == Book.BookStatus.PENDING2UPDATE)
                    {
                        if (removeList == null)
                        {
                            removeList = new List <Book>();
                        }

                        removeList.Add(b);
                    }
                }

                if (removeList != null)
                {
                    foreach (Book b in removeList)
                    {
                        BooksOnDeviceAccessor.RemoveBook(b.ID);
                    }
                }
            }
        }
Пример #2
0
        void HandleUpdateAvailableBadgeEvent(object sender, EventArgs e)
        {
            try
            {
                List <Book> sBooks = BooksOnServerAccessor.GetBooks();
                List <Book> dBooks = BooksOnDeviceAccessor.GetBooks();

                int count = 0;
                if (sBooks != null && dBooks != null)
                {
                    HashSet <String> dIDs = new HashSet <String>(dBooks.Select(d => d.ID));
                    var results           = sBooks.Where(s => !dIDs.Contains(s.ID)).Where(s => !s.Viewed).ToList();
                    if (results != null)
                    {
                        count = results.Count;
                    }
                }
                else if (sBooks != null)
                {
                    count = sBooks.Where(s => !s.Viewed).ToList().Count;
                }

                UpdateBadge(3, count);
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("eBriefingViewController - HandleUpdateAvailableBadgeEvent: {0}", ex.ToString());
            }
        }
        public void RetrieveBooks()
        {
            List <Book> bookList = BooksOnDeviceAccessor.GetBooks();

            if (bookList == null || bookList.Count == 0)
            {
                if (BookUpdater.Books2Download == null)
                {
                    UpdateStatusLabel();
                }
                else
                {
                    ShowHideStatusLabel(false);

                    LoadCollectionView(bookList);
                }
            }
            else
            {
                bookList.RemoveAll(x => String.IsNullOrEmpty(x.Title) && x.PageCount == 0 && String.IsNullOrEmpty(x.Description) && x.ChapterCount == 0);

                // Hide statusLabel
                ShowHideStatusLabel(false);

                // Load collectionView
                LoadCollectionView(bookList);
            }
        }
            public BookSearchDisplayDelegate(PopoverSearchController parent)
            {
                this.parent = parent;

                myBooks        = BooksOnDeviceAccessor.GetBooks();
                availableBooks = BooksOnServerAccessor.GetBooks();
            }
Пример #5
0
        public static void CheckBooks2Download()
        {
            bool        added    = false;
            List <Book> bookList = BooksOnDeviceAccessor.GetBooks();

            if (bookList != null)
            {
                foreach (Book book in bookList)
                {
                    if (book.Status == Book.BookStatus.DOWNLOADING || book.Status == Book.BookStatus.PENDING2DOWNLOAD)
                    {
                        if (Books2Download == null)
                        {
                            Books2Download = new List <Book>();
                        }

                        // Do not add if Books2Download already has it
                        if (!Books2Download.Contains(book))
                        {
                            added = true;
                            Books2Download.Add(book);
                        }
                    }
                }
            }

            if (added)
            {
                if (NewBookAddedEvent != null)
                {
                    NewBookAddedEvent();
                }
            }
        }
Пример #6
0
        async public static void Check4Update()
        {
            if (BooksOnDeviceAccessor.GetBooks() != null)
            {
                List <Book> bookList = await eBriefingService.Run(() => eBriefingService.StartDownloadBooks());

                if (bookList != null)
                {
                    BookUpdater.DoesBooksNeedUpdate(bookList);
                }
            }
        }
Пример #7
0
 private static void RemoveBooks(String url, String id)
 {
     if (!String.IsNullOrEmpty(URL.ServerURL))
     {
         if (url != URL.ServerURL || id != Settings.UserID)
         {
             List <Book> bookList = BooksOnDeviceAccessor.GetBooks();
             if (bookList != null)
             {
                 BookRemover.RemoveBooks(bookList);
             }
         }
     }
 }
        private void LoadCollectionView()
        {
            // Load collectionView
            if (collectionView != null)
            {
                List <Book> bookList = null;

                // Only show those books that are not on the device
                List <Book> sBooks = BooksOnServerAccessor.GetBooks();
                List <Book> dBooks = BooksOnDeviceAccessor.GetBooks();

                if (sBooks != null && dBooks != null)
                {
                    HashSet <String> dIDs = new HashSet <String>(dBooks.Select(d => d.ID));
                    var results           = sBooks.Where(s => !dIDs.Contains(s.ID)).ToList();
                    if (results != null)
                    {
                        bookList = results;
                    }
                }
                else if (sBooks != null)
                {
                    bookList = sBooks;
                }

                LoadingView.Hide();

                if (bookList == null || bookList.Count == 0)
                {
                    UpdateStatusLabel("There are no more available books.");

                    UpdateAvailableBadge();
                }
                else
                {
                    dataSource = new LibraryDataSource(new List <Book>(bookList), this);
                    dataSource.ItemPressedEvent += HandleItemPressedEvent;
                    dataSource.DownloadEvent    += HandleDownloadEvent;
                    collectionView.Source        = dataSource;
                    collectionView.ReloadData();

                    ShowHideStatusLabel(false);
                }
            }
        }
Пример #9
0
        void CalculateMyBooksBadge()
        {
            try
            {
                int         count  = 0;
                List <Book> dBooks = BooksOnDeviceAccessor.GetBooks();
                if (dBooks != null)
                {
                    count = dBooks.Where(d => d.New && (!String.IsNullOrEmpty(d.Title) && d.PageCount != 0 && d.ChapterCount != 0)).ToList().Count;
                }

                UpdateBadge(0, count);
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("eBriefingViewController - CalculateMyBooksBadge: {0}", ex.ToString());
            }
        }
Пример #10
0
        public static void DoesBooksNeedUpdate(List <Book> booksOnServer)
        {
            List <Book> booksOnDevice = BooksOnDeviceAccessor.GetBooks();

            if (booksOnDevice != null)
            {
                if (Books2Update != null)
                {
                    Books2Update.Clear();
                }

                foreach (Book bookOnDevice in booksOnDevice)
                {
                    if (booksOnServer != null)
                    {
                        List <Book> list = booksOnServer.Where(i => i.ID == bookOnDevice.ID && bookOnDevice.Status == Book.BookStatus.DOWNLOADED && i.Version > bookOnDevice.Version).ToList();
                        if (list != null && list.Count > 0)
                        {
                            foreach (var item in list)
                            {
                                if (Books2Update == null)
                                {
                                    Books2Update = new List <Book>();
                                }

                                item.New    = false;
                                item.Status = Book.BookStatus.ISUPDATE;
                                Books2Update.Add(item);
                            }
                        }
                    }
                }

                if (Books2Update != null && Books2Update.Count > 0)
                {
                    if (UpdateNeededEvent != null)
                    {
                        UpdateNeededEvent(Books2Update.Count);
                    }
                }
            }
        }
Пример #11
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());
            }
        }
Пример #12
0
        private void InitializeTabBarController()
        {
            // My Books
            vc1                          = new MyBooksViewController();
            vc1.Title                    = StringRef.myBooks;
            vc1.RefreshEvent            += HandleRefreshEvent1;
            vc1.UpdateUpdatesBadgeEvent += HandleUpdateUpdatesBadgeEvent;
            vc1.UpdateMyBooksBadgeEvent += HandleUpdateMyBooksBadgeEvent;

            // Favorite
            vc2                          = new FavoriteViewController();
            vc2.Title                    = StringRef.favorites;
            vc2.RefreshEvent            += HandleRefreshEvent2;
            vc2.UpdateUpdatesBadgeEvent += HandleUpdateUpdatesBadgeEvent;

            // Updates
            vc3                          = new UpdateViewController();
            vc3.Title                    = StringRef.updates;
            vc3.RefreshEvent            += HandleRefreshEvent3;
            vc3.ClearUpdatesBadgeEvent  += HandleClearUpdatesBadgeEvent;
            vc3.UpdateUpdatesBadgeEvent += HandleUpdateUpdatesBadgeEvent;
            vc3.UpdateMyBooksBadgeEvent += HandleUpdateMyBooksBadgeEvent;

            // Available
            vc4                            = new LibraryViewController();
            vc4.Title                      = StringRef.available;
            vc4.RefreshEvent              += HandleRefreshEvent4;
            vc4.OpenBookshelfEvent        += HandleOpenBookshelfEvent;
            vc4.UpdateUpdatesBadgeEvent   += HandleUpdateUpdatesBadgeEvent;
            vc4.UpdateMyBooksBadgeEvent   += HandleUpdateMyBooksBadgeEvent;
            vc4.UpdateAvailableBadgeEvent += HandleUpdateAvailableBadgeEvent;
            vc4.UpdateTabLocationEvent    += HandleUpdateTabLocationEvent;

            // tabBarController
            tabBarController = new UITabBarController();
            tabBarController.TabBar.Translucent      = false;
            tabBarController.ViewControllerSelected += HandleViewControllerSelected;
            tabBarController.SetViewControllers(new UIViewController[] {
                vc1,
                vc2,
                vc3,
                vc4
            }, false);

            vc1.TabBarItem.Title = StringRef.myBooks;
            vc1.TabBarItem.Image = UIImage.FromBundle("Assets/Icons/tab0.png");
            vc1.TabBarItem.Tag   = 0;

            vc2.TabBarItem.Title = StringRef.favorites;
            vc2.TabBarItem.Image = UIImage.FromBundle("Assets/Icons/tab1.png");
            vc2.TabBarItem.Tag   = 1;

            vc3.TabBarItem.Title = StringRef.updates;
            vc3.TabBarItem.Image = UIImage.FromBundle("Assets/Icons/tab2.png");
            vc3.TabBarItem.Tag   = 2;

            vc4.TabBarItem.Title = StringRef.available;
            vc4.TabBarItem.Image = UIImage.FromBundle("Assets/Icons/tab3.png");
            vc4.TabBarItem.Tag   = 3;

            tabBarController.View.Hidden = true;
            this.View.AddSubview(tabBarController.View);

            List <Book> dBooks = BooksOnDeviceAccessor.GetBooks();

            if (dBooks != null)
            {
                tabBarController.SelectedIndex = 0;
            }
            else
            {
                tabBarController.SelectedIndex = 3;
            }
        }
Пример #13
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());
            }
        }