Skip to content

Commit

Permalink
Prepare to deploy 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
GFlisch committed Apr 5, 2024
1 parent c785ae1 commit e462d64
Show file tree
Hide file tree
Showing 20 changed files with 355 additions and 183 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/BuildPreview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
description: 'nuget version number x.y.z'
required: false
type: string
default: '8.1.0'
default: '8.2.0'
nugetPreviewName:
description: 'nuget preview ?'
required: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/BuildRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
description: 'nuget version number x.y.z'
required: false
type: string
default: '8.1.0'
default: '8.2.0'
nugetPackageIdPrefix:
description: 'NuGet PackageId prefix (include the period if necessary)'
required: false
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/CoreBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ jobs:
- name: Change Arc4u.Standard.Configuration.Decryptor versions
run: .\src\Builds\SetVersion.ps1 "..\" "Arc4u.Standard.Configuration.Decryptor.csproj" "1.0.0.0" "${{env.netStandardVersion}}" "0.0.0.0" "${{env.netStandardVersionNuget}}"
shell: powershell
- name: Change Arc4u.Standard.Configuration.Store versions
run: .\src\Builds\SetVersion.ps1 "..\" "Arc4u.Standard.Configuration.Store.csproj" "1.0.0.0" "${{env.netStandardVersion}}" "0.0.0.0" "${{env.netStandardVersionNuget}}"
shell: powershell
- name: Change Arc4u.Configuration.Store.EFCore versions
run: .\src\Builds\SetVersion.ps1 "..\" "Arc4u.Configuration.Store.EFCore.csproj" "1.0.0.0" "${{env.netStandardVersion}}" "0.0.0.0" "${{env.netStandardVersionNuget}}"
shell: powershell
- name: Change Arc4u.Standard.Dependency versions
run: .\src\Builds\SetVersion.ps1 "..\" "Arc4u.Standard.Dependency.csproj" "1.0.0.0" "${{env.netStandardVersion}}" "0.0.0.0" "${{env.netStandardVersionNuget}}"
shell: powershell
Expand Down Expand Up @@ -111,9 +117,12 @@ jobs:
- name: Change Arc4u.Standard.Dispatcher versions
run: .\src\Builds\SetVersion.ps1 "..\" "Arc4u.Standard.Dispatcher.csproj" "1.0.0.0" "${{env.netStandardVersion}}" "0.0.0.0" "${{env.netStandardVersionNuget}}"
shell: powershell
- name: Change Arc4u.Standard.Serializer versions
- name: Change Arc4u.Standard.Results versions
run: .\src\Builds\SetVersion.ps1 "..\" "Arc4u.Standard.Results.csproj" "1.0.0.0" "${{env.netStandardVersion}}" "0.0.0.0" "${{env.netStandardVersionNuget}}"
shell: powershell
- name: Change Arc4u.OAuth2.AspNetCore.Results versions
run: .\src\Builds\SetVersion.ps1 "..\" "Arc4u.OAuth2.AspNetCore.Results.csproj" "1.0.0.0" "${{env.netStandardVersion}}" "0.0.0.0" "${{env.netStandardVersionNuget}}"
shell: powershell
- name: Change Arc4u.Standard.Serializer versions
run: .\src\Builds\SetVersion.ps1 "..\" "Arc4u.Standard.Serializer.csproj" "1.0.0.0" "${{env.netStandardVersion}}" "0.0.0.0" "${{env.netStandardVersionNuget}}"
shell: powershell
Expand Down
41 changes: 41 additions & 0 deletions src/Arc4u.AspNetCore.Results/Arc4u.AspNetCore.Results.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Version>0.0.0.0</Version>
<Authors>Gilles Flisch</Authors>
<Description>Package used on Interface and Facade projects to return ProblemDetails based on Results.</Description>
<Copyright>Gilles Flisch</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>Arc4u.png</PackageIcon>
<PackageProjectUrl>https://github.com/GFlisch/Arc4u</PackageProjectUrl>
<RepositoryUrl>https://github.com/GFlisch/Arc4u</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>Arc4u</PackageTags>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RootNamespace>Arc4u.OAuth2</RootNamespace>
<LangVersion>latest</LangVersion>
<PackageId>Arc4u.AspNetCore.Results</PackageId>
<RootNamespace>$(MSBuildProjectName.Replace(" ", "_").Replace(".Standard", ""))</RootNamespace>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath>
</PackagePath>
</None>
<None Include="..\..\Arc4u.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Arc4u.Standard.Results\Arc4u.Standard.Results.csproj" />
</ItemGroup>
</Project>
134 changes: 134 additions & 0 deletions src/Arc4u.AspNetCore.Results/ProblemDetailExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Arc4u.AspNetCore.Results;
using Arc4u.Results.Validation;
using Arc4u.ServiceModel;
using FluentResults;
using FluentValidation;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Arc4u.Results;

public static class ProblemDetailExtension
{
public static Func<IError, ProblemDetails> FromError => error => _fromError(error);

public static void SetFromErrorFactory(Func<IError, ProblemDetails> fromError)
{
_fromError = fromError;
}
private static Func<IError, ProblemDetails> _fromError = _from;

private static ProblemDetails _from(IError error)
{
if (error is ValidationError validationError)
{
return new ProblemDetails()
.WithTitle("Error from validation.")
.WithDetail(validationError.Message)
.WithStatusCode(StatusCodes.Status422UnprocessableEntity)
.WithSeverity(validationError.Severity.ToString());
}

return new ProblemDetails()
.WithTitle("Error.")
.WithDetail(error.Message)
.WithStatusCode(StatusCodes.Status400BadRequest)
.WithSeverity(Severity.Error.ToString());
}

public static ProblemDetails ToGenericMessage<TResult>(this Result<TResult> result)
{
return ToGenericMessage(result, Activity.Current?.Id);
}

public static ProblemDetails ToGenericMessage<TResult>(this Result<TResult> result, string? activityId)
{
return result.ToResult().ToGenericMessage(activityId);
}

public static ProblemDetails ToGenericMessage(this Result result)
{
return result.ToGenericMessage(Activity.Current?.Id);
}

public static ProblemDetails ToGenericMessage(this Result result, string? activityId)
{
if (result.IsFailed)
{
result.Log();

if (activityId is not null)
{
return new ProblemDetails()
.WithTitle("A technical error occured!")
.WithDetail($"Contact the application owner. A message has been logged with id: {activityId}.")
.WithStatusCode(StatusCodes.Status400BadRequest);
}

return new ProblemDetails()
.WithTitle("A technical error occured!")
.WithDetail("Contact the application owner. A message has been logged.")
.WithStatusCode(StatusCodes.Status400BadRequest);
}

return new ProblemDetails()
.WithTitle("A technical error occured!")
.WithDetail("Contact the application owner.")
.WithStatusCode(StatusCodes.Status400BadRequest);

}

/// <summary>
/// If Success, return the reasons!
/// If Failure and no exceptions, return the Errors: Message, Code, Severity.
/// If Failure and exceptions, Log and return the generic messages.
/// </summary>
/// <typeparam name="TResult"></typeparam>
/// <param name="result"></param>
/// <returns></returns>
public static List<ProblemDetails> ToProblemDetails<TResult>(this Result<TResult> result)
{
if (result.IsSuccess)
{
return new List<ProblemDetails>();
}

if (result.IsFailed && result.Errors.OfType<IExceptionalError>().Any())
{
result.Log();
return new List<ProblemDetails>(new[] { result.ToGenericMessage() });
}

return result.Errors.Select(e => ProblemDetailExtension.FromError(e)).ToList();

}

/// <summary>
/// If Success, return the reasons!
/// If Failure and no exceptions, return the Errors: Message, Code, Severity.
/// If Failure and exceptions, Log and return the generic messages.
/// </summary>
/// <typeparam name="TResult"></typeparam>
/// <param name="result"></param>
/// <returns></returns>
public static List<ProblemDetails> ToProblemDetails(this Result result)
{
if (result.IsSuccess)
{
return result.Reasons.Select(reason => new ProblemDetails().WithDetail(reason.Message).WithSeverity(Severity.Info.ToString())).ToList();
}

if (result.IsFailed && result.Errors.OfType<IExceptionalError>().Any())
{
result.Log();
return new List<ProblemDetails>([result.ToGenericMessage()]);
}

return result.Errors.Select(error => ProblemDetailExtension.FromError(error)).ToList();

}
}
44 changes: 44 additions & 0 deletions src/Arc4u.AspNetCore.Results/ProblemDetailsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using Arc4u.Diagnostics;
using Microsoft.AspNetCore.Mvc;

namespace Arc4u.AspNetCore.Results;
public static class ProblemDetailsExtensions
{
public static ProblemDetails WithStatusCode(this ProblemDetails problemDetails, int statusCode)
{
problemDetails.Status = statusCode;
return problemDetails;
}

public static ProblemDetails WithTitle(this ProblemDetails problemDetails, string title)
{
problemDetails.Title = title;
return problemDetails;
}

public static ProblemDetails WithType(this ProblemDetails problemDetails, Uri type)
{
problemDetails.Type = type.ToString();
return problemDetails;
}

public static ProblemDetails WithDetail(this ProblemDetails problemDetails, string detail)
{
problemDetails.Detail = detail;
return problemDetails;
}

public static ProblemDetails WithCode(this ProblemDetails problemDetails, string code)
{
problemDetails.Extensions.AddOrReplace("Code", code);
return problemDetails;
}

public static ProblemDetails WithSeverity(this ProblemDetails problemDetails, string severity)
{
problemDetails.Extensions.AddOrReplace("Severity", severity);
return problemDetails;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Authors>Gilles Flisch</Authors>
<Description>Core Framework to read configuration from EfCore.</Description>
<Copyright>Gilles Flisch</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>Arc4u.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/GFlisch/Arc4u</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>Arc4u</PackageTags>
<PackageProjectUrl>https://github.com/GFlisch/Arc4u</PackageProjectUrl>
<Version>0.0.0.0</Version>
<LangVersion>latest</LangVersion>
<PackageId>Arc4u.Configuration.Store.EfCore</PackageId>
<RootNamespace>$(MSBuildProjectName.Replace(" ", "_").Replace(".Standard", ""))</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" Condition="'$(TargetFramework)' == 'net7.0'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Authors>Gilles Flisch</Authors>
<Description>Core Framework to read configuration from EfCore.</Description>
<Copyright>Gilles Flisch</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>Arc4u.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/GFlisch/Arc4u</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>Arc4u</PackageTags>
<PackageProjectUrl>https://github.com/GFlisch/Arc4u</PackageProjectUrl>
<Version>0.0.0.0</Version>
<LangVersion>latest</LangVersion>
<PackageId>Arc4u.Configuration.Store</PackageId>
<RootNamespace>$(MSBuildProjectName.Replace(" ", "_").Replace(".Standard", ""))</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
Expand All @@ -25,5 +37,8 @@
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Arc4u.Standard.Configuration\Arc4u.Standard.Configuration.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration;

namespace Arc4u.Configuration.Store.Internals;

Expand Down Expand Up @@ -36,7 +36,9 @@ public SectionStoreConfigurationOptions()
private static void CheckKeyArgument(string key)
{
if (string.IsNullOrWhiteSpace(key))
{
throw new ArgumentNullException(nameof(key), "The key of a section cannot be null");
}
}

public ISectionStoreConfigurationOptions Add<TValue>(string key, TValue? value)
Expand All @@ -59,13 +61,18 @@ public ISectionStoreConfigurationOptions Add<TValue>(string key)
public IReadOnlyList<(string Key, IValueHolder Value)> GetInitialData(IConfigurationBuilder builder)
{
if (_sections.Count == 0)
{
return _objects;
}
else
{
var data = new List<(string Key, IValueHolder Value)>(_objects);
var configurationRoot = builder.Build();
foreach (var valueBuilder in _sections)
{
data.Add((valueBuilder.Key, valueBuilder.Build(configurationRoot)));
}

return data;
}
}
Expand Down
Loading

0 comments on commit e462d64

Please sign in to comment.