diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleEventFormatter.cs b/backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleEventFormatter.cs index c1b807b75..c10dad1f6 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleEventFormatter.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleEventFormatter.cs @@ -17,6 +17,7 @@ using Squidex.Domain.Apps.Core.Rules.EnrichedEvents; using Squidex.Domain.Apps.Core.Scripting; using Squidex.Infrastructure; using Squidex.Infrastructure.Json; +using ValueTaskSupplement; namespace Squidex.Domain.Apps.Core.HandleRules { @@ -33,21 +34,22 @@ namespace Squidex.Domain.Apps.Core.HandleRules { public bool IsText; - public int Length; + public int TextLength; - public int Offset; + public int TextOffset; - public string Fallback; + public string VarFallback; - public string Transform; + public string VarTransform; - public ValueTask Replacement; + public ValueTask Var; public static TextPart Text(int offset, int length) { var result = default(TextPart); - result.Offset = offset; - result.Length = length; + + result.TextOffset = offset; + result.TextLength = length; result.IsText = true; return result; @@ -56,9 +58,10 @@ namespace Squidex.Domain.Apps.Core.HandleRules public static TextPart Variable(ValueTask replacement, string fallback, string transform) { var result = default(TextPart); - result.Replacement = replacement; - result.Fallback = fallback; - result.Transform = transform; + + result.Var = replacement; + result.VarFallback = fallback; + result.VarTransform = transform; return result; } @@ -104,7 +107,7 @@ namespace Squidex.Domain.Apps.Core.HandleRules var parts = BuildParts(text, @event); - await Task.WhenAll(parts.Select(x => x.Replacement.AsTask())); + await ValueTaskEx.WhenAll(parts.Select(x => x.Var)); return CombineParts(text, parts); } @@ -119,13 +122,13 @@ namespace Squidex.Domain.Apps.Core.HandleRules { if (!part.IsText) { - var result = part.Replacement.Result; + var result = part.Var.Result; - result = TransformText(result, part.Transform); + result = TransformText(result, part.VarTransform); if (result == null) { - result = part.Fallback; + result = part.VarFallback; } if (string.IsNullOrEmpty(result)) @@ -137,7 +140,7 @@ namespace Squidex.Domain.Apps.Core.HandleRules } else { - sb.Append(span.Slice(part.Offset, part.Length)); + sb.Append(span.Slice(part.TextOffset, part.TextLength)); } } diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj b/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj index fcf332d2a..566034c6b 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj @@ -24,6 +24,7 @@ + ..\..\Squidex.ruleset diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleEventFormatterTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleEventFormatterTests.cs index cb469f17f..cea1bd83b 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleEventFormatterTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleEventFormatterTests.cs @@ -7,7 +7,6 @@ using System; using System.Collections.Generic; -using System.Runtime.InteropServices; using System.Security.Claims; using System.Threading.Tasks; using FakeItEasy;