| | | 1 | | using Elsa.Mediator.Contracts; |
| | | 2 | | using Elsa.Expressions.Python.Notifications; |
| | | 3 | | using Elsa.Expressions.Python.Options; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | using Microsoft.Extensions.Options; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Expressions.Python.Handlers; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// This handler configures the Python engine based on the <see cref="PythonOptions"/>. |
| | | 11 | | /// </summary> |
| | | 12 | | [UsedImplicitly] |
| | | 13 | | public class ConfigurePythonFromOptions : INotificationHandler<EvaluatingPython> |
| | | 14 | | { |
| | | 15 | | private readonly PythonOptions _options; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Initializes a new instance of the <see cref="ConfigurePythonFromOptions"/> class. |
| | | 19 | | /// </summary> |
| | 319 | 20 | | public ConfigurePythonFromOptions(IOptions<PythonOptions> options) |
| | | 21 | | { |
| | 319 | 22 | | _options = options.Value; |
| | 319 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <inheritdoc /> |
| | | 26 | | public Task HandleAsync(EvaluatingPython notification, CancellationToken cancellationToken) |
| | | 27 | | { |
| | 0 | 28 | | foreach (var action in _options.Scopes) action(notification.Scope); |
| | 0 | 29 | | foreach (var script in _options.Scripts) notification.AppendScript(script); |
| | | 30 | | |
| | 0 | 31 | | return Task.CompletedTask; |
| | | 32 | | } |
| | | 33 | | } |