| | | 1 | | namespace Elsa.Workflows; |
| | | 2 | | |
| | 3 | 3 | | public class DefaultWorkflowInstanceVariableWriter(IVariablePersistenceManager variablePersistenceManager) : IWorkflowIn |
| | | 4 | | { |
| | | 5 | | public async Task<IEnumerable<ResolvedVariable>> SetVariables(WorkflowExecutionContext workflowExecutionContext, IEn |
| | | 6 | | { |
| | 0 | 7 | | var workflow = workflowExecutionContext.Workflow; |
| | 0 | 8 | | var workflowVariables = workflow.Variables; |
| | 0 | 9 | | var rootWorkflowActivityExecutionContext = workflowExecutionContext.ActivityExecutionContexts.FirstOrDefault(x = |
| | | 10 | | |
| | 0 | 11 | | if (rootWorkflowActivityExecutionContext == null) |
| | 0 | 12 | | return []; |
| | | 13 | | |
| | 0 | 14 | | await variablePersistenceManager.LoadVariablesAsync(workflowExecutionContext); |
| | 0 | 15 | | var variablesToUpdate = variables.ToDictionary(x => x.Id, x => x.Value); |
| | 0 | 16 | | var resolvedVariables = new Dictionary<string, ResolvedVariable>(); |
| | | 17 | | |
| | 0 | 18 | | foreach (var workflowVariable in workflowVariables) |
| | | 19 | | { |
| | 0 | 20 | | var currentValue = workflowVariable.Get(rootWorkflowActivityExecutionContext.ExpressionExecutionContext); |
| | 0 | 21 | | var resolvedVariable = new ResolvedVariable(workflowVariable, currentValue); |
| | 0 | 22 | | resolvedVariables[workflowVariable.Id] = resolvedVariable; |
| | | 23 | | |
| | 0 | 24 | | if (!variablesToUpdate.TryGetValue(workflowVariable.Id, out var value)) |
| | | 25 | | continue; |
| | | 26 | | |
| | 0 | 27 | | workflowVariable.Set(rootWorkflowActivityExecutionContext.ExpressionExecutionContext, value); |
| | 0 | 28 | | resolvedVariable = resolvedVariable with |
| | 0 | 29 | | { |
| | 0 | 30 | | Value = value |
| | 0 | 31 | | }; |
| | | 32 | | |
| | 0 | 33 | | resolvedVariables[workflowVariable.Id] = resolvedVariable; |
| | | 34 | | } |
| | | 35 | | |
| | 0 | 36 | | await variablePersistenceManager.SaveVariablesAsync(workflowExecutionContext); |
| | 0 | 37 | | return resolvedVariables.Values; |
| | 0 | 38 | | } |
| | | 39 | | } |