diff --git a/DataLayer/EfClasses/UserDefinedItem.cs b/DataLayer/EfClasses/UserDefinedItem.cs index 4643d02e..18bb4fd5 100644 --- a/DataLayer/EfClasses/UserDefinedItem.cs +++ b/DataLayer/EfClasses/UserDefinedItem.cs @@ -42,7 +42,11 @@ namespace DataLayer public string Tags { get => _tags; - set => _tags = sanitize(value); + set + { + _tags = sanitize(value); + ItemChanged?.Invoke(this, nameof(Tags)); + } } public IEnumerable TagsEnumerated => Tags == "" ? new string[0] : Tags.Split(null as char[], StringSplitOptions.RemoveEmptyEntries); @@ -99,10 +103,38 @@ namespace DataLayer #endregion #region LiberatedStatuses - public LiberatedStatus BookStatus { get; set; } - public LiberatedStatus? PdfStatus { get; set; } - #endregion + private LiberatedStatus _bookStatus; + private LiberatedStatus? _pdfStatus; + public LiberatedStatus BookStatus + { + get => _bookStatus; + set + { + if (_bookStatus != value) + { + _bookStatus = value; + ItemChanged?.Invoke(this, nameof(BookStatus)); + } + } + } + public LiberatedStatus? PdfStatus + { + get => _pdfStatus; + set + { + if (_pdfStatus != value) + { + _pdfStatus = value; + ItemChanged?.Invoke(this, nameof(PdfStatus)); + } + } + } + #endregion + /// + /// Occurs when , , or values change. + /// + public static event EventHandler ItemChanged; public override string ToString() => $"{Book} {Rating} {Tags}"; } } diff --git a/FileLiberator/DownloadDecryptBook.cs b/FileLiberator/DownloadDecryptBook.cs index 4acf9681..8dc6eea8 100644 --- a/FileLiberator/DownloadDecryptBook.cs +++ b/FileLiberator/DownloadDecryptBook.cs @@ -52,10 +52,7 @@ namespace FileLiberator if (!moveResults.movedAudioFile) return new StatusHandler { "Cannot find final audio file after decryption" }; - // need to update before Audio_Exists will return true - ApplicationServices.LibraryCommands.UpdateBook(libraryBook.Book, LiberatedStatus.Liberated); - - + libraryBook.Book.UserDefinedItem.BookStatus = LiberatedStatus.Liberated; return new StatusHandler(); } diff --git a/FileLiberator/DownloadPdf.cs b/FileLiberator/DownloadPdf.cs index 0919c841..a9b8815c 100644 --- a/FileLiberator/DownloadPdf.cs +++ b/FileLiberator/DownloadPdf.cs @@ -23,8 +23,7 @@ namespace FileLiberator await downloadPdfAsync(libraryBook, proposedDownloadFilePath); var result = verifyDownload(libraryBook); - var liberatedStatus = result.IsSuccess ? LiberatedStatus.Liberated : LiberatedStatus.NotLiberated; - ApplicationServices.LibraryCommands.UpdatePdf(libraryBook.Book, liberatedStatus); + libraryBook.Book.UserDefinedItem.PdfStatus = result.IsSuccess ? LiberatedStatus.Liberated : LiberatedStatus.NotLiberated; return result; } diff --git a/FileLiberator/FileLiberator.csproj b/FileLiberator/FileLiberator.csproj index 08a7d736..776a70fa 100644 --- a/FileLiberator/FileLiberator.csproj +++ b/FileLiberator/FileLiberator.csproj @@ -7,7 +7,6 @@ - diff --git a/FileLiberator/IProcessableExt.cs b/FileLiberator/IProcessableExt.cs index 3a4339e3..0ba57965 100644 --- a/FileLiberator/IProcessableExt.cs +++ b/FileLiberator/IProcessableExt.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using ApplicationServices; using DataLayer; using Dinah.Core; using Dinah.Core.ErrorHandling; @@ -18,10 +17,8 @@ namespace FileLiberator // when used in foreach: stateful. deferred execution - public static IEnumerable GetValidLibraryBooks(this IProcessable processable) - => DbContexts.GetContext() - .GetLibrary_Flat_NoTracking() - .Where(libraryBook => processable.Validate(libraryBook)); + public static IEnumerable GetValidLibraryBooks(this IProcessable processable, IEnumerable library) + => library.Where(libraryBook => processable.Validate(libraryBook)); public static async Task ProcessSingleAsync(this IProcessable processable, LibraryBook libraryBook, bool validate) { diff --git a/Libation.sln b/Libation.sln index 8d11ecc4..1dcd66ee 100644 --- a/Libation.sln +++ b/Libation.sln @@ -86,7 +86,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dinah.EntityFrameworkCore.T EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AAXClean", "..\AAXClean\AAXClean.csproj", "{94BEB7CC-511D-45AB-9F09-09BE858EE486}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hoopla", "Hoopla\Hoopla.csproj", "{D8F56E5A-3E65-41A6-B7E7-C4515A264B1F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hoopla", "Hoopla\Hoopla.csproj", "{D8F56E5A-3E65-41A6-B7E7-C4515A264B1F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -222,7 +222,7 @@ Global {8BD8E012-F44F-4EE2-A234-D66C14D5FE4B} = {7FBBB086-0807-4998-85BF-6D1A49C8AD05} {1AE65B61-9C05-4C80-ABFF-48F16E22FDF1} = {7FBBB086-0807-4998-85BF-6D1A49C8AD05} {59A10DF3-63EC-43F1-A3BF-4000CFA118D2} = {751093DD-5DBA-463E-ADBE-E05FAFB6983E} - {393B5B27-D15C-4F77-9457-FA14BA8F3C73} = {41CDCC73-9B81-49DD-9570-C54406E852AF} + {393B5B27-D15C-4F77-9457-FA14BA8F3C73} = {7FBBB086-0807-4998-85BF-6D1A49C8AD05} {06882742-27A6-4347-97D9-56162CEC9C11} = {F0CBB7A7-D3FB-41FF-8F47-CF3F6A592249} {2E1F5DB4-40CC-4804-A893-5DCE0193E598} = {41CDCC73-9B81-49DD-9570-C54406E852AF} {9F1AA3DE-962F-469B-82B2-46F93491389B} = {F61184E7-2426-4A13-ACEF-5689928E2CE2} diff --git a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs index 820fbc31..6d604184 100644 --- a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs +++ b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs @@ -50,24 +50,24 @@ namespace LibationWinForms.BookLiberation public static class ProcessorAutomationController { - public static async Task BackupSingleBookAsync(LibraryBook libraryBook, EventHandler completedAction = null) + public static async Task BackupSingleBookAsync(LibraryBook libraryBook) { Serilog.Log.Logger.Information($"Begin {nameof(BackupSingleBookAsync)} {{@DebugInfo}}", new { libraryBook?.Book?.AudibleProductId }); var logMe = LogMe.RegisterForm(); - var backupBook = CreateBackupBook(completedAction, logMe); + var backupBook = CreateBackupBook(logMe); // continue even if libraryBook is null. we'll display even that in the processing box await new BackupSingle(logMe, backupBook, libraryBook).RunBackupAsync(); } - public static async Task BackupAllBooksAsync(EventHandler completedAction = null) + public static async Task BackupAllBooksAsync() { Serilog.Log.Logger.Information("Begin " + nameof(BackupAllBooksAsync)); var automatedBackupsForm = new AutomatedBackupsForm(); var logMe = LogMe.RegisterForm(automatedBackupsForm); - var backupBook = CreateBackupBook(completedAction, logMe); + var backupBook = CreateBackupBook(logMe); await new BackupLoop(logMe, backupBook, automatedBackupsForm).RunBackupAsync(); } @@ -84,19 +84,19 @@ namespace LibationWinForms.BookLiberation await new BackupLoop(logMe, convertBook, automatedBackupsForm).RunBackupAsync(); } - public static async Task BackupAllPdfsAsync(EventHandler completedAction = null) + public static async Task BackupAllPdfsAsync() { Serilog.Log.Logger.Information("Begin " + nameof(BackupAllPdfsAsync)); var automatedBackupsForm = new AutomatedBackupsForm(); var logMe = LogMe.RegisterForm(automatedBackupsForm); - var downloadPdf = CreateProcessable(logMe, completedAction); + var downloadPdf = CreateProcessable(logMe); await new BackupLoop(logMe, downloadPdf, automatedBackupsForm).RunBackupAsync(); } - private static IProcessable CreateBackupBook(EventHandler completedAction, LogMe logMe) + private static IProcessable CreateBackupBook(LogMe logMe) { var downloadPdf = CreateProcessable(logMe); @@ -104,7 +104,6 @@ namespace LibationWinForms.BookLiberation async void onDownloadDecryptBookCompleted(object sender, LibraryBook e) { await downloadPdf.TryProcessAsync(e); - completedAction(sender, e); } var downloadDecryptBook = CreateProcessable(logMe, onDownloadDecryptBookCompleted); @@ -246,7 +245,7 @@ $@" Title: {libraryBook.Book.Title} if (dialogResult == SkipResult) { - ApplicationServices.LibraryCommands.UpdateBook(libraryBook.Book, LiberatedStatus.Error); + libraryBook.Book.UserDefinedItem.BookStatus = LiberatedStatus.Error; LogMe.Info($"Error. Skip: [{libraryBook.Book.AudibleProductId}] {libraryBook.Book.Title}"); } @@ -305,7 +304,7 @@ An error occurred while trying to process this book. protected override async Task RunAsync() { // support for 'skip this time only' requires state. iterators provide this state for free. therefore: use foreach/iterator here - foreach (var libraryBook in Processable.GetValidLibraryBooks()) + foreach (var libraryBook in Processable.GetValidLibraryBooks(ApplicationServices.DbContexts.GetContext().GetLibrary_Flat_NoTracking())) { var keepGoing = await ProcessOneAsync(libraryBook, validate: false); if (!keepGoing) diff --git a/LibationWinForms/LibationWinForms.csproj b/LibationWinForms/LibationWinForms.csproj index 343425c6..7eee10cc 100644 --- a/LibationWinForms/LibationWinForms.csproj +++ b/LibationWinForms/LibationWinForms.csproj @@ -14,6 +14,7 @@ +