Added count of items removed from library.
This commit is contained in:
parent
00f7e4b779
commit
771d992da7
@ -13,10 +13,10 @@ namespace ApplicationServices
|
||||
{
|
||||
public static class LibraryCommands
|
||||
{
|
||||
public static async Task<(int totalCount, int newCount)> ImportAccountAsync(Func<Account, ILoginCallback> loginCallbackFactoryFunc, params Account[] accounts)
|
||||
public static async Task<(int totalCount, int newCount, int removedCount)> ImportAccountAsync(Func<Account, ILoginCallback> 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<int> importIntoDbAsync(List<ImportItem> importItems)
|
||||
private static async Task<(ushort newCount, ushort removedCount)> importIntoDbAsync(List<ImportItem> 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)
|
||||
|
||||
@ -62,7 +62,7 @@ namespace DtoImporterService
|
||||
|
||||
var qtyNew = newItems.Count();
|
||||
var qtyRemoved = removedItems.Count();
|
||||
return qtyNew;
|
||||
return (qtyNew << 0x10) | (qtyRemoved & 0xffff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user