| | | 1 | | using Elsa.Extensions; |
| | | 2 | | using Elsa.Expressions.JavaScript.Notifications; |
| | | 3 | | using Elsa.Mediator.Contracts; |
| | | 4 | | using Elsa.Workflows.LogPersistence; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Expressions.JavaScript.Handlers; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// A handler that configures the Jint engine with common types. |
| | | 11 | | /// </summary> |
| | | 12 | | [UsedImplicitly] |
| | | 13 | | public class ConfigureEngineWithCommonTypes : INotificationHandler<EvaluatingJavaScript> |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public Task HandleAsync(EvaluatingJavaScript notification, CancellationToken cancellationToken) |
| | | 17 | | { |
| | 188 | 18 | | var engine = notification.Engine; |
| | | 19 | | |
| | | 20 | | // Add common .NET types. |
| | 188 | 21 | | engine.RegisterType<DateTime>(); |
| | 188 | 22 | | engine.RegisterType<DateTimeOffset>(); |
| | 188 | 23 | | engine.RegisterType<TimeSpan>(); |
| | 188 | 24 | | engine.RegisterType<Guid>(); |
| | 188 | 25 | | engine.RegisterType<Random>(); |
| | 188 | 26 | | engine.RegisterType<LogPersistenceMode>(); |
| | | 27 | | |
| | 188 | 28 | | return Task.CompletedTask; |
| | | 29 | | } |
| | | 30 | | } |