| | | 1 | | using Elsa.Workflows.Models; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Workflows; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Adds extension methods to <see cref="ActivityExecutionContext"/>. |
| | | 7 | | /// </summary> |
| | | 8 | | public static class BackgroundActivityExecutionContextExtensions |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// A key into the activity execution context's transient properties that indicates whether the current activity is |
| | | 12 | | /// </summary> |
| | 4 | 13 | | public static readonly object IsBackgroundExecution = new(); |
| | | 14 | | |
| | | 15 | | /// <param name="activityExecutionContext"></param> |
| | | 16 | | extension(ActivityExecutionContext activityExecutionContext) |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Configures the activity execution context to execute the current activity in the background. |
| | | 20 | | /// </summary> |
| | | 21 | | public void SetIsBackgroundExecution(bool value = true) |
| | | 22 | | { |
| | 0 | 23 | | activityExecutionContext.TransientProperties[IsBackgroundExecution] = value; |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets a value indicating whether the current activity is being executed in the background. |
| | | 28 | | /// </summary> |
| | | 29 | | public bool GetIsBackgroundExecution() |
| | | 30 | | { |
| | 5725 | 31 | | return activityExecutionContext.TransientProperties.ContainsKey(IsBackgroundExecution); |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Sets the background outcomes. |
| | | 36 | | /// </summary> |
| | | 37 | | public void SetBackgroundOutcomes(IEnumerable<string> outcomes) |
| | | 38 | | { |
| | 0 | 39 | | var outcomesList = outcomes.ToList(); |
| | 0 | 40 | | activityExecutionContext.SetProperty("BackgroundOutcomes", outcomesList); |
| | 0 | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Gets the background outcomes. |
| | | 45 | | /// </summary> |
| | | 46 | | public IEnumerable<string>? GetBackgroundOutcomes() |
| | | 47 | | { |
| | 0 | 48 | | return activityExecutionContext.GetProperty<IEnumerable<string>>("BackgroundOutcomes"); |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Sets the background outcomes. |
| | | 53 | | /// </summary> |
| | | 54 | | public void SetBackgroundCompletion() |
| | | 55 | | { |
| | 0 | 56 | | activityExecutionContext.SetProperty("BackgroundCompletion", true); |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// Gets the background outcomes. |
| | | 61 | | /// </summary> |
| | | 62 | | public bool? GetBackgroundCompleted() |
| | | 63 | | { |
| | 0 | 64 | | return activityExecutionContext.GetProperty<bool>("BackgroundCompletion"); |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | /// <summary> |
| | | 68 | | /// Sets the background scheduled activities. |
| | | 69 | | /// </summary> |
| | | 70 | | public void SetBackgroundScheduledActivities(IEnumerable<ScheduledActivity> scheduledActivities) |
| | | 71 | | { |
| | 0 | 72 | | var scheduledActivitiesList = scheduledActivities.ToList(); |
| | 0 | 73 | | activityExecutionContext.SetProperty("BackgroundScheduledActivities", scheduledActivitiesList); |
| | 0 | 74 | | } |
| | | 75 | | |
| | | 76 | | /// <summary> |
| | | 77 | | /// Gets the background scheduled activities. |
| | | 78 | | /// </summary> |
| | | 79 | | public IEnumerable<ScheduledActivity> GetBackgroundScheduledActivities() |
| | | 80 | | { |
| | 0 | 81 | | return activityExecutionContext.GetProperty<IEnumerable<ScheduledActivity>>("BackgroundScheduledActivities") |
| | | 82 | | } |
| | | 83 | | } |
| | | 84 | | } |