| | | 1 | | using Elsa.Expressions.CSharp.Notifications; |
| | | 2 | | using Elsa.Expressions.CSharp.Options; |
| | | 3 | | using Elsa.Mediator.Contracts; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | using Microsoft.CodeAnalysis.Scripting; |
| | | 6 | | using Microsoft.Extensions.Options; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Expressions.CSharp.Handlers; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// This handler configures the <see cref="ScriptOptions"/> and <see cref="Script"/> from the <see cref="CSharpOptions"/ |
| | | 12 | | /// </summary> |
| | | 13 | | [UsedImplicitly] |
| | | 14 | | public class ConfigureScriptsFromOptions : INotificationHandler<EvaluatingCSharp> |
| | | 15 | | { |
| | | 16 | | private readonly CSharpOptions _options; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Initializes a new instance of the <see cref="ConfigureScriptsFromOptions"/> class. |
| | | 20 | | /// </summary> |
| | 319 | 21 | | public ConfigureScriptsFromOptions(IOptions<CSharpOptions> options) |
| | | 22 | | { |
| | 319 | 23 | | _options = options.Value; |
| | 319 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | | 27 | | public Task HandleAsync(EvaluatingCSharp notification, CancellationToken cancellationToken) |
| | | 28 | | { |
| | 0 | 29 | | foreach (var scriptOptionsCallback in _options.ConfigureScriptOptionsCallbacks) |
| | 0 | 30 | | notification.ScriptOptions = scriptOptionsCallback(notification.ScriptOptions, notification.Context); |
| | | 31 | | |
| | 0 | 32 | | foreach (var scriptCallback in _options.ConfigureScriptCallbacks) |
| | 0 | 33 | | notification.Script = scriptCallback(notification.Script, notification.Context); |
| | | 34 | | |
| | 0 | 35 | | return Task.CompletedTask; |
| | | 36 | | } |
| | | 37 | | } |