diff --git a/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs b/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs index 1d39d0806..c069d439d 100644 --- a/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs +++ b/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs @@ -9,6 +9,9 @@ using Elsa.Workflows.Core.Services; // ReSharper disable once CheckNamespace namespace Elsa.Extensions; +/// +/// Provides extensions on +/// public static class ExpressionExecutionContextExtensions { public static readonly object WorkflowExecutionContextKey = new(); @@ -16,6 +19,9 @@ public static class ExpressionExecutionContextExtensions public static readonly object InputKey = new(); public static readonly object WorkflowKey = new(); + /// + /// Creates a dictionary for the specified and . + /// public static IDictionary CreateActivityExecutionContextPropertiesFrom(WorkflowExecutionContext workflowExecutionContext, IDictionary input) => new Dictionary { @@ -24,6 +30,9 @@ public static class ExpressionExecutionContextExtensions [WorkflowKey] = workflowExecutionContext.Workflow, }; + /// + /// Creates a dictionary for the specified and . + /// public static IDictionary CreateTriggerIndexingPropertiesFrom(Workflow workflow, IDictionary input) => new Dictionary { @@ -31,23 +40,72 @@ public static class ExpressionExecutionContextExtensions [InputKey] = input }; + /// + /// Returns the of the specified + /// public static bool TryGetWorkflowExecutionContext(this ExpressionExecutionContext context, out WorkflowExecutionContext workflowExecutionContext) => context.TransientProperties.TryGetValue(WorkflowExecutionContextKey, out workflowExecutionContext!); + /// + /// Returns the of the specified + /// public static WorkflowExecutionContext GetWorkflowExecutionContext(this ExpressionExecutionContext context) => (WorkflowExecutionContext)context.TransientProperties[WorkflowExecutionContextKey]; + + /// + /// Returns the of the specified + /// + /// + /// public static ActivityExecutionContext GetActivityExecutionContext(this ExpressionExecutionContext context) => (ActivityExecutionContext)context.TransientProperties[ActivityExecutionContextKey]; + + /// + /// Returns the of the specified + /// + /// + /// + /// public static bool TryGetActivityExecutionContext(this ExpressionExecutionContext context, out ActivityExecutionContext activityExecutionContext) => context.TransientProperties.TryGetValue(ActivityExecutionContextKey, out activityExecutionContext!); + /// + /// Returns the input of the current activity. + /// public static IDictionary GetInput(this ExpressionExecutionContext context) => (IDictionary)context.TransientProperties[InputKey]; + + /// + /// Returns the value of the specified input. + /// public static T? GetInput(this ExpressionExecutionContext context, string key) => context.GetInput(key).ConvertTo(); + + /// + /// Returns the value of the specified input. + /// public static object? GetInput(this ExpressionExecutionContext context, string key) => context.GetInput().TryGetValue(key, out var value) ? value : default; + /// + /// Returns the value of the specified input. + /// public static T? Get(this ExpressionExecutionContext context, Input? input) => input != null ? context.GetBlock(input.MemoryBlockReference).Value.ConvertTo() : default; + + /// + /// Returns the value of the specified output. + /// public static T? Get(this ExpressionExecutionContext context, Output output) => context.GetBlock(output.MemoryBlockReference).Value.ConvertTo(); + + /// + /// Returns the value of the specified output. + /// public static object? Get(this ExpressionExecutionContext context, Output output) => context.GetBlock(output.MemoryBlockReference).Value; + + + /// + /// Returns the value of the variable with the specified name. + /// public static T? GetVariable(this ExpressionExecutionContext context, string name) => (T?)context.GetVariable(name)?.Value; - public static Variable? GetVariable(this ExpressionExecutionContext context, string name) + /// + /// Returns the variable with the specified name. + /// + public static Variable? GetVariable(this ExpressionExecutionContext context, string name, bool localScopeOnly = false) { foreach (var block in context.Memory.Blocks.Where(b => b.Value.Metadata is VariableBlockMetadata)) { @@ -55,8 +113,8 @@ public static class ExpressionExecutionContextExtensions if (metadata!.Variable.Name == name) return metadata.Variable; } - - return context.ParentContext?.GetVariable(name); + + return localScopeOnly ? null : context.ParentContext?.GetVariable(name); } /// @@ -64,7 +122,7 @@ public static class ExpressionExecutionContextExtensions /// public static Variable CreateVariable(this ExpressionExecutionContext context, string name, T? value, Type? storageDriverType = null, Action? configure = default) { - var existingVariable = context.GetVariable(name); + var existingVariable = context.GetVariable(name, localScopeOnly: true); if(existingVariable != null) throw new Exception($"Variable {name} already exists in the context.");