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
42 changes: 42 additions & 0 deletions Masa.Framework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Service.Caller
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Contrib.Authentication.OpenIdConnect.EFCore.Oracle", "src\Contrib\Authentication\OpenIdConnect\Masa.Contrib.Authentication.OpenIdConnect.EFCore.Oracle\Masa.Contrib.Authentication.OpenIdConnect.EFCore.Oracle.csproj", "{03F476EF-022A-4370-B1C3-FEEDE3BB4E7F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RulesEngine", "RulesEngine", "{A7081ADB-DB21-4678-8510-A5367D470743}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RulesEngine", "RulesEngine", "{8E74F3D4-9387-4F69-9A17-C793CE2CBAA9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.BuildingBlocks.RulesEngine", "src\BuildingBlocks\RulesEngine\Masa.BuildingBlocks.RulesEngine\Masa.BuildingBlocks.RulesEngine.csproj", "{B03C329C-70F4-442A-B420-90DDF7E31847}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Contrib.RulesEngine.MicrosoftRulesEngine", "src\Contrib\RulesEngine\Masa.Contrib.RulesEngine.MicrosoftRulesEngine\Masa.Contrib.RulesEngine.MicrosoftRulesEngine.csproj", "{4E217EC9-0616-414B-82D9-9107F9826D6E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{3FADF704-2581-47AC-A1F7-07091B6328A1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Contrib.RulesEngine.MicrosoftRulesEngine.Tests", "src\Contrib\RulesEngine\Tests\Masa.Contrib.RulesEngine.MicrosoftRulesEngine.Tests\Masa.Contrib.RulesEngine.MicrosoftRulesEngine.Tests.csproj", "{EEB2D542-5A2C-4E18-A0E6-72844C359DAD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -2041,6 +2053,14 @@ Global
{BEA8E5A5-E7BD-4165-80CD-D1F53ED82D02}.Release|Any CPU.Build.0 = Release|Any CPU
{BEA8E5A5-E7BD-4165-80CD-D1F53ED82D02}.Release|x64.ActiveCfg = Release|Any CPU
{BEA8E5A5-E7BD-4165-80CD-D1F53ED82D02}.Release|x64.Build.0 = Release|Any CPU
{B03C329C-70F4-442A-B420-90DDF7E31847}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B03C329C-70F4-442A-B420-90DDF7E31847}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B03C329C-70F4-442A-B420-90DDF7E31847}.Debug|x64.ActiveCfg = Debug|Any CPU
{B03C329C-70F4-442A-B420-90DDF7E31847}.Debug|x64.Build.0 = Debug|Any CPU
{B03C329C-70F4-442A-B420-90DDF7E31847}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B03C329C-70F4-442A-B420-90DDF7E31847}.Release|Any CPU.Build.0 = Release|Any CPU
{B03C329C-70F4-442A-B420-90DDF7E31847}.Release|x64.ActiveCfg = Release|Any CPU
{B03C329C-70F4-442A-B420-90DDF7E31847}.Release|x64.Build.0 = Release|Any CPU
{03F476EF-022A-4370-B1C3-FEEDE3BB4E7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03F476EF-022A-4370-B1C3-FEEDE3BB4E7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03F476EF-022A-4370-B1C3-FEEDE3BB4E7F}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -2049,6 +2069,22 @@ Global
{03F476EF-022A-4370-B1C3-FEEDE3BB4E7F}.Release|Any CPU.Build.0 = Release|Any CPU
{03F476EF-022A-4370-B1C3-FEEDE3BB4E7F}.Release|x64.ActiveCfg = Release|Any CPU
{03F476EF-022A-4370-B1C3-FEEDE3BB4E7F}.Release|x64.Build.0 = Release|Any CPU
{4E217EC9-0616-414B-82D9-9107F9826D6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E217EC9-0616-414B-82D9-9107F9826D6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E217EC9-0616-414B-82D9-9107F9826D6E}.Debug|x64.ActiveCfg = Debug|Any CPU
{4E217EC9-0616-414B-82D9-9107F9826D6E}.Debug|x64.Build.0 = Debug|Any CPU
{4E217EC9-0616-414B-82D9-9107F9826D6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E217EC9-0616-414B-82D9-9107F9826D6E}.Release|Any CPU.Build.0 = Release|Any CPU
{4E217EC9-0616-414B-82D9-9107F9826D6E}.Release|x64.ActiveCfg = Release|Any CPU
{4E217EC9-0616-414B-82D9-9107F9826D6E}.Release|x64.Build.0 = Release|Any CPU
{EEB2D542-5A2C-4E18-A0E6-72844C359DAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEB2D542-5A2C-4E18-A0E6-72844C359DAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEB2D542-5A2C-4E18-A0E6-72844C359DAD}.Debug|x64.ActiveCfg = Debug|Any CPU
{EEB2D542-5A2C-4E18-A0E6-72844C359DAD}.Debug|x64.Build.0 = Debug|Any CPU
{EEB2D542-5A2C-4E18-A0E6-72844C359DAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEB2D542-5A2C-4E18-A0E6-72844C359DAD}.Release|Any CPU.Build.0 = Release|Any CPU
{EEB2D542-5A2C-4E18-A0E6-72844C359DAD}.Release|x64.ActiveCfg = Release|Any CPU
{EEB2D542-5A2C-4E18-A0E6-72844C359DAD}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2332,7 +2368,13 @@ Global
{9BB5CC86-C2E8-4859-9610-50DB263605A3} = {FC4A0C94-47F7-4C9A-A7EC-138DE8EB842D}
{8D7D3D21-86DB-4FCC-8FF0-6E1587ABD22A} = {FC4A0C94-47F7-4C9A-A7EC-138DE8EB842D}
{BEA8E5A5-E7BD-4165-80CD-D1F53ED82D02} = {8D7D3D21-86DB-4FCC-8FF0-6E1587ABD22A}
{A7081ADB-DB21-4678-8510-A5367D470743} = {950DA7D0-48C1-42BA-8E8F-F72C0DCE41C4}
{03F476EF-022A-4370-B1C3-FEEDE3BB4E7F} = {41769FBF-91A8-48D1-B3BB-CAE4C814E7CD}
{8E74F3D4-9387-4F69-9A17-C793CE2CBAA9} = {DC578D74-98F0-4F19-A230-CFA8DAEE0AF1}
{B03C329C-70F4-442A-B420-90DDF7E31847} = {8E74F3D4-9387-4F69-9A17-C793CE2CBAA9}
{4E217EC9-0616-414B-82D9-9107F9826D6E} = {A7081ADB-DB21-4678-8510-A5367D470743}
{3FADF704-2581-47AC-A1F7-07091B6328A1} = {A7081ADB-DB21-4678-8510-A5367D470743}
{EEB2D542-5A2C-4E18-A0E6-72844C359DAD} = {3FADF704-2581-47AC-A1F7-07091B6328A1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {40383055-CC50-4600-AD9A-53C14F620D03}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

// ReSharper disable once CheckNamespace

namespace Masa.BuildingBlocks.Data;

public class MasaRelationOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.Data.Contracts.Response;

public class ResponseBase
{
public bool IsValid { get; }

public string Message { get; }

public ResponseBase(bool isValid, string message = "")
{
IsValid = isValid;
Message = message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.RulesEngine;

public class DefaultRulesEngineFactory : MasaFactoryBase<IRulesEngineClient, RulesEngineRelationOptions>,
IRulesEngineFactory
{
protected override string DefaultServiceNotFoundMessage
=> $"No default {nameof(IRulesEngineClient)} found, you may need services.AddRulesEngine(options => options.UseRulesEngine())";

protected override string SpecifyServiceNotFoundMessage
=> $"Please make sure you have used [{0}] {nameof(IRulesEngineClient)}, it was not found";

protected override MasaFactoryOptions<RulesEngineRelationOptions> FactoryOptions => _options.Value;

private readonly IOptions<RulesEngineFactoryOptions> _options;

public DefaultRulesEngineFactory(IServiceProvider serviceProvider) : base(serviceProvider)
{
_options = serviceProvider.GetRequiredService<IOptions<RulesEngineFactoryOptions>>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.RulesEngine;

public interface IRulesEngineClient
{
/// <summary>
/// Check if the rule format is correct
/// </summary>
/// <param name="ruleRaw"></param>
/// <returns></returns>
VerifyResponse Verify(string ruleRaw);

/// <summary>
/// Obtain whether the match is successful according to the rules and input parameters
/// </summary>
/// <param name="ruleRaw"></param>
/// <param name="data">Input data</param>
/// <typeparam name="TRequest"></typeparam>
/// <returns>Whether the match was successful</returns>
List<ExecuteResponse> Execute<TRequest>(string ruleRaw, TRequest data);

/// <summary>
/// Obtain whether the match is successful according to the rules and input parameters
/// </summary>
/// <param name="ruleRaw">Rule Json</param>
/// <param name="data">Input data</param>
/// <typeparam name="TRequest"></typeparam>
/// <returns>Whether the match was successful</returns>
Task<List<ExecuteResponse>> ExecuteAsync<TRequest>(string ruleRaw, TRequest data);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.RulesEngine;

public interface IRulesEngineFactory : IMasaFactory<IRulesEngineClient>
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Data\Masa.BuildingBlocks.Data\Masa.BuildingBlocks.Data.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

// ReSharper disable once CheckNamespace

namespace Masa.BuildingBlocks.RulesEngine;

public class RulesEngineFactoryOptions : MasaFactoryOptions<RulesEngineRelationOptions>
{
public void TryAddRulesEngine(string name, Func<IServiceProvider, IRulesEngineClient> func)
{
if (Options.Any(opt => opt.Name.Equals(name, StringComparison.OrdinalIgnoreCase)))
return;

Options.Add(new RulesEngineRelationOptions(name, func));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

// ReSharper disable once CheckNamespace
namespace Masa.BuildingBlocks.RulesEngine;

public class RulesEngineOptions
{
public IServiceCollection Services { get; }

public RulesEngineOptions(IServiceCollection services)
{
Services = services;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

// ReSharper disable once CheckNamespace

namespace Masa.BuildingBlocks.RulesEngine;

public class RulesEngineRelationOptions : MasaRelationOptions<IRulesEngineClient>
{
public RulesEngineRelationOptions(string name, Func<IServiceProvider, IRulesEngineClient> func)
: base(name)
{
Func = func;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.RulesEngine;

public class ActionResponse
{
public object Output { get; set; }

public Exception Exception { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.RulesEngine;

public class ExecuteResponse : ResponseBase
{
public string RuleName { get; set; }

public string SuccessEvent { get; set; }

public ActionResponse ActionResult { get; set; }

public ExecuteResponse(string ruleName, bool isValid, string message = "")
: base(isValid, message)
{
RuleName = ruleName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.RulesEngine;

public class VerifyResponse : ResponseBase
{
public VerifyResponse(bool isValid, string message = "")
: base(isValid, message)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.RulesEngine;

public abstract class RulesEngineClientBase : IRulesEngineClient
{
public abstract VerifyResponse Verify(string ruleRaw);

public abstract List<ExecuteResponse> Execute<TRequest>(string ruleRaw, TRequest data);

public abstract Task<List<ExecuteResponse>> ExecuteAsync<TRequest>(string ruleRaw, TRequest data);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

// ReSharper disable once CheckNamespace

namespace Microsoft.Extensions.DependencyInjection;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddRulesEngine(this IServiceCollection services, Action<RulesEngineOptions> action)
{
MasaApp.TrySetServiceCollection(services);
services.TryAddSingleton<IRulesEngineFactory, DefaultRulesEngineFactory>();
services.TryAddTransient(serviceProvider => serviceProvider.GetRequiredService<IRulesEngineFactory>().Create());
RulesEngineOptions rulesEngineOptions = new RulesEngineOptions(services);
action.Invoke(rulesEngineOptions);
return services;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

global using Masa.BuildingBlocks.Data;
global using Masa.BuildingBlocks.Data.Contracts.Response;
global using Masa.BuildingBlocks.RulesEngine;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.DependencyInjection.Extensions;
global using Microsoft.Extensions.Options;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

// ReSharper disable once CheckNamespace
namespace Masa.Contrib.RulesEngine.MicrosoftRulesEngine;

internal static class Constant
{
public const string DEFAULT_JSON_NAME = "Masa.Contrib.RulesEngine.MicrosoftRulesEngine";

public const string ERROR_RULE = "illegal rules on MicrosoftRulesEngine";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\RulesEngine\Masa.BuildingBlocks.RulesEngine\Masa.BuildingBlocks.RulesEngine.csproj" />
<ProjectReference Include="..\..\..\Utils\Masa.Utils.Exceptions\Masa.Utils.Exceptions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftPackageVersion)" />
<PackageReference Aliases="MicrosoftRulesEngine" Include="RulesEngine" Version="4.0.0" />
</ItemGroup>

</Project>
Loading