From 5fae56d2bfab853304586c26bbfd4a5edc96b057 Mon Sep 17 00:00:00 2001 From: noxe Date: Wed, 24 Nov 2021 11:52:46 +0100 Subject: [PATCH] Bug - Accessing Output via Liquid (#2509) * do not create a new Scope - reuse workflowExecutionContext's scope * Upgrade Rebus.ServiceProvider to 7.0 * using the correct storage provider Co-authored-by: Martin --- .../Handlers/ConfigureLiquidEngine.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/scripting/Elsa.Scripting.Liquid/Handlers/ConfigureLiquidEngine.cs b/src/scripting/Elsa.Scripting.Liquid/Handlers/ConfigureLiquidEngine.cs index a39f0b3b9..41e26d0bd 100644 --- a/src/scripting/Elsa.Scripting.Liquid/Handlers/ConfigureLiquidEngine.cs +++ b/src/scripting/Elsa.Scripting.Liquid/Handlers/ConfigureLiquidEngine.cs @@ -10,6 +10,7 @@ using Elsa.Providers.WorkflowStorage; using Elsa.Scripting.Liquid.Helpers; using Elsa.Scripting.Liquid.Messages; using Elsa.Scripting.Liquid.Options; +using Elsa.Services; using Elsa.Services.Models; using Elsa.Services.WorkflowStorage; using Fluid; @@ -26,12 +27,14 @@ namespace Elsa.Scripting.Liquid.Handlers private readonly IConfiguration _configuration; private readonly IWorkflowStorageService _workflowStorageService; private readonly LiquidOptions _liquidOptions; + private readonly IActivityTypeService _activityTypeService; - public ConfigureLiquidEngine(IConfiguration configuration, IWorkflowStorageService workflowStorageService, IOptions liquidOptions) + public ConfigureLiquidEngine(IConfiguration configuration, IWorkflowStorageService workflowStorageService, IOptions liquidOptions, IActivityTypeService activityTypeService) { _configuration = configuration; _workflowStorageService = workflowStorageService; _liquidOptions = liquidOptions.Value; + _activityTypeService = activityTypeService; } public Task Handle(EvaluatingLiquidExpression notification, CancellationToken cancellationToken) @@ -61,7 +64,7 @@ namespace Elsa.Scripting.Liquid.Handlers memberAccessStrategy.Register((x, a) => GetActivityModel(x, a)); memberAccessStrategy.Register((model, name) => GetActivityProperty(model, name, cancellationToken)); memberAccessStrategy.Register, JObject>((x, name) => x.GetValueAsync(name)); - memberAccessStrategy.Register((x, name) => ((IDictionary) x)[name]); + memberAccessStrategy.Register((x, name) => ((IDictionary)x)[name]); memberAccessStrategy.Register((source, name) => source.GetValue(name, StringComparison.OrdinalIgnoreCase)); if (_liquidOptions.EnableConfigurationAccess) @@ -94,7 +97,14 @@ namespace Elsa.Scripting.Liquid.Handlers var workflowExecutionContext = activityExecutionContext.WorkflowExecutionContext; var activityBlueprint = activityModel.ActivityId != null ? workflowExecutionContext.GetActivityBlueprintById(activityModel.ActivityId)! : workflowExecutionContext.GetActivityBlueprintByName(activityModel.ActivityName!)!; var activityId = activityBlueprint.Id; - var storageProviderName = activityBlueprint.PropertyStorageProviders.GetItem(name); + + var activityType = await _activityTypeService.GetActivityTypeAsync(activityBlueprint.Type, cancellationToken); + var activityDescriptor = await _activityTypeService.DescribeActivityType(activityType, cancellationToken); + + var property = activityDescriptor.OutputProperties.FirstOrDefault(d => d.Name == name); + + var storageProviderName = activityBlueprint.PropertyStorageProviders.GetItem(name) ?? property?.DefaultWorkflowStorageProvider; + var storageContext = new WorkflowStorageContext(workflowExecutionContext.WorkflowInstance, activityId); var value = await _workflowStorageService.LoadAsync(storageProviderName, storageContext, name, cancellationToken); return value;