Skip to content

Commit

Permalink
Merge pull request #79 from NerosoftDev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Codespilot authored Aug 12, 2024
2 parents bfce69c + 5d16e83 commit 554e4b8
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 28 deletions.
34 changes: 17 additions & 17 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<EnablePackageVersionOverride>true</EnablePackageVersionOverride>
<MicrosoftPackageVersion6>6.0.31</MicrosoftPackageVersion6>
<MicrosoftPackageVersion6>6.0.32</MicrosoftPackageVersion6>
<MicrosoftPackageVersion7>7.0.20</MicrosoftPackageVersion7>
<MicrosoftPackageVersion8>8.0.6</MicrosoftPackageVersion8>
<GrpcAspNetCoreVersion>2.63.0</GrpcAspNetCoreVersion>
<QuartzVersion>3.9.0</QuartzVersion>
<MicrosoftPackageVersion8>8.0.7</MicrosoftPackageVersion8>
<GrpcAspNetCoreVersion>2.65.0</GrpcAspNetCoreVersion>
<QuartzVersion>3.13.0</QuartzVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Apache.NMS.ActiveMQ" Version="2.1.0" />
<PackageVersion Include="Autofac" Version="8.0.0" />
<PackageVersion Include="Autofac.Extensions.DependencyInjection" Version="9.0.0" />
<PackageVersion Include="Autofac.Extras.DynamicProxy" Version="7.1.0" />
<PackageVersion Include="AutoMapper" Version="13.0.1" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.20.0" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.21.2" />
<PackageVersion Include="Castle.Core" Version="5.1.1" />
<PackageVersion Include="Consul" Version="1.6.10.9" />
<PackageVersion Include="FluentValidation" Version="11.9.1" />
<PackageVersion Include="FluentValidation" Version="11.9.2" />
<PackageVersion Include="IdentityModel" Version="7.0.0" />
<PackageVersion Include="IdentityModel.AspNetCore.OAuth2Introspection" Version="6.2.0" />
<PackageVersion Include="Mapster" Version="7.4.0" />
<PackageVersion Include="Mapster.DependencyInjection" Version="1.0.1" />
<PackageVersion Include="MediatR" Version="12.1.1" />
<PackageVersion Include="MediatR.Contracts" Version="2.0.1" />
<PackageVersion Include="mongocsharpdriver" Version="2.25.0" />
<PackageVersion Include="mongocsharpdriver" Version="2.28.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Polly" Version="8.4.0" />
<PackageVersion Include="Polly" Version="8.4.1" />
<PackageVersion Include="protobuf-net" Version="3.1.33" />
<PackageVersion Include="Quartz" Version="$(QuartzVersion)" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="$(QuartzVersion)" />
Expand All @@ -35,14 +35,14 @@
<PackageVersion Include="Refit" Version="6.3.2" />
<PackageVersion Include="Refit.HttpClientFactory" Version="6.3.2" />
<PackageVersion Include="Refit.Newtonsoft.Json" Version="6.3.2" />
<PackageVersion Include="Serilog" Version="4.0.0" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageVersion Include="Serilog.Enrichers.Environment" Version="2.3.0" />
<PackageVersion Include="Serilog" Version="4.0.1" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.2" />
<PackageVersion Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageVersion Include="Serilog.Sinks.Elasticsearch" Version="10.0.0" />
<PackageVersion Include="Serilog.Sinks.Email" Version="3.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageVersion Include="StackExchange.Redis" Version="2.7.33" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageVersion Include="Serilog.Sinks.Email" Version="4.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageVersion Include="StackExchange.Redis" Version="2.8.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.7.0" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
Expand All @@ -51,7 +51,7 @@
<PackageVersion Include="System.Reactive" Version="6.0.1" />
<PackageVersion Include="System.Runtime.Caching" Version="8.0.0" />
<PackageVersion Include="System.Runtime.Loader" Version="4.3.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.3" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
<PackageVersion Include="Winton.Extensions.Configuration.Consul" Version="3.2.0" />
<PackageVersion Include="ZooKeeperNetEx" Version="3.4.12.4" />
</ItemGroup>
Expand Down Expand Up @@ -112,7 +112,7 @@
<!-- Grpc -->
<ItemGroup>
<PackageVersion Include="Google.Api.CommonProtos" Version="2.12.0" />
<PackageVersion Include="Google.Protobuf" Version="3.27.0" />
<PackageVersion Include="Google.Protobuf" Version="3.27.3" />
<PackageVersion Include="Grpc" Version="2.46.6" />
<PackageVersion Include="Grpc.AspNetCore" Version="$(GrpcAspNetCoreVersion)" />
<PackageVersion Include="Grpc.AspNetCore.HealthChecks" Version="$(GrpcAspNetCoreVersion)" />
Expand Down
1 change: 1 addition & 0 deletions Euonia.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution", "Solution", "{CC
NuGet.config = NuGet.config
project.props = project.props
README.md = README.md
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{E57A56F3-7BAB-4DB5-9CE8-EC91985A6586}"
Expand Down
3 changes: 3 additions & 0 deletions Source/Euonia.Bus.Abstract/DefaultIdentityProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Nerosoft.Euonia.Bus;

/// <summary>
/// The default message identity provider.
/// </summary>
internal class DefaultIdentityProvider : IIdentityProvider
{
private readonly IdentityAccessor _accessor;
Expand Down
34 changes: 23 additions & 11 deletions Source/Euonia.Bus/Core/HandlerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public virtual async Task HandleAsync(string channel, object message, MessageCon
return;
}

var tasks = new List<Task>();
using var scope = _provider.GetRequiredService<IServiceScopeFactory>().CreateScope();

if (!_handlerContainer.TryGetValue(channel, out var handling))
Expand All @@ -101,22 +100,35 @@ public virtual async Task HandleAsync(string channel, object message, MessageCon

// Get handler instance from service provider using Expression Tree

foreach (var factory in handling)
if (handling.Count == 0)
{
var handler = factory(scope.ServiceProvider);
tasks.Add(handler(message, context, cancellationToken));
throw new InvalidOperationException("No handler registered for message");
}

if (tasks.Count == 0)
_logger?.LogInformation("Message {Id} is being handled", context.MessageId);

if (handling.Count == 1)
{
return;
var handler = handling.First()(scope.ServiceProvider);
await handler(message, context, cancellationToken);
}

await Task.WhenAll(tasks).ContinueWith(task =>
else
{
task.WaitAndUnwrapException(cancellationToken);
_logger?.LogInformation("Message {Id} was completed handled", context.MessageId);
}, cancellationToken);
await Parallel.ForEachAsync(handling, cancellationToken, async (factory, token) =>
{
try
{
var handler = factory(scope.ServiceProvider);
await handler(message, context, token);
}
catch (Exception ex)
{
_logger?.LogError(ex, "Error occurred while handling message {Id}", context.MessageId);
}
});
}

_logger?.LogInformation("Message {Id} was completed handled", context.MessageId);
}

#endregion
Expand Down
203 changes: 203 additions & 0 deletions Source/Euonia.Core/System/LikeOperator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
#nullable enable
namespace System;

/// <summary>
/// The LikeOperator class is used to compare two strings using the * and ? wildcards.
/// </summary>
public class LikeOperator
{
/// <summary>
/// Compares two strings using the * and ? wildcards.
/// </summary>
public static bool LikeString(string? content, string? pattern, bool ignoreCase = true, bool useInvariantCulture = true)
{
if (content == null && pattern == null)
return true;
if (content == null || pattern == null)
return false;

var patternSpan = pattern.AsSpan();
var contentSpan = content.AsSpan();

return LikeString(contentSpan, patternSpan, ignoreCase, useInvariantCulture);
}

/// <summary>
/// Compares two spans using the * and ? wildcards.
/// </summary>
public static bool LikeString(ReadOnlySpan<char> contentSpan, ReadOnlySpan<char> patternSpan, bool ignoreCase = true, bool useInvariantCulture = true)
{
var zeroOrMoreChars = '*';
var oneChar = '?';

if (patternSpan.Length == 1)
{
ref readonly char patternItem = ref patternSpan[0];
if (patternItem == zeroOrMoreChars)
{
return true;
}
}

if (contentSpan.Length == 1)
{
ref readonly var patternItem = ref patternSpan[0];
if (patternItem == oneChar)
{
return true;
}
}

var zeroOrMorePatternCount = 0;
var onePatternCount = 0;
foreach (var @char in patternSpan)
{
ref readonly char patternItem = ref @char;
if (patternItem == zeroOrMoreChars)
{
zeroOrMorePatternCount++;
}
else if (patternItem == oneChar)
{
onePatternCount++;
}
}

if (zeroOrMorePatternCount + onePatternCount == patternSpan.Length)
{
if (zeroOrMorePatternCount > 0)
{
return true;
}

if (patternSpan.Length == contentSpan.Length)
{
return true;
}
}

EqualsCharDelegate equalsChar;
if (ignoreCase)
{
if (useInvariantCulture)
{
equalsChar = EqualsCharInvariantCultureIgnoreCase;
}
else
{
equalsChar = EqualsCharCurrentCultureIgnoreCase;
}
}
else
{
equalsChar = EqualsChar;
}

return LikeStringCore(contentSpan, patternSpan, in zeroOrMoreChars, in oneChar, equalsChar);
}

private static bool LikeStringCore(ReadOnlySpan<char> contentSpan, ReadOnlySpan<char> patternSpan, in char zeroOrMoreChars, in char oneChar, EqualsCharDelegate equalsChar)
{
var contentIndex = 0;
var patternIndex = 0;
while (contentIndex < contentSpan.Length && patternIndex < patternSpan.Length)
{
ref readonly var patternItem = ref patternSpan[patternIndex];
if (patternItem == zeroOrMoreChars)
{
while (true)
{
if (patternIndex < patternSpan.Length)
{
ref readonly char nextPatternItem = ref patternSpan[patternIndex];
if (nextPatternItem == zeroOrMoreChars)
{
patternIndex++;
continue;
}
}

break;
}

if (patternIndex == patternSpan.Length)
{
return true;
}

while (contentIndex < contentSpan.Length)
{
if (LikeStringCore(contentSpan[contentIndex..], patternSpan[patternIndex..], in zeroOrMoreChars, in oneChar, equalsChar))
{
return true;
}

contentIndex++;
}

return false;
}

if (patternItem == oneChar)
{
contentIndex++;
patternIndex++;
}
else
{
if (contentIndex >= contentSpan.Length)
{
return false;
}

ref readonly var contentItem = ref contentSpan[contentIndex];
if (!equalsChar(in contentItem, in patternItem))
{
return false;
}

contentIndex++;
patternIndex++;
}
}

if (contentIndex == contentSpan.Length)
{
while (true)
{
if (patternIndex < patternSpan.Length)
{
ref readonly char nextPatternItem = ref patternSpan[patternIndex];
if (nextPatternItem == zeroOrMoreChars)
{
patternIndex++;
continue;
}
}

break;
}

return patternIndex == patternSpan.Length;
}

return false;
}

private static bool EqualsChar(in char contentItem, in char patternItem)
{
return contentItem == patternItem;
}

private static bool EqualsCharCurrentCultureIgnoreCase(in char contentItem, in char patternItem)
{
return char.ToUpper(contentItem) == char.ToUpper(patternItem);
}

private static bool EqualsCharInvariantCultureIgnoreCase(in char contentItem, in char patternItem)
{
return char.ToUpperInvariant(contentItem) == char.ToUpperInvariant(patternItem);
}

private delegate bool EqualsCharDelegate(in char contentItem, in char patternItem);
}

0 comments on commit 554e4b8

Please sign in to comment.