< Summary

Information
Class: Elsa.Workflows.BackgroundActivityExecutionContextExtensions
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Extensions/BackgroundActivityExecutionContextExtensions.cs
Line coverage
13%
Covered lines: 2
Uncovered lines: 13
Coverable lines: 15
Total lines: 84
Line coverage: 13.3%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Extensions/BackgroundActivityExecutionContextExtensions.cs

#LineLine coverage
 1using Elsa.Workflows.Models;
 2
 3namespace Elsa.Workflows;
 4
 5/// <summary>
 6/// Adds extension methods to <see cref="ActivityExecutionContext"/>.
 7/// </summary>
 8public 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>
 413    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        {
 023            activityExecutionContext.TransientProperties[IsBackgroundExecution] = value;
 024        }
 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        {
 572531            return activityExecutionContext.TransientProperties.ContainsKey(IsBackgroundExecution);
 32        }
 33
 34        /// <summary>
 35        /// Sets the background outcomes.
 36        /// </summary>
 37        public void SetBackgroundOutcomes(IEnumerable<string> outcomes)
 38        {
 039            var outcomesList = outcomes.ToList();
 040            activityExecutionContext.SetProperty("BackgroundOutcomes", outcomesList);
 041        }
 42
 43        /// <summary>
 44        /// Gets the background outcomes.
 45        /// </summary>
 46        public IEnumerable<string>? GetBackgroundOutcomes()
 47        {
 048            return activityExecutionContext.GetProperty<IEnumerable<string>>("BackgroundOutcomes");
 49        }
 50
 51        /// <summary>
 52        /// Sets the background outcomes.
 53        /// </summary>
 54        public void SetBackgroundCompletion()
 55        {
 056            activityExecutionContext.SetProperty("BackgroundCompletion", true);
 057        }
 58
 59        /// <summary>
 60        /// Gets the background outcomes.
 61        /// </summary>
 62        public bool? GetBackgroundCompleted()
 63        {
 064            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        {
 072            var scheduledActivitiesList = scheduledActivities.ToList();
 073            activityExecutionContext.SetProperty("BackgroundScheduledActivities", scheduledActivitiesList);
 074        }
 75
 76        /// <summary>
 77        /// Gets the background scheduled activities.
 78        /// </summary>
 79        public IEnumerable<ScheduledActivity> GetBackgroundScheduledActivities()
 80        {
 081            return activityExecutionContext.GetProperty<IEnumerable<ScheduledActivity>>("BackgroundScheduledActivities")
 82        }
 83    }
 84}