| | | 1 | | using Elsa.Expressions.JavaScript.Notifications; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | using Elsa.Mediator.Contracts; |
| | | 4 | | using Elsa.Workflows.Management.Options; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | using Microsoft.Extensions.Options; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Expressions.JavaScript.Handlers; |
| | | 9 | | |
| | | 10 | | [UsedImplicitly] |
| | 520 | 11 | | public class ConfigureEngineWithWorkflowVariableTypes(IOptions<ManagementOptions> options) |
| | | 12 | | : INotificationHandler<EvaluatingJavaScript> |
| | | 13 | | { |
| | 3 | 14 | | private static readonly Type[] BlacklistedTypes = |
| | 3 | 15 | | [ |
| | 3 | 16 | | typeof(string), |
| | 3 | 17 | | typeof(object), |
| | 3 | 18 | | // Add more types if needed. |
| | 3 | 19 | | ]; |
| | | 20 | | |
| | | 21 | | /// <inheritdoc /> |
| | | 22 | | public Task HandleAsync(EvaluatingJavaScript notification, CancellationToken cancellationToken) |
| | | 23 | | { |
| | 188 | 24 | | var engine = notification.Engine; |
| | 188 | 25 | | var variableTypes = options.Value.VariableDescriptors |
| | 4100 | 26 | | .Where(x => x.Type is { ContainsGenericParameters: false } && !BlacklistedTypes.Contains(x.Type) && !x.Type. |
| | 2784 | 27 | | .Select(x => x.Type) |
| | 188 | 28 | | .ToArray(); |
| | | 29 | | |
| | 5944 | 30 | | foreach (var variableType in variableTypes) |
| | | 31 | | { |
| | 2784 | 32 | | engine.RegisterType(variableType); |
| | | 33 | | } |
| | | 34 | | |
| | 188 | 35 | | return Task.CompletedTask; |
| | | 36 | | } |
| | | 37 | | } |