From 771d992da718da66319fadf129655137f4e8b6c3 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 2 Jul 2021 15:01:55 -0600 Subject: [PATCH] Added count of items removed from library. --- ApplicationServices/LibraryCommands.cs | 16 +++++++++------- DtoImporterService/LibraryImporter.cs | 2 +- LibationWinForms/Dialogs/IndexLibraryDialog.cs | 3 ++- LibationWinForms/Form1.cs | 3 ++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ApplicationServices/LibraryCommands.cs b/ApplicationServices/LibraryCommands.cs index 3ec19cc7..70ecefb4 100644 --- a/ApplicationServices/LibraryCommands.cs +++ b/ApplicationServices/LibraryCommands.cs @@ -13,10 +13,10 @@ namespace ApplicationServices { public static class LibraryCommands { - public static async Task<(int totalCount, int newCount)> ImportAccountAsync(Func loginCallbackFactoryFunc, params Account[] accounts) + public static async Task<(int totalCount, int newCount, int removedCount)> ImportAccountAsync(Func loginCallbackFactoryFunc, params Account[] accounts) { if (accounts is null || accounts.Length == 0) - return (0, 0); + return (0, 0, 0); try { @@ -25,13 +25,13 @@ namespace ApplicationServices var totalCount = importItems.Count; Log.Logger.Information($"GetAllLibraryItems: Total count {totalCount}"); - var newCount = await importIntoDbAsync(importItems); + (var newCount, var removedCount) = await importIntoDbAsync(importItems); Log.Logger.Information($"Import: New count {newCount}"); await Task.Run(() => SearchEngineCommands.FullReIndex()); Log.Logger.Information("FullReIndex: success"); - return (totalCount, newCount); + return (totalCount, newCount, removedCount); } catch (AudibleApi.Authentication.LoginFailedException lfEx) { @@ -90,14 +90,16 @@ namespace ApplicationServices return dtoItems.Select(d => new ImportItem { DtoItem = d, AccountId = account.AccountId, LocaleName = account.Locale?.Name }).ToList(); } - private static async Task importIntoDbAsync(List importItems) + private static async Task<(ushort newCount, ushort removedCount)> importIntoDbAsync(List importItems) { using var context = DbContexts.GetContext(); var libraryImporter = new LibraryImporter(context); - var newCount = await Task.Run(() => libraryImporter.Import(importItems)); + var newAndRemoved = await Task.Run(() => libraryImporter.Import(importItems)); context.SaveChanges(); - return newCount; + var newCount = (ushort)(newAndRemoved >> 0x10); + var removedCount = (ushort)(newAndRemoved & 0xffff); + return (newCount, removedCount); } public static int UpdateTags(this LibationContext context, Book book, string newTags) diff --git a/DtoImporterService/LibraryImporter.cs b/DtoImporterService/LibraryImporter.cs index 430919c3..76e2103d 100644 --- a/DtoImporterService/LibraryImporter.cs +++ b/DtoImporterService/LibraryImporter.cs @@ -62,7 +62,7 @@ namespace DtoImporterService var qtyNew = newItems.Count(); var qtyRemoved = removedItems.Count(); - return qtyNew; + return (qtyNew << 0x10) | (qtyRemoved & 0xffff); } } } diff --git a/LibationWinForms/Dialogs/IndexLibraryDialog.cs b/LibationWinForms/Dialogs/IndexLibraryDialog.cs index f3b6594c..40f5fa31 100644 --- a/LibationWinForms/Dialogs/IndexLibraryDialog.cs +++ b/LibationWinForms/Dialogs/IndexLibraryDialog.cs @@ -11,6 +11,7 @@ namespace LibationWinForms.Dialogs private Account[] _accounts { get; } public int NewBooksAdded { get; private set; } + public int OldBooksRemoved { get; private set; } public int TotalBooksProcessed { get; private set; } public IndexLibraryDialog(params Account[] accounts) @@ -31,7 +32,7 @@ namespace LibationWinForms.Dialogs try { - (TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.ImportAccountAsync((account) => new WinformResponder(account), _accounts); + (TotalBooksProcessed, NewBooksAdded, OldBooksRemoved) = await LibraryCommands.ImportAccountAsync((account) => new WinformResponder(account), _accounts); } catch (Exception ex) { diff --git a/LibationWinForms/Form1.cs b/LibationWinForms/Form1.cs index 3c4fa133..1e180277 100644 --- a/LibationWinForms/Form1.cs +++ b/LibationWinForms/Form1.cs @@ -284,8 +284,9 @@ namespace LibationWinForms var totalProcessed = dialog.TotalBooksProcessed; var newAdded = dialog.NewBooksAdded; + var oldRemoved = dialog.OldBooksRemoved; - MessageBox.Show($"Total processed: {totalProcessed}\r\nNew: {newAdded}"); + MessageBox.Show($"Total processed: {totalProcessed}\r\nNew: {newAdded}\r\nRemoved: {oldRemoved}"); if (totalProcessed > 0) reloadGrid();