/// <summary>
        /// Handles the entire problem of reviewing each of the selected books. Will pop up a little pop-up
        /// and let the user do a review of each one.
        /// </summary>
        /// <returns></returns>
        public async Task RunSavedReviewEachBook()
        {
            if (SavedSelectedBooks == null)
            {
                return;
            }
            var selectedBooks = SavedSelectedBooks;
            var deleteBook    = SavedDeleteBook;

            // Setup to delete all selected books from the Nook
            EbookReaderProgressControl progress = null;

            if (deleteBook)
            {
                await SetupProgressFolderAsync();

                progress = new EbookReaderProgressControl();
                uiAlternateContent.Visibility = Visibility.Visible;
                uiAlternateContent.Children.Clear();
                uiAlternateContent.Children.Add(progress);
                progress.SetNBooks(selectedBooks.Count);
            }

            var bookdb = BookDataContext.Get();
            var sh     = new ContentDialog()
            {
                Title               = "Review Book",
                PrimaryButtonText   = "OK",
                SecondaryButtonText = "Cancel",
            };
            var reviewlist = new ReviewNoteStatusListControl();

            reviewlist.SetBookList(selectedBooks);
            sh.Content = reviewlist;
            var result = await sh.ShowAsync();

            ;
#if NEVER_EVER_DEFINED
// The old code that did a pop-up per book. The new way does one pop-up with a swipable list.
            foreach (var bookData in selectedBooks)
            {
                var srcfullname = bookData.DownloadData.FullFilePath;
                var fname       = bookData.DownloadData.FileName;
                var nd          = CommonQueries.BookNavigationDataEnsure(bookdb, bookData);
                var sh          = new ContentDialog()
                {
                    Title               = "Review Book",
                    PrimaryButtonText   = "OK",
                    SecondaryButtonText = "Cancel",
                };
                var    review            = new ReviewNoteStatusControl();
                string defaultReviewText = null;
                var    BookData          = bookData;

                review.SetBookData(BookData, defaultReviewText);
                sh.Content = review;
                var result = await sh.ShowAsync();

                switch (result)
                {
                case ContentDialogResult.Primary:
                    review.SaveData();

                    bool deleteOk = true;
                    if (progress != null)
                    {
                        deleteOk = await DeleteDownloadedBookAsync(progress, bookData);
                    }

                    var nav = Navigator.Get();
                    //TODO: setup Rome?? nav.UpdateProjectRome(ControlId, GetCurrBookLocation());
                    break;
                }
                if (deleteBook)
                {
                    // TODO: How to delete it?
                    ;
                }
            }
#endif
        }
Пример #2
0
        private async void OnSend(object sender, RoutedEventArgs e)
        {
            int nok   = 0;
            int nfail = 0;

            var           bookdb        = BookDataContext.Get();
            var           selectedBooks = GetSelectedBooks();
            StorageFolder folder        = (await EBookFolder.GetFolderSilentAsync()).Folder;

            if (folder == null)
            {
                folder = await EBookFolder.PickFolderAsync();
            }
            EbookReaderProgressControl progress = null;

            if (folder != null)
            {
                progress = new EbookReaderProgressControl();
                uiAlternateContent.Visibility = Visibility.Visible;
                uiAlternateContent.Children.Clear();
                uiAlternateContent.Children.Add(progress);
                progress.SetNBooks(selectedBooks.Count);


                foreach (var bookData in selectedBooks)
                {
                    var srcfullname = bookData.DownloadData.FullFilePath;
                    var fname       = bookData.DownloadData.FileName;
                    try
                    {
                        var src = await StorageFile.GetFileFromPathAsync(srcfullname);

                        var exists = await folder.FileExistsAsync(fname);

                        if (!exists)
                        {
                            progress.SetCurrentBook(bookData.Title);
                            Logger.Log($"SEND: sending {fname}");
                            await src.CopyAsync(folder, fname, NameCollisionOption.FailIfExists);
                        }
                        else
                        {
                            progress.AddLog($"No need to send {fname}");
                            Logger.Log($"SEND: no need to send {fname}\n");
                            ; //NOTE: possibly in the future I'll do something useful here -- like offer to
                              // re-copy the file, or verify that it's at least the same size or something.
                        }
                        var nd = CommonQueries.BookNavigationDataEnsure(bookdb, bookData);
                        nd.CurrStatus = BookNavigationData.UserStatus.CopiedToEBookReader;
                        nok++;
                    }
                    catch (Exception ex)
                    {
                        nfail++;
                        progress.AddLog($"ERROR: exception when sending {fname} message {ex.Message}\n");
                        Logger.Log($"ERROR: COPY: exception when copying {fname} message {ex.Message}");
                    }
                }
            }


            Logger.Log($"COPY: OK={nok} FAIL={nfail}\n");

            if (nok > 0)
            {
                CommonQueries.BookSaveChanges(bookdb);
            }
            if (progress != null)
            {
                progress.AddLog($"Book send complete OK={nok} FAIL={nfail}");
                await Task.Delay(5_000); // wait so the user can see something happened.
            }

            // End by closing the dialog box.
            var parent = this.Parent as ContentDialog;

            parent.Hide();
        }
        private async void OnMark(object sender, RoutedEventArgs e)
        {
            int             nok       = 0;
            var             newStatus = NewStatus;
            MarkCommandType mark      = GetCommandType();

            if (mark == MarkCommandType.ChangeStatus)
            {
                newStatus = GetUserStatus();
            }
            var deleteBook = uiDeleteFromReader.IsChecked.Value;

            var bookdb        = BookDataContext.Get();
            var selectedBooks = GetSelectedBooks();

            // Setup to delete all selected books from the Nook
            EbookReaderProgressControl progress = null;

            if (deleteBook && mark != MarkCommandType.ReviewEachBook) // ReviewEachBook does this itself.
            {
                await SetupProgressFolderAsync();

                progress = new EbookReaderProgressControl();
                uiAlternateContent.Visibility = Visibility.Visible;
                uiAlternateContent.Children.Clear();
                uiAlternateContent.Children.Add(progress);
                progress.SetNBooks(selectedBooks.Count);
            }

            switch (mark)
            {
            case MarkCommandType.ChangeStatus:
                foreach (var bookData in selectedBooks)
                {
                    var srcfullname = bookData.DownloadData.FullFilePath;
                    var fname       = bookData.DownloadData.FileName;
                    Logger.Log($"MARK: setting {fname} to {NewStatus}");

                    bool deleteOk = true;
                    if (progress != null)
                    {
                        deleteOk = await DeleteDownloadedBookAsync(progress, bookData);
                    }

                    if (deleteOk)
                    {
                        var nd = CommonQueries.BookNavigationDataEnsure(bookdb, bookData);
                        nd.CurrStatus = newStatus;
                        nok++;
                    }
                }
                break;

            case MarkCommandType.NoChange:
                break;

            case MarkCommandType.ReviewEachBook:
                SavedSelectedBooks = selectedBooks;
                SavedDeleteBook    = deleteBook;
                break;
            }

            if (nok > 0)
            {
                CommonQueries.BookSaveChanges(bookdb);
            }

            if (progress != null)
            {
                progress.AddLog($"Book move complete");
                await Task.Delay(5_000); // wait so the user can see something happened.
            }


            Logger.Log($"COPY: OK={nok}");

            // End by closing the dialog box.
            var parent = this.Parent as ContentDialog;

            parent.Hide();
        }