| | | 1 | | using Elsa.Workflows; |
| | | 2 | | using Elsa.Workflows.Runtime; |
| | | 3 | | using Elsa.Workflows.Runtime.Entities; |
| | | 4 | | |
| | | 5 | | // ReSharper disable once CheckNamespace |
| | | 6 | | namespace Elsa.Extensions; |
| | | 7 | | |
| | | 8 | | public static class ActivityExecutionContextRecordExtensions |
| | | 9 | | { |
| | | 10 | | private const string ActivityExecutionRecordKey = "CapturedActivityExecutionRecord"; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Captures the activity execution record for the provided <see cref="ActivityExecutionContext"/> and stores it in |
| | | 14 | | /// </summary> |
| | | 15 | | public static async Task CaptureActivityExecutionRecordAsync(this ActivityExecutionContext context) |
| | | 16 | | { |
| | 1334 | 17 | | var mapper = context.GetRequiredService<IActivityExecutionMapper>(); |
| | 1334 | 18 | | var record = await mapper.MapAsync(context); |
| | 1334 | 19 | | context.TransientProperties[ActivityExecutionRecordKey] = record; |
| | 1334 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Retrieves the captured activity execution record from the transient properties of the provided <see cref="Activi |
| | | 24 | | /// If the record is not found, it maps and returns a new activity execution record using the <see cref="IActivityEx |
| | | 25 | | /// </summary> |
| | | 26 | | public static async Task<ActivityExecutionRecord> GetOrMapCapturedActivityExecutionRecordAsync(this ActivityExecutio |
| | | 27 | | { |
| | | 28 | | // If the record is already captured in the transient properties, return it, as it will contain the serialized s |
| | | 29 | | // This is useful for scenarios where the activity execution state may change after the record is captured, such |
| | 3791 | 30 | | if (context.TransientProperties.TryGetValue(ActivityExecutionRecordKey, out var capturedRecord)) |
| | 1293 | 31 | | return (ActivityExecutionRecord)capturedRecord; |
| | | 32 | | |
| | | 33 | | // If the record is not captured, map a new activity execution record using the mapper. |
| | 2498 | 34 | | var mapper = context.GetRequiredService<IActivityExecutionMapper>(); |
| | 2498 | 35 | | var record = await mapper.MapAsync(context); |
| | | 36 | | |
| | 2498 | 37 | | return record; |
| | 3791 | 38 | | } |
| | | 39 | | } |