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">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
<Version>8.1.4.31</Version>
</PropertyGroup>
<ItemGroup>

View File

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

View File

@ -154,19 +154,27 @@ namespace AudibleUtilities
#if DEBUG
//System.IO.File.WriteAllText(library_json, AudibleApi.Common.Converter.ToJson(items));
#endif
var exceptions = new List<Exception>();
exceptions.AddRange(IValidator.Validate<LibraryValidator>(items));
exceptions.AddRange(IValidator.Validate<BookValidator>(items));
exceptions.AddRange(IValidator.Validate<CategoryValidator>(items));
exceptions.AddRange(IValidator.Validate<ContributorValidator>(items));
exceptions.AddRange(IValidator.Validate<SeriesValidator>(items));
if (exceptions.Any())
throw new AggregateException(exceptions);
var validators = new List<IValidator>();
validators.AddRange(getValidators());
foreach (var v in validators)
{
var exceptions = v.Validate(items);
if (exceptions is not null && exceptions.Any())
throw new AggregateException(exceptions);
}
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
private async Task<List<Item>> getChildEpisodesAsync(SemaphoreSlim concurrencySemaphore, Item parent)

View File

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

View File

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

View File

@ -8,8 +8,10 @@ using Dinah.Core.Collections.Generic;
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();
private ContributorImporter contributorImporter { get; }

View File

@ -8,8 +8,10 @@ using Dinah.Core.Collections.Generic;
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 CategoryImporter(LibationContext context) : base(context) { }

View File

@ -8,8 +8,10 @@ using Dinah.Core.Collections.Generic;
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 ContributorImporter(LibationContext context) : base(context) { }
@ -89,7 +91,7 @@ namespace DtoImporterService
return hash.Count;
}
private Contributor addContributor(string name, string id = null)
private Contributor addContributor(string name, string id = null)
{
try
{
@ -106,6 +108,6 @@ namespace DtoImporterService
Serilog.Log.Logger.Error(ex, "Error adding contributor. {@DebugInfo}", new { name, id });
throw;
}
}
}
}
}
}

View File

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

View File

@ -7,7 +7,7 @@ using Dinah.Core;
namespace DtoImporterService
{
public abstract class ImporterBase<TValidate> where TValidate : IValidator
public abstract class ImporterBase<T>
{
protected LibationContext DbContext { get; }
@ -18,13 +18,13 @@ namespace DtoImporterService
}
/// <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
{
var exceptions = TValidate.Validate(param.Select(i => i.DtoItem));
var exceptions = Validate(param);
if (exceptions is not null && exceptions.Any())
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
{
public class LibraryBookImporter : ImporterBase<LibraryValidator>
public class LibraryBookImporter : ItemsImporterBase
{
protected override IValidator Validator => new LibraryValidator();
private BookImporter bookImporter { get; }
public LibraryBookImporter(LibationContext context) : base(context)
@ -47,7 +49,7 @@ namespace DtoImporterService
// just use the first
var hash = newItems.ToDictionarySafe(dto => dto.DtoItem.ProductId);
foreach (var kvp in hash)
{
{
var newItem = kvp.Value;
var libraryBook = new LibraryBook(

View File

@ -8,8 +8,10 @@ using Dinah.Core.Collections.Generic;
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 SeriesImporter(LibationContext context) : base(context) { }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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