Revert preview feature

This commit is contained in:
Michael Bucari-Tovo 2022-06-26 10:42:52 -06:00
parent 888967be31
commit 3ce1f94f87
18 changed files with 58 additions and 45 deletions

View File

@ -2,7 +2,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
<Version>8.1.4.31</Version> <Version>8.1.4.31</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -2,7 +2,6 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -154,19 +154,27 @@ namespace AudibleUtilities
#if DEBUG #if DEBUG
//System.IO.File.WriteAllText(library_json, AudibleApi.Common.Converter.ToJson(items)); //System.IO.File.WriteAllText(library_json, AudibleApi.Common.Converter.ToJson(items));
#endif #endif
var exceptions = new List<Exception>(); var validators = new List<IValidator>();
validators.AddRange(getValidators());
exceptions.AddRange(IValidator.Validate<LibraryValidator>(items)); foreach (var v in validators)
exceptions.AddRange(IValidator.Validate<BookValidator>(items)); {
exceptions.AddRange(IValidator.Validate<CategoryValidator>(items)); var exceptions = v.Validate(items);
exceptions.AddRange(IValidator.Validate<ContributorValidator>(items)); if (exceptions is not null && exceptions.Any())
exceptions.AddRange(IValidator.Validate<SeriesValidator>(items));
if (exceptions.Any())
throw new AggregateException(exceptions); throw new AggregateException(exceptions);
}
return items; return items;
} }
private static List<IValidator> getValidators()
{
var type = typeof(IValidator);
var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => type.IsAssignableFrom(p) && !p.IsInterface);
return types.Select(t => Activator.CreateInstance(t) as IValidator).ToList();
}
#region episodes and podcasts #region episodes and podcasts
private async Task<List<Item>> getChildEpisodesAsync(SemaphoreSlim concurrencySemaphore, Item parent) private async Task<List<Item>> getChildEpisodesAsync(SemaphoreSlim concurrencySemaphore, Item parent)

View File

@ -7,14 +7,11 @@ namespace AudibleUtilities
{ {
public interface IValidator public interface IValidator
{ {
public static abstract IEnumerable<Exception> Validate(IEnumerable<Item> items); IEnumerable<Exception> Validate(IEnumerable<Item> items);
public static IEnumerable<Exception> Validate<T>(IEnumerable<Item> items)
where T : IValidator
=> T.Validate(items);
} }
public class LibraryValidator : IValidator public class LibraryValidator : IValidator
{ {
public static IEnumerable<Exception> Validate(IEnumerable<Item> items) public IEnumerable<Exception> Validate(IEnumerable<Item> items)
{ {
var exceptions = new List<Exception>(); var exceptions = new List<Exception>();
@ -28,7 +25,7 @@ namespace AudibleUtilities
} }
public class BookValidator : IValidator public class BookValidator : IValidator
{ {
public static IEnumerable<Exception> Validate(IEnumerable<Item> items) public IEnumerable<Exception> Validate(IEnumerable<Item> items)
{ {
var exceptions = new List<Exception>(); var exceptions = new List<Exception>();
@ -46,7 +43,7 @@ namespace AudibleUtilities
} }
public class CategoryValidator : IValidator public class CategoryValidator : IValidator
{ {
public static IEnumerable<Exception> Validate(IEnumerable<Item> items) public IEnumerable<Exception> Validate(IEnumerable<Item> items)
{ {
var exceptions = new List<Exception>(); var exceptions = new List<Exception>();
@ -61,7 +58,7 @@ namespace AudibleUtilities
} }
public class ContributorValidator : IValidator public class ContributorValidator : IValidator
{ {
public static IEnumerable<Exception> Validate(IEnumerable<Item> items) public IEnumerable<Exception> Validate(IEnumerable<Item> items)
{ {
var exceptions = new List<Exception>(); var exceptions = new List<Exception>();
@ -75,7 +72,7 @@ namespace AudibleUtilities
} }
public class SeriesValidator : IValidator public class SeriesValidator : IValidator
{ {
public static IEnumerable<Exception> Validate(IEnumerable<Item> items) public IEnumerable<Exception> Validate(IEnumerable<Item> items)
{ {
var exceptions = new List<Exception>(); var exceptions = new List<Exception>();

View File

@ -2,7 +2,6 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -8,8 +8,10 @@ using Dinah.Core.Collections.Generic;
namespace DtoImporterService namespace DtoImporterService
{ {
public class BookImporter : ImporterBase<BookValidator> public class BookImporter : ItemsImporterBase
{ {
protected override IValidator Validator => new BookValidator();
public Dictionary<string, Book> Cache { get; private set; } = new(); public Dictionary<string, Book> Cache { get; private set; } = new();
private ContributorImporter contributorImporter { get; } private ContributorImporter contributorImporter { get; }

View File

@ -8,8 +8,10 @@ using Dinah.Core.Collections.Generic;
namespace DtoImporterService namespace DtoImporterService
{ {
public class CategoryImporter : ImporterBase<CategoryValidator> public class CategoryImporter : ItemsImporterBase
{ {
protected override IValidator Validator => new CategoryValidator();
public Dictionary<string, Category> Cache { get; private set; } = new(); public Dictionary<string, Category> Cache { get; private set; } = new();
public CategoryImporter(LibationContext context) : base(context) { } public CategoryImporter(LibationContext context) : base(context) { }

View File

@ -8,8 +8,10 @@ using Dinah.Core.Collections.Generic;
namespace DtoImporterService namespace DtoImporterService
{ {
public class ContributorImporter : ImporterBase<ContributorValidator> public class ContributorImporter : ItemsImporterBase
{ {
protected override IValidator Validator => new ContributorValidator();
public Dictionary<string, Contributor> Cache { get; private set; } = new(); public Dictionary<string, Contributor> Cache { get; private set; } = new();
public ContributorImporter(LibationContext context) : base(context) { } public ContributorImporter(LibationContext context) : base(context) { }

View File

@ -2,7 +2,6 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@ -7,7 +7,7 @@ using Dinah.Core;
namespace DtoImporterService namespace DtoImporterService
{ {
public abstract class ImporterBase<TValidate> where TValidate : IValidator public abstract class ImporterBase<T>
{ {
protected LibationContext DbContext { get; } protected LibationContext DbContext { get; }
@ -18,13 +18,13 @@ namespace DtoImporterService
} }
/// <summary>LONG RUNNING. call with await Task.Run</summary> /// <summary>LONG RUNNING. call with await Task.Run</summary>
public int Import(IEnumerable<ImportItem> param) => Run(DoImport, param); public int Import(T param) => Run(DoImport, param);
public TResult Run<TResult>(Func<IEnumerable<ImportItem>, TResult> func, IEnumerable<ImportItem> param) public TResult Run<TResult>(Func<T, TResult> func, T param)
{ {
try try
{ {
var exceptions = TValidate.Validate(param.Select(i => i.DtoItem)); var exceptions = Validate(param);
if (exceptions is not null && exceptions.Any()) if (exceptions is not null && exceptions.Any())
throw new AggregateException($"Importer validation failed", exceptions); throw new AggregateException($"Importer validation failed", exceptions);
} }
@ -46,6 +46,16 @@ namespace DtoImporterService
} }
} }
protected abstract int DoImport(IEnumerable<ImportItem> elements); protected abstract int DoImport(T elements);
public abstract IEnumerable<Exception> Validate(T param);
}
public abstract class ItemsImporterBase : ImporterBase<IEnumerable<ImportItem>>
{
protected ItemsImporterBase(LibationContext context) : base(context) { }
protected abstract IValidator Validator { get; }
public sealed override IEnumerable<Exception> Validate(IEnumerable<ImportItem> importItems)
=> Validator.Validate(importItems.Select(i => i.DtoItem));
} }
} }

View File

@ -7,8 +7,10 @@ using Dinah.Core.Collections.Generic;
namespace DtoImporterService namespace DtoImporterService
{ {
public class LibraryBookImporter : ImporterBase<LibraryValidator> public class LibraryBookImporter : ItemsImporterBase
{ {
protected override IValidator Validator => new LibraryValidator();
private BookImporter bookImporter { get; } private BookImporter bookImporter { get; }
public LibraryBookImporter(LibationContext context) : base(context) public LibraryBookImporter(LibationContext context) : base(context)

View File

@ -8,8 +8,10 @@ using Dinah.Core.Collections.Generic;
namespace DtoImporterService namespace DtoImporterService
{ {
public class SeriesImporter : ImporterBase<SeriesValidator> public class SeriesImporter : ItemsImporterBase
{ {
protected override IValidator Validator => new SeriesValidator();
public Dictionary<string, DataLayer.Series> Cache { get; private set; } = new(); public Dictionary<string, DataLayer.Series> Cache { get; private set; } = new();
public SeriesImporter(LibationContext context) : base(context) { } public SeriesImporter(LibationContext context) : base(context) { }

View File

@ -2,7 +2,6 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -6,7 +6,6 @@
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>hangover.ico</ApplicationIcon> <ApplicationIcon>hangover.ico</ApplicationIcon>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
<PublishReadyToRun>true</PublishReadyToRun> <PublishReadyToRun>true</PublishReadyToRun>
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>

View File

@ -5,7 +5,6 @@
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<PublishReadyToRun>true</PublishReadyToRun> <PublishReadyToRun>true</PublishReadyToRun>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath> <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>

View File

@ -6,7 +6,6 @@
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>libation.ico</ApplicationIcon> <ApplicationIcon>libation.ico</ApplicationIcon>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
<AssemblyName>Libation</AssemblyName> <AssemblyName>Libation</AssemblyName>
<PublishReadyToRun>true</PublishReadyToRun> <PublishReadyToRun>true</PublishReadyToRun>

View File

@ -2,8 +2,6 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>

View File

@ -2,8 +2,6 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>