Use abstract static member, add publish script
This commit is contained in:
parent
1668b7c9a1
commit
d48a74912a
12
Source/.config/dotnet-tools.json
Normal file
12
Source/.config/dotnet-tools.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"isRoot": true,
|
||||||
|
"tools": {
|
||||||
|
"frogvall.dotnetbumpversion": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"commands": [
|
||||||
|
"bump-version"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"//": "https://github.com/BalassaMarton/MSBump",
|
|
||||||
BumpRevision: true
|
|
||||||
}
|
|
||||||
@ -1,30 +1,24 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
<Version>8.1.4.1</Version>
|
<EnablePreviewFeatures>True</EnablePreviewFeatures>
|
||||||
|
<Version>8.1.4.16</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<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" />
|
<PackageReference Include="Octokit" Version="0.51.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ApplicationServices\ApplicationServices.csproj" />
|
<ProjectReference Include="..\ApplicationServices\ApplicationServices.csproj" />
|
||||||
<ProjectReference Include="..\AudibleUtilities\AudibleUtilities.csproj" />
|
<ProjectReference Include="..\AudibleUtilities\AudibleUtilities.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<DebugType>embedded</DebugType>
|
||||||
<DebugType>embedded</DebugType>
|
</PropertyGroup>
|
||||||
</PropertyGroup>
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
<DebugType>embedded</DebugType>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
</PropertyGroup>
|
||||||
<DebugType>embedded</DebugType>
|
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||||
</PropertyGroup>
|
<Exec Command="dotnet bump-version revision AppScaffolding.csproj" />
|
||||||
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<EnablePreviewFeatures>True</EnablePreviewFeatures>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -154,15 +154,16 @@ 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 validators = new List<IValidator>();
|
var exceptions = new List<Exception>();
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,25 +5,16 @@ using AudibleApi.Common;
|
|||||||
|
|
||||||
namespace AudibleUtilities
|
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
|
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 class LibraryValidator : IValidator
|
||||||
{
|
{
|
||||||
public IEnumerable<Exception> Validate(IEnumerable<Item> items)
|
public static IEnumerable<Exception> Validate(IEnumerable<Item> items)
|
||||||
{
|
{
|
||||||
var exceptions = new List<Exception>();
|
var exceptions = new List<Exception>();
|
||||||
|
|
||||||
@ -37,7 +28,7 @@ namespace AudibleUtilities
|
|||||||
}
|
}
|
||||||
public class BookValidator : IValidator
|
public class BookValidator : IValidator
|
||||||
{
|
{
|
||||||
public IEnumerable<Exception> Validate(IEnumerable<Item> items)
|
public static IEnumerable<Exception> Validate(IEnumerable<Item> items)
|
||||||
{
|
{
|
||||||
var exceptions = new List<Exception>();
|
var exceptions = new List<Exception>();
|
||||||
|
|
||||||
@ -55,7 +46,7 @@ namespace AudibleUtilities
|
|||||||
}
|
}
|
||||||
public class CategoryValidator : IValidator
|
public class CategoryValidator : IValidator
|
||||||
{
|
{
|
||||||
public IEnumerable<Exception> Validate(IEnumerable<Item> items)
|
public static IEnumerable<Exception> Validate(IEnumerable<Item> items)
|
||||||
{
|
{
|
||||||
var exceptions = new List<Exception>();
|
var exceptions = new List<Exception>();
|
||||||
|
|
||||||
@ -70,7 +61,7 @@ namespace AudibleUtilities
|
|||||||
}
|
}
|
||||||
public class ContributorValidator : IValidator
|
public class ContributorValidator : IValidator
|
||||||
{
|
{
|
||||||
public IEnumerable<Exception> Validate(IEnumerable<Item> items)
|
public static IEnumerable<Exception> Validate(IEnumerable<Item> items)
|
||||||
{
|
{
|
||||||
var exceptions = new List<Exception>();
|
var exceptions = new List<Exception>();
|
||||||
|
|
||||||
@ -84,7 +75,7 @@ namespace AudibleUtilities
|
|||||||
}
|
}
|
||||||
public class SeriesValidator : IValidator
|
public class SeriesValidator : IValidator
|
||||||
{
|
{
|
||||||
public IEnumerable<Exception> Validate(IEnumerable<Item> items)
|
public static IEnumerable<Exception> Validate(IEnumerable<Item> items)
|
||||||
{
|
{
|
||||||
var exceptions = new List<Exception>();
|
var exceptions = new List<Exception>();
|
||||||
|
|
||||||
|
|||||||
@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<EnablePreviewFeatures>True</EnablePreviewFeatures>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- <PackageReference Include="AudibleApi" Version="4.2.2.1" /> -->
|
<PackageReference Include="AudibleApi" Version="4.2.2.1" />
|
||||||
<ProjectReference Include="..\..\..\audible api\AudibleApi\AudibleApi\AudibleApi.csproj" />
|
|
||||||
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,10 +8,8 @@ using Dinah.Core.Collections.Generic;
|
|||||||
|
|
||||||
namespace DtoImporterService
|
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();
|
public Dictionary<string, Book> Cache { get; private set; } = new();
|
||||||
|
|
||||||
private ContributorImporter contributorImporter { get; }
|
private ContributorImporter contributorImporter { get; }
|
||||||
|
|||||||
@ -8,10 +8,8 @@ using Dinah.Core.Collections.Generic;
|
|||||||
|
|
||||||
namespace DtoImporterService
|
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 Dictionary<string, Category> Cache { get; private set; } = new();
|
||||||
|
|
||||||
public CategoryImporter(LibationContext context) : base(context) { }
|
public CategoryImporter(LibationContext context) : base(context) { }
|
||||||
|
|||||||
@ -8,10 +8,8 @@ using Dinah.Core.Collections.Generic;
|
|||||||
|
|
||||||
namespace DtoImporterService
|
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 Dictionary<string, Contributor> Cache { get; private set; } = new();
|
||||||
|
|
||||||
public ContributorImporter(LibationContext context) : base(context) { }
|
public ContributorImporter(LibationContext context) : base(context) { }
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<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'">
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Dinah.Core;
|
|||||||
|
|
||||||
namespace DtoImporterService
|
namespace DtoImporterService
|
||||||
{
|
{
|
||||||
public abstract class ImporterBase<T>
|
public abstract class ImporterBase<TValidate> where TValidate : IValidator
|
||||||
{
|
{
|
||||||
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(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
|
try
|
||||||
{
|
{
|
||||||
var exceptions = Validate(param);
|
var exceptions = TValidate.Validate(param.Select(i => i.DtoItem));
|
||||||
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,16 +46,6 @@ namespace DtoImporterService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract int DoImport(T elements);
|
protected abstract int DoImport(IEnumerable<ImportItem> 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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,10 +7,8 @@ using Dinah.Core.Collections.Generic;
|
|||||||
|
|
||||||
namespace DtoImporterService
|
namespace DtoImporterService
|
||||||
{
|
{
|
||||||
public class LibraryBookImporter : ItemsImporterBase
|
public class LibraryBookImporter : ImporterBase<LibraryValidator>
|
||||||
{
|
{
|
||||||
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)
|
||||||
|
|||||||
@ -8,10 +8,8 @@ using Dinah.Core.Collections.Generic;
|
|||||||
|
|
||||||
namespace DtoImporterService
|
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 Dictionary<string, DataLayer.Series> Cache { get; private set; } = new();
|
||||||
|
|
||||||
public SeriesImporter(LibationContext context) : base(context) { }
|
public SeriesImporter(LibationContext context) : base(context) { }
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<EnablePreviewFeatures>True</EnablePreviewFeatures>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<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>
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
<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>
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
<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>
|
||||||
|
|||||||
@ -5,7 +5,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration>Release</Configuration>
|
<Configuration>Release</Configuration>
|
||||||
<Platform>Any CPU</Platform>
|
<Platform>x64</Platform>
|
||||||
<PublishDir>..\bin\publish\</PublishDir>
|
<PublishDir>..\bin\publish\</PublishDir>
|
||||||
<PublishProtocol>FileSystem</PublishProtocol>
|
<PublishProtocol>FileSystem</PublishProtocol>
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
|||||||
4
Source/publish.bat
Normal file
4
Source/publish.bat
Normal 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
|
||||||
Loading…
x
Reference in New Issue
Block a user