diff --git a/ApplicationServices/LibraryCommands.cs b/ApplicationServices/LibraryCommands.cs index 164fcee7..b92eb7d8 100644 --- a/ApplicationServices/LibraryCommands.cs +++ b/ApplicationServices/LibraryCommands.cs @@ -190,7 +190,7 @@ namespace ApplicationServices // below are queries, not commands. maybe I should make a LibraryQueries. except there's already one of those... - public record LibraryStats(int booksFullyBackedUp, int booksDownloadedOnly, int booksNoProgress, int pdfsDownloaded, int pdfsNotDownloaded) { } + public record LibraryStats(int booksFullyBackedUp, int booksDownloadedOnly, int booksNoProgress, int booksError, int pdfsDownloaded, int pdfsNotDownloaded) { } public static LibraryStats GetCounts() { var libraryBooks = DbContexts.GetContext().GetLibrary_Flat_NoTracking(); @@ -202,8 +202,9 @@ namespace ApplicationServices var booksFullyBackedUp = results.Count(r => r == LiberatedStatus.Liberated); var booksDownloadedOnly = results.Count(r => r == LiberatedStatus.PartialDownload); var booksNoProgress = results.Count(r => r == LiberatedStatus.NotLiberated); + var booksError = results.Count(r => r == LiberatedStatus.Error); - Log.Logger.Information("Book counts. {@DebugInfo}", new { total = results.Count, booksFullyBackedUp, booksDownloadedOnly, booksNoProgress }); + Log.Logger.Information("Book counts. {@DebugInfo}", new { total = results.Count, booksFullyBackedUp, booksDownloadedOnly, booksNoProgress, booksError }); var boolResults = libraryBooks .AsParallel() @@ -215,7 +216,7 @@ namespace ApplicationServices Log.Logger.Information("PDF counts. {@DebugInfo}", new { total = boolResults.Count, pdfsDownloaded, pdfsNotDownloaded }); - return new(booksFullyBackedUp, booksDownloadedOnly, booksNoProgress, pdfsDownloaded, pdfsNotDownloaded); + return new(booksFullyBackedUp, booksDownloadedOnly, booksNoProgress, booksError, pdfsDownloaded, pdfsNotDownloaded); } } } diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index d6c118c8..d71ad236 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 5.5.8.3 + 5.5.9.1 diff --git a/LibationSearchEngine/LuceneExtensions.cs b/LibationSearchEngine/LuceneExtensions.cs index 430a50c7..020427d3 100644 --- a/LibationSearchEngine/LuceneExtensions.cs +++ b/LibationSearchEngine/LuceneExtensions.cs @@ -9,24 +9,24 @@ using Lucene.Net.Search; namespace LibationSearchEngine { // field names are case specific and, due to StandardAnalyzer, content is case INspecific - public static class LuceneExtensions + internal static class LuceneExtensions { - public static void AddRaw(this Document document, string name, string value) + internal static void AddRaw(this Document document, string name, string value) => document.Add(new Field(name, value, Field.Store.YES, Field.Index.NOT_ANALYZED)); - public static void AddAnalyzed(this Document document, string name, string value) + internal static void AddAnalyzed(this Document document, string name, string value) { if (value != null) document.Add(new Field(name.ToLowerInvariant(), value, Field.Store.YES, Field.Index.ANALYZED)); } - public static void AddNotAnalyzed(this Document document, string name, string value) + internal static void AddNotAnalyzed(this Document document, string name, string value) => document.Add(new Field(name.ToLowerInvariant(), value, Field.Store.YES, Field.Index.NOT_ANALYZED)); - public static void AddBool(this Document document, string name, bool value) + internal static void AddBool(this Document document, string name, bool value) => document.Add(new Field(name.ToLowerInvariant(), value.ToString(), Field.Store.YES, Field.Index.ANALYZED_NO_NORMS)); - public static Query GetQuery(this Analyzer analyzer, string defaultField, string searchString) + internal static Query GetQuery(this Analyzer analyzer, string defaultField, string searchString) => new QueryParser(SearchEngine.Version, defaultField.ToLowerInvariant(), analyzer).Parse(searchString); // put all numbers, including dates, into this format: diff --git a/LibationWinForms/Dialogs/BookDetailsDialog.cs b/LibationWinForms/Dialogs/BookDetailsDialog.cs index 8a6c6bbf..94391926 100644 --- a/LibationWinForms/Dialogs/BookDetailsDialog.cs +++ b/LibationWinForms/Dialogs/BookDetailsDialog.cs @@ -77,7 +77,6 @@ Purchase Date: {_libraryBook.DateAdded.ToString("d")} if (status == LiberatedStatus.Error) this.bookLiberatedCb.Items.Add(new liberatedComboBoxItem { Status = LiberatedStatus.Error, Text = "Error" }); - setDefaultComboBox(this.bookLiberatedCb, status); } diff --git a/LibationWinForms/Form1.cs b/LibationWinForms/Form1.cs index 134a2123..945204ec 100644 --- a/LibationWinForms/Form1.cs +++ b/LibationWinForms/Form1.cs @@ -50,7 +50,6 @@ namespace LibationWinForms // also applies filter. ONLY call AFTER loading grid loadInitialQuickFilterState(); - } private void Form1_FormClosing(object sender, FormClosingEventArgs e) @@ -172,26 +171,26 @@ namespace LibationWinForms #region bottom: backup counts private async void setBackupCountsAsync(object _, object __) { - LibraryCommands.LibraryStats libraryStats = null; - await Task.Run(() => libraryStats = LibraryCommands.GetCounts()); + var libraryStats = await Task.Run(() => LibraryCommands.GetCounts()); - setBookBackupCounts(libraryStats.booksFullyBackedUp, libraryStats.booksDownloadedOnly, libraryStats.booksNoProgress); - setPdfBackupCounts(libraryStats.pdfsDownloaded, libraryStats.pdfsNotDownloaded); + setBookBackupCounts(libraryStats); + setPdfBackupCounts(libraryStats); } - private void setBookBackupCounts(int booksFullyBackedUp, int booksDownloadedOnly, int booksNoProgress) + private void setBookBackupCounts(LibraryCommands.LibraryStats libraryStats) { var backupsCountsLbl_Format = "BACKUPS: No progress: {0} Encrypted: {1} Fully backed up: {2}"; // enable/disable export - var hasResults = 0 < (booksFullyBackedUp + booksDownloadedOnly + booksNoProgress); + var hasResults = 0 < (libraryStats.booksFullyBackedUp + libraryStats.booksDownloadedOnly + libraryStats.booksNoProgress + libraryStats.booksError); exportLibraryToolStripMenuItem.Enabled = hasResults; // update bottom numbers - var pending = booksNoProgress + booksDownloadedOnly; + var pending = libraryStats.booksNoProgress + libraryStats.booksDownloadedOnly; var statusStripText = !hasResults ? "No books. Begin by importing your library" - : pending > 0 ? string.Format(backupsCountsLbl_Format, booksNoProgress, booksDownloadedOnly, booksFullyBackedUp) - : $"All {"book".PluralizeWithCount(booksFullyBackedUp)} backed up"; + : libraryStats.booksError > 0 ? string.Format(backupsCountsLbl_Format + " Errors: {3}", libraryStats.booksNoProgress, libraryStats.booksDownloadedOnly, libraryStats.booksFullyBackedUp, libraryStats.booksError) + : pending > 0 ? string.Format(backupsCountsLbl_Format, libraryStats.booksNoProgress, libraryStats.booksDownloadedOnly, libraryStats.booksFullyBackedUp) + : $"All {"book".PluralizeWithCount(libraryStats.booksFullyBackedUp)} backed up"; // update menu item var menuItemText @@ -204,26 +203,26 @@ namespace LibationWinForms menuStrip1.UIThread(() => beginBookBackupsToolStripMenuItem.Enabled = pending > 0); menuStrip1.UIThread(() => beginBookBackupsToolStripMenuItem.Text = string.Format(beginBookBackupsToolStripMenuItem_format, menuItemText)); } - private void setPdfBackupCounts(int pdfsDownloaded, int pdfsNotDownloaded) + private void setPdfBackupCounts(LibraryCommands.LibraryStats libraryStats) { var pdfsCountsLbl_Format = "| PDFs: NOT d/l\'ed: {0} Downloaded: {1}"; // update bottom numbers - var hasResults = 0 < (pdfsNotDownloaded + pdfsDownloaded); + var hasResults = 0 < (libraryStats.pdfsNotDownloaded + libraryStats.pdfsDownloaded); var statusStripText = !hasResults ? "" - : pdfsNotDownloaded > 0 ? string.Format(pdfsCountsLbl_Format, pdfsNotDownloaded, pdfsDownloaded) - : $"| All {pdfsDownloaded} PDFs downloaded"; + : libraryStats.pdfsNotDownloaded > 0 ? string.Format(pdfsCountsLbl_Format, libraryStats.pdfsNotDownloaded, libraryStats.pdfsDownloaded) + : $"| All {libraryStats.pdfsDownloaded} PDFs downloaded"; // update menu item var menuItemText - = pdfsNotDownloaded > 0 - ? $"{pdfsNotDownloaded} remaining" + = libraryStats.pdfsNotDownloaded > 0 + ? $"{libraryStats.pdfsNotDownloaded} remaining" : "All PDFs have been downloaded"; // update UI statusStrip1.UIThread(() => pdfsCountsLbl.Text = statusStripText); - menuStrip1.UIThread(() => beginPdfBackupsToolStripMenuItem.Enabled = pdfsNotDownloaded > 0); + menuStrip1.UIThread(() => beginPdfBackupsToolStripMenuItem.Enabled = libraryStats.pdfsNotDownloaded > 0); menuStrip1.UIThread(() => beginPdfBackupsToolStripMenuItem.Text = string.Format(beginPdfBackupsToolStripMenuItem_format, menuItemText)); } #endregion diff --git a/LibationWinForms/LiberateDataGridViewImageButtonColumn.cs b/LibationWinForms/LiberateDataGridViewImageButtonColumn.cs index f1769f36..62d6d2db 100644 --- a/LibationWinForms/LiberateDataGridViewImageButtonColumn.cs +++ b/LibationWinForms/LiberateDataGridViewImageButtonColumn.cs @@ -35,12 +35,14 @@ namespace LibationWinForms private static (string mouseoverText, Bitmap buttonImage) GetLiberateDisplay(LiberatedStatus liberatedStatus, LiberatedStatus? pdfStatus) { + if (liberatedStatus == LiberatedStatus.Error) + return ("Book downloaded ERROR", SystemIcons.Error.ToBitmap()); + (string libState, string image_lib) = liberatedStatus switch { LiberatedStatus.Liberated => ("Liberated", "green"), LiberatedStatus.PartialDownload => ("File has been at least\r\npartially downloaded", "yellow"), LiberatedStatus.NotLiberated => ("Book NOT downloaded", "red"), - LiberatedStatus.Error => ("Book downloaded ERROR", "red"), _ => throw new Exception("Unexpected liberation state") };