| | | 1 | | using System.Reflection; |
| | | 2 | | using System.Runtime.CompilerServices; |
| | | 3 | | using Elsa.Expressions.Models; |
| | | 4 | | using Elsa.Extensions; |
| | | 5 | | using Elsa.Workflows; |
| | | 6 | | using Elsa.Workflows.Attributes; |
| | | 7 | | using Elsa.Workflows.Memory; |
| | | 8 | | using Elsa.Workflows.Models; |
| | | 9 | | |
| | | 10 | | namespace Elsa.Scheduling.Activities; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Delay execution for the specified amount of time. |
| | | 14 | | /// </summary> |
| | | 15 | | [Activity("Elsa", "Scheduling", "Delay execution for the specified amount of time.")] |
| | | 16 | | public class Delay : Activity, IActivityPropertyDefaultValueProvider |
| | | 17 | | { |
| | | 18 | | /// <inheritdoc /> |
| | 298 | 19 | | public Delay([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line) |
| | | 20 | | { |
| | 298 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | | 24 | | public Delay( |
| | | 25 | | Func<ExpressionExecutionContext, TimeSpan> timeSpan, |
| | 0 | 26 | | [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : this(new Input<TimeSpan>(timeSpan |
| | | 27 | | { |
| | 0 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | | 31 | | public Delay( |
| | | 32 | | Func<ExpressionExecutionContext, ValueTask<TimeSpan>> timeSpan, |
| | 0 | 33 | | [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : this(new Input<TimeSpan>(timeSpan |
| | | 34 | | { |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <inheritdoc /> |
| | | 38 | | public Delay( |
| | | 39 | | Input<TimeSpan> timeSpan, |
| | 0 | 40 | | [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line) |
| | | 41 | | { |
| | 0 | 42 | | TimeSpan = timeSpan; |
| | 0 | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <inheritdoc /> |
| | | 46 | | public Delay( |
| | | 47 | | TimeSpan timeSpan, |
| | 139 | 48 | | [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line) |
| | | 49 | | { |
| | 139 | 50 | | TimeSpan = new Input<TimeSpan>(timeSpan); |
| | 139 | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <inheritdoc /> |
| | | 54 | | public Delay( |
| | | 55 | | Variable<TimeSpan> timeSpan, |
| | 0 | 56 | | [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line) |
| | | 57 | | { |
| | 0 | 58 | | TimeSpan = new Input<TimeSpan>(timeSpan); |
| | 0 | 59 | | } |
| | | 60 | | |
| | | 61 | | /// <summary> |
| | | 62 | | /// The amount of time to delay execution. |
| | | 63 | | /// </summary> |
| | | 64 | | [Input( |
| | | 65 | | Description = "The timespan to delay workflow execution.", |
| | | 66 | | DefaultValueProvider = typeof(Delay) |
| | | 67 | | )] |
| | 580 | 68 | | public Input<TimeSpan> TimeSpan { get; set; } = null!; |
| | | 69 | | |
| | | 70 | | /// <inheritdoc /> |
| | | 71 | | protected override void Execute(ActivityExecutionContext context) |
| | | 72 | | { |
| | 23 | 73 | | var timeSpan = context.ExpressionExecutionContext.Get(TimeSpan); |
| | 23 | 74 | | context.DelayFor(timeSpan); |
| | 23 | 75 | | } |
| | | 76 | | |
| | | 77 | | /// <summary> |
| | | 78 | | /// Creates a new <see cref="Delay"/> from the specified number of milliseconds. |
| | | 79 | | /// </summary> |
| | | 80 | | public static Delay FromMilliseconds( |
| | | 81 | | double value, |
| | 56 | 82 | | [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) => new(System.TimeSpan.FromMillisec |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// Creates a new <see cref="Delay"/> from the specified number of seconds. |
| | | 86 | | /// </summary> |
| | | 87 | | public static Delay FromSeconds( |
| | | 88 | | double value, |
| | 20 | 89 | | [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) => new(System.TimeSpan.FromSeconds( |
| | | 90 | | |
| | | 91 | | /// <summary> |
| | | 92 | | /// Creates a new <see cref="Delay"/> from the specified number of minutes. |
| | | 93 | | /// </summary> |
| | | 94 | | public static Delay FromMinutes( |
| | | 95 | | double value, |
| | 2 | 96 | | [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) => new(System.TimeSpan.FromMinutes( |
| | | 97 | | |
| | | 98 | | /// <summary> |
| | | 99 | | /// Creates a new <see cref="Delay"/> from the specified number of hours. |
| | | 100 | | /// </summary> |
| | | 101 | | public static Delay FromHours( |
| | | 102 | | double value, |
| | 2 | 103 | | [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) => new(System.TimeSpan.FromHours(va |
| | | 104 | | |
| | | 105 | | /// <summary> |
| | | 106 | | /// Creates a new <see cref="Delay"/> from the specified number of days. |
| | | 107 | | /// </summary> |
| | | 108 | | public static Delay FromDays( |
| | | 109 | | double value, |
| | 2 | 110 | | [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) => new(System.TimeSpan.FromDays(val |
| | | 111 | | |
| | 268 | 112 | | object IActivityPropertyDefaultValueProvider.GetDefaultValue(PropertyInfo property) => System.TimeSpan.FromMinutes(1 |
| | | 113 | | } |