Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"dotnet-sonarscanner": {
"version": "11.0.0",
"version": "11.1.0",
"commands": [
"dotnet-sonarscanner"
]
Expand Down
8 changes: 6 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
interval: monthly
labels:
- "dependencies"
- "github-actions"

- package-ecosystem: "nuget"
directory: "/tests"
schedule:
interval: "weekly"
interval: monthly
ignore:
- dependency-name: "*"
update-types:
- "version-update:semver-patch"
labels:
- "dependencies"
- "nuget"
Expand Down
5 changes: 4 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.103">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
/// Returns Code value from <see cref="CodeAttribute"/> attribute
/// </summary>
/// <param name="value"></param>
/// <returns><see cref="string"/> Code from <see cref="CodeAttribute"/> or <see langword="null"/></returns>
/// <returns><see cref="string"/> Code from <see cref="CodeAttribute"/></returns>
/// <exception cref="ArgumentNullException"></exception>
public static string GetCodeEnumSafe(this Enum value)
{
return GetCodeEnum(value) ?? throw new NullReferenceException("Code Enum Not Found");

Check warning on line 30 in src/OLT.Core.Attribute.Abstractions/Code/OltCodeAttributeExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

'System.NullReferenceException' should not be thrown by user code. (https://rules.sonarsource.com/csharp/RSPEC-112)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ public static class OltAttributeExtensions
/// Gets <see cref="DescriptionAttribute"/>
/// </summary>
/// <param name="value"></param>
/// <returns><see cref="DescriptionAttribute.Description"/> or <seealso cref="Enum"/> ToString() or <see langword="null"/></returns>
public static string? GetDescription(this Enum value)
/// <returns><see cref="DescriptionAttribute.Description"/> or <seealso cref="Enum"/> ToString() </returns>
public static string GetDescription(this Enum value)
{
var attribute = GetAttributeInstance<DescriptionAttribute>(value);
return attribute?.Description ?? value?.ToString();
return attribute?.Description ?? value.ToString();
}


/// <summary>
/// Searches <typeparamref name="TEnum"/> for <see cref="DescriptionAttribute"/> or Name matching string
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;

namespace OLT.Core
Expand All @@ -10,19 +11,22 @@ public interface IOltCommandBus : IOltInjectableScoped
/// Runs Command Validation
/// </summary>
/// <param name="command"></param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <returns></returns>
/// <exception cref="OltCommandHandlerNotFoundException"></exception>
/// <exception cref="OltCommandHandlerMultipleException"></exception>
Task<IOltCommandValidationResult> ValidateAsync(IOltCommand command);
Task<IOltCommandValidationResult> ValidateAsync(IOltCommand command, CancellationToken cancellationToken = default);

/// <summary>
/// Processes Command using <see cref="IOltCommandHandler"/> for <see cref="IOltCommand"/>
/// </summary>
/// <param name="command"></param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <returns></returns>
/// <exception cref="OltCommandHandlerNotFoundException"></exception>
/// <exception cref="OltCommandHandlerMultipleException"></exception>
Task ProcessAsync(IOltCommand command);
[Obsolete("Removing in 10.x, ProcessAsync<T> is deprecated, use IOltCommand<TResult>")]
Task ProcessAsync(IOltCommand command, CancellationToken cancellationToken = default);


/// <summary>
Expand All @@ -40,11 +44,13 @@ public interface IOltCommandBus : IOltInjectableScoped
/// Processes Command using <see cref="IOltCommandHandler"/> for <see cref="IOltCommand"/>
/// </summary>
/// <param name="command"></param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <typeparam name="TResult"><see cref="IOltCommandHandler"/> Returned Result</typeparam>
/// <returns></returns>
/// <exception cref="OltCommandHandlerNotFoundException"></exception>
/// <exception cref="NullReferenceException">Thrown is command result is null</exception>
/// <exception cref="InvalidCastException">Thrown is command result doesn't match handler type</exception>
/// <returns></returns>
Task<TResult> ProcessAsync<TResult>(IOltCommand<TResult> command) where TResult : notnull;
Task<TResult> ProcessAsync<TResult>(IOltCommand<TResult> command, CancellationToken cancellationToken = default) where TResult : notnull;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace OLT.Core
{
[Obsolete("Removing in 10.x, Complete<T> is deprecated, use IOltCommand<TResult> with OltCommandHandler<TCommand, TResult>")]

public record OltCommandResult(object? Result = null) : IOltCommandResult
{
public static OltCommandResult Complete()
{
return new OltCommandResult();
}


[Obsolete("Removing in 10.x, Complete<T> is deprecated, use IOltCommand<TResult> with OltCommandHandler<TCommand, TResult>")]
public static OltCommandResult Complete<T>(T result) //Issue #149
{
return new OltCommandResult(result);
Expand Down
44 changes: 22 additions & 22 deletions src/OLT.Core.CommandBus/OltCommandBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace OLT.Core
Expand All @@ -23,6 +24,8 @@ protected OltCommandBus(
protected virtual TContext Context { get; }
protected virtual List<IOltCommandHandler> Handlers { get; }

public CancellationToken CancellationToken { get; private set; } = CancellationToken.None;

/// <summary>
/// Attempts to locate <see cref="IOltCommandHandler"/> for <see cref="IOltCommand"/>
/// </summary>
Expand Down Expand Up @@ -53,21 +56,23 @@ protected virtual IOltCommandHandler GetHandler(IOltCommand command)
/// <param name="command"></param>
/// <param name="handler"></param>
/// <returns></returns>
protected virtual Task<IOltCommandValidationResult> ValidateAsync(IOltCommandHandler handler, IOltCommand command)
{
protected virtual Task<IOltCommandValidationResult> ValidateAsync_Internal(IOltCommandHandler handler, IOltCommand command)
{
return handler.ValidateAsync(this, command);
}

/// <summary>
/// Validates Command and CommandHandler can Execute
/// </summary>
/// <param name="command"></param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <returns></returns>
/// <exception cref="OltCommandHandlerNotFoundException"></exception>
/// <exception cref="OltCommandHandlerMultipleException"></exception>
public virtual Task<IOltCommandValidationResult> ValidateAsync(IOltCommand command)
/// <exception cref="OltCommandHandlerMultipleException"></exception>
public virtual Task<IOltCommandValidationResult> ValidateAsync(IOltCommand command, CancellationToken cancellationToken = default)
{
return this.ValidateAsync(GetHandler(command), command);
this.CancellationToken = cancellationToken;
return this.ValidateAsync_Internal(GetHandler(command), command);
}

/// <summary>
Expand All @@ -76,9 +81,10 @@ public virtual Task<IOltCommandValidationResult> ValidateAsync(IOltCommand comma
/// <param name="command"></param>
/// <param name="handler"></param>
/// <returns></returns>
[Obsolete("Removing in 10.x, ProcessAsync<T> is deprecated, use IOltCommand<TResult>")]
protected virtual async Task<IOltCommandBusResult> ExecuteAsync(IOltCommandHandler handler, IOltCommand command)
{
var validationResult = await ValidateAsync(handler, command);
var validationResult = await ValidateAsync_Internal(handler, command);
if (!validationResult.Valid)
{
throw validationResult.ToException();
Expand All @@ -95,16 +101,6 @@ protected virtual async Task<IOltCommandBusResult> ExecuteAsync(IOltCommandHandl
}


/////// <summary>
/////// Executes Command
/////// </summary>
/////// <param name="command"></param>
/////// <returns></returns>
////protected virtual Task<IOltCommandBusResult> ExecuteAsync(IOltCommand command)
////{
//// return ExecuteAsync(GetHandler(command), command);
////}

/// <summary>
/// Runs in order (or Queues if in Transaction) the <seealso cref="IOltPostCommandHandler.PostExecuteAsync(IOltCommand, IOltCommandResult)"/>
/// </summary>
Expand All @@ -115,7 +111,6 @@ protected virtual async Task<IOltCommandBusResult> ExecuteAsync(IOltCommandHandl
protected virtual async Task PostExecuteAsync<TResult>(IOltCommandHandler currentHandler, IOltCommand command, TResult result)
where TResult: notnull
{

if (currentHandler is IOltPostCommandHandler<TResult> typedPostHandler)
{
PostProcessItems.Enqueue(new OltAfterCommandQueueItem<TResult>(typedPostHandler, command, result));
Expand All @@ -138,12 +133,15 @@ protected virtual async Task PostExecuteAsync<TResult>(IOltCommandHandler curren
/// Processes Command using <see cref="IOltCommandHandler"/> for <see cref="IOltCommand"/>
/// </summary>
/// <param name="command"></param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <returns></returns>
/// <exception cref="OltCommandHandlerNotFoundException"></exception>
/// <exception cref="OltCommandHandlerMultipleException"></exception>
/// <exception cref="OltValidationException"></exception>
public virtual Task ProcessAsync(IOltCommand command)
[Obsolete("Removing in 10.x, ProcessAsync<T> is deprecated, use IOltCommand<TResult>")]
public virtual Task ProcessAsync(IOltCommand command, CancellationToken cancellationToken = default)
{
this.CancellationToken = cancellationToken;
return ExecuteAsync(GetHandler(command), command);
}

Expand All @@ -165,20 +163,22 @@ public virtual async Task<T> ProcessAsync<T>(IOltCommand command)
}




/// <summary>
/// Processes Command using <see cref="IOltCommandHandler"/> for <see cref="IOltCommand"/>
/// </summary>
/// <param name="command"></param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <typeparam name="TResult"><see cref="IOltCommandHandler"/> Returned Result</typeparam>
/// <returns></returns>
/// <exception cref="OltCommandHandlerNotFoundException"></exception>
/// <exception cref="NullReferenceException">Thrown is command result is null</exception>
/// <exception cref="OltValidationException"></exception>
/// <exception cref="InvalidCastException"></exception>
/// <returns></returns>
public virtual async Task<TResult> ProcessAsync<TResult>(IOltCommand<TResult> command) where TResult : notnull
public virtual async Task<TResult> ProcessAsync<TResult>(IOltCommand<TResult> command, CancellationToken cancellationToken = default) where TResult : notnull
{
this.CancellationToken = cancellationToken;

var validationResult = await ValidateAsync(command);
if (!validationResult.Valid)
{
Expand All @@ -199,7 +199,7 @@ public virtual async Task<TResult> ProcessAsync<TResult>(IOltCommand<TResult> co
return result;
}

return await ProcessAsync<TResult>((IOltCommand)command);
throw new InvalidCastException($"Unable to cast to {typeof(IOltCommandHandler<TResult>)}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amazon.Extensions.Configuration.SystemsManager" Version="7.0.0" />
<PackageReference Include="Amazon.Extensions.Configuration.SystemsManager" Version="7.1.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.17.1" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.13.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.4.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.5.0" />
</ItemGroup>

</Project>
13 changes: 8 additions & 5 deletions src/OLT.Extensions.General/OltRegExPatterns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ namespace OLT.Constants
{
public static class OltRegExPatterns
{
public static readonly Regex Spaces = new Regex(@"\s+"); //Looks for Spaces
public static readonly Regex DigitsOnly = new Regex(@"[^\d]");
public static readonly Regex DecimalDigitsOnly = new Regex(@"[^\d\.]");
public static readonly Regex RemoveSpecialCharacters = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
public static readonly Regex ZipRegex = new Regex("\\d{5}(-?\\d{4})?");
// Default match timeout to avoid catastrophic backtracking / long-running matches
private static readonly TimeSpan DefaultMatchTimeout = TimeSpan.FromMilliseconds(750);

public static readonly Regex Spaces = new Regex(@"\s+", RegexOptions.None, DefaultMatchTimeout); // Looks for Spaces
public static readonly Regex DigitsOnly = new Regex(@"[^\d]", RegexOptions.None, DefaultMatchTimeout);
public static readonly Regex DecimalDigitsOnly = new Regex(@"[^\d\.]", RegexOptions.None, DefaultMatchTimeout);
public static readonly Regex RemoveSpecialCharacters = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled, DefaultMatchTimeout);
public static readonly Regex ZipRegex = new Regex("\\d{5}(-?\\d{4})?", RegexOptions.None, DefaultMatchTimeout);
}
}
4 changes: 2 additions & 2 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AwesomeAssertions" Version="9.3.0" PrivateAssets="All" />
<PackageReference Include="AwesomeAssertions" Version="9.4.0" PrivateAssets="All" />
<PackageReference Include="Faker.Net" Version="2.0.163" PrivateAssets="All" />
<PackageReference Include="coverlet.collector" Version="6.0.4" PrivateAssets="All">
<PackageReference Include="coverlet.collector" Version="8.0.0" PrivateAssets="All">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading
Loading