Don't allow multiple simultaneous imports

This commit is contained in:
Robert McRackan 2022-05-06 16:00:37 -04:00
parent ecaa3b9aab
commit 12abbb79b1
2 changed files with 20 additions and 5 deletions

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Version>7.1.0.1</Version>
<Version>7.1.1.1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -15,6 +15,18 @@ namespace ApplicationServices
{
public static class LibraryCommands
{
public static event EventHandler<int> ScanBegin;
public static event EventHandler ScanEnd;
public static bool Scanning { get; private set; }
private static object _lock { get; } = new();
static LibraryCommands()
{
ScanBegin += (_, __) => Scanning = true;
ScanEnd += (_, __) => Scanning = false;
}
public static async Task<List<LibraryBook>> FindInactiveBooks(Func<Account, Task<ApiExtended>> apiExtendedfunc, List<LibraryBook> existingLibrary, params Account[] accounts)
{
logRestart();
@ -72,8 +84,6 @@ namespace ApplicationServices
}
}
public static event EventHandler<int> ScanBegin;
public static event EventHandler ScanEnd;
#region FULL LIBRARY scan and import
public static async Task<(int totalCount, int newCount)> ImportAccountAsync(Func<Account, Task<ApiExtended>> apiExtendedfunc, params Account[] accounts)
{
@ -84,7 +94,12 @@ namespace ApplicationServices
try
{
lock (_lock)
{
if (Scanning)
return (0, 0);
ScanBegin?.Invoke(null, accounts.Length);
}
logTime($"pre {nameof(scanAccountsAsync)} all");
var importItems = await scanAccountsAsync(apiExtendedfunc, accounts, LibraryOptions.ResponseGroupOptions.ALL_OPTIONS);