Use abstract static member, add publish script

This commit is contained in:
Michael Bucari-Tovo 2022-06-25 16:48:23 -06:00
parent 1668b7c9a1
commit d48a74912a
20 changed files with 66 additions and 84 deletions

View File

@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"frogvall.dotnetbumpversion": {
"version": "3.0.1",
"commands": [
"bump-version"
]
}
}
}

View File

@ -1,4 +0,0 @@
{
"//": "https://github.com/BalassaMarton/MSBump",
BumpRevision: true
}

View File

@ -1,30 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Version>8.1.4.1</Version>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
<Version>8.1.4.16</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSBump" Version="2.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Octokit" Version="0.51.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ApplicationServices\ApplicationServices.csproj" />
<ProjectReference Include="..\AudibleUtilities\AudibleUtilities.csproj" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="dotnet bump-version revision AppScaffolding.csproj" />
</Target>
</Project>

View File

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

View File

@ -154,15 +154,16 @@ namespace AudibleUtilities
#if DEBUG
//System.IO.File.WriteAllText(library_json, AudibleApi.Common.Converter.ToJson(items));
#endif
var validators = new List<IValidator>();
validators.AddRange(Validators.GetValidators());
foreach (var v in validators)
{
var exceptions = v.Validate(items);
if (exceptions is not null && exceptions.Any())
throw new AggregateException(exceptions);
}
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);
return items;
}

View File

@ -5,25 +5,16 @@ using AudibleApi.Common;
namespace AudibleUtilities
{
public static class Validators
{
public static IValidator[] GetValidators()
=> new IValidator[]
{
new LibraryValidator(),
new BookValidator(),
new CategoryValidator(),
new ContributorValidator(),
new SeriesValidator(),
};
}
public interface IValidator
{
IEnumerable<Exception> Validate(IEnumerable<Item> items);
public static abstract 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 IEnumerable<Exception> Validate(IEnumerable<Item> items)
public static IEnumerable<Exception> Validate(IEnumerable<Item> items)
{
var exceptions = new List<Exception>();
@ -37,7 +28,7 @@ namespace AudibleUtilities
}
public class BookValidator : IValidator
{
public IEnumerable<Exception> Validate(IEnumerable<Item> items)
public static IEnumerable<Exception> Validate(IEnumerable<Item> items)
{
var exceptions = new List<Exception>();
@ -55,7 +46,7 @@ namespace AudibleUtilities
}
public class CategoryValidator : IValidator
{
public IEnumerable<Exception> Validate(IEnumerable<Item> items)
public static IEnumerable<Exception> Validate(IEnumerable<Item> items)
{
var exceptions = new List<Exception>();
@ -70,7 +61,7 @@ namespace AudibleUtilities
}
public class ContributorValidator : IValidator
{
public IEnumerable<Exception> Validate(IEnumerable<Item> items)
public static IEnumerable<Exception> Validate(IEnumerable<Item> items)
{
var exceptions = new List<Exception>();
@ -84,7 +75,7 @@ namespace AudibleUtilities
}
public class SeriesValidator : IValidator
{
public IEnumerable<Exception> Validate(IEnumerable<Item> items)
public static IEnumerable<Exception> Validate(IEnumerable<Item> items)
{
var exceptions = new List<Exception>();

View File

@ -2,12 +2,11 @@
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup>
<ItemGroup>
<!-- <PackageReference Include="AudibleApi" Version="4.2.2.1" /> -->
<ProjectReference Include="..\..\..\audible api\AudibleApi\AudibleApi\AudibleApi.csproj" />
<PackageReference Include="AudibleApi" Version="4.2.2.1" />
</ItemGroup>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,10 +8,8 @@ using Dinah.Core.Collections.Generic;
namespace DtoImporterService
{
public class SeriesImporter : ItemsImporterBase
public class SeriesImporter : ImporterBase<SeriesValidator>
{
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,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup>
<ItemGroup>

View File

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

View File

@ -5,7 +5,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<Platform>x64</Platform>
<PublishDir>..\bin\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net6.0-windows</TargetFramework>

4
Source/publish.bat Normal file
View File

@ -0,0 +1,4 @@
rmdir bin\Publish /S /Q
dotnet publish LibationWinForms\LibationWinForms.csproj -p:PublishProfile=LibationWinForms\Properties\PublishProfiles\FolderProfile.pubxml
dotnet publish LibationCli\LibationCli.csproj -p:PublishProfile=LibationCli\Properties\PublishProfiles\FolderProfile.pubxml
dotnet publish Hangover\Hangover.csproj -p:PublishProfile=Hangover\Properties\PublishProfiles\FolderProfile.pubxml