Prevent same bok being decrypted more than once at a time

This commit is contained in:
Michael Bucari-Tovo 2022-05-08 16:31:24 -06:00
parent 458ea6a377
commit 2afcaebb78
2 changed files with 12 additions and 4 deletions

View File

@ -50,12 +50,12 @@ namespace LibationWinForms.BookLiberation
public static class ProcessorAutomationController
{
public static async Task BackupSingleBookAsync(LibraryBook libraryBook)
public static async Task BackupSingleBookAsync(LibraryBook libraryBook, Action<LibraryBook> onCompleteAction = null)
{
Serilog.Log.Logger.Information($"Begin {nameof(BackupSingleBookAsync)} {{@DebugInfo}}", new { libraryBook?.Book?.AudibleProductId });
var logMe = LogMe.RegisterForm();
var backupBook = CreateBackupBook(logMe);
var backupBook = CreateBackupBook(logMe, onCompleteAction);
// continue even if libraryBook is null. we'll display even that in the processing box
await new BackupSingle(logMe, backupBook, libraryBook).RunBackupAsync();
@ -96,13 +96,14 @@ namespace LibationWinForms.BookLiberation
await new BackupLoop(logMe, downloadPdf, automatedBackupsForm).RunBackupAsync();
}
private static Processable CreateBackupBook(LogMe logMe)
private static Processable CreateBackupBook(LogMe logMe, Action<LibraryBook> onCompleteAction = null)
{
var downloadPdf = CreateProcessable<DownloadPdf, PdfDownloadForm>(logMe);
//Chain pdf download on DownloadDecryptBook.Completed
async void onDownloadDecryptBookCompleted(object sender, LibraryBook e)
{
onCompleteAction?.Invoke(e);
await downloadPdf.TryProcessAsync(e);
}

View File

@ -29,6 +29,7 @@ namespace LibationWinForms
public partial class ProductsGrid : UserControl
{
private static List<string> bookConversionInProgress = new();
public event EventHandler<int> VisibleCountChanged;
// alias
@ -88,8 +89,14 @@ namespace LibationWinForms
return;
}
//don't try to decrypt the same book at the same time.
if (bookConversionInProgress.Contains(libraryBook.Book.AudibleProductId))
return;
bookConversionInProgress.Add(libraryBook.Book.AudibleProductId);
// else: liberate
await BookLiberation.ProcessorAutomationController.BackupSingleBookAsync(libraryBook);
await BookLiberation.ProcessorAutomationController.BackupSingleBookAsync(libraryBook, b => bookConversionInProgress.Remove(b.Book.AudibleProductId));
}
private static void Details_Click(GridEntry liveGridEntry)