| | | 1 | | using Elsa.Workflows.Management.Entities; |
| | | 2 | | using Elsa.Workflows.State; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Workflows.Management.Services; |
| | | 5 | | |
| | 3 | 6 | | public class WorkflowInstanceVariableManager( |
| | 3 | 7 | | IWorkflowInstanceManager workflowInstanceManager, |
| | 3 | 8 | | IWorkflowDefinitionService workflowDefinitionService, |
| | 3 | 9 | | IServiceProvider serviceProvider, |
| | 3 | 10 | | IWorkflowInstanceVariableReader variableReader, |
| | 3 | 11 | | IWorkflowInstanceVariableWriter variableWriter) : IWorkflowInstanceVariableManager |
| | | 12 | | { |
| | | 13 | | public async Task<IEnumerable<ResolvedVariable>> GetVariablesAsync(string workflowInstanceId, IEnumerable<string>? e |
| | | 14 | | { |
| | 1 | 15 | | var workflowExecutionContext = await GetWorkflowExecutionContextAsync(workflowInstanceId, cancellationToken); |
| | 1 | 16 | | if (workflowExecutionContext == null) return []; |
| | 1 | 17 | | return await variableReader.GetVariables(workflowExecutionContext, excludeTags, cancellationToken); |
| | 1 | 18 | | } |
| | | 19 | | |
| | | 20 | | public Task<IEnumerable<ResolvedVariable>> GetVariablesAsync(WorkflowExecutionContext workflowExecutionContext, IEnu |
| | | 21 | | { |
| | 1 | 22 | | return variableReader.GetVariables(workflowExecutionContext, excludeTags, cancellationToken); |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | public async Task<IEnumerable<ResolvedVariable>> GetVariablesAsync(WorkflowInstance workflowInstance, IEnumerable<st |
| | | 26 | | { |
| | 0 | 27 | | return await GetVariablesAsync(workflowInstance.WorkflowState, excludeTags, cancellationToken); |
| | 0 | 28 | | } |
| | | 29 | | |
| | | 30 | | public async Task<IEnumerable<ResolvedVariable>> GetVariablesAsync(WorkflowState workflowState, IEnumerable<string>? |
| | | 31 | | { |
| | 0 | 32 | | var workflowExecutionContext = await GetWorkflowExecutionContextAsync(workflowState, cancellationToken); |
| | 0 | 33 | | if (workflowExecutionContext == null) return []; |
| | 0 | 34 | | return await variableReader.GetVariables(workflowExecutionContext, excludeTags, cancellationToken); |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | public async Task<IEnumerable<ResolvedVariable>> SetVariablesAsync(string workflowInstanceId, IEnumerable<VariableUp |
| | | 38 | | { |
| | 0 | 39 | | var workflowExecutionContext = await GetWorkflowExecutionContextAsync(workflowInstanceId, cancellationToken); |
| | 0 | 40 | | if (workflowExecutionContext == null) return []; |
| | 0 | 41 | | var resolvedVariables = await variableWriter.SetVariables(workflowExecutionContext, variables, cancellationToken |
| | 0 | 42 | | await workflowInstanceManager.SaveAsync(workflowExecutionContext, cancellationToken); |
| | 0 | 43 | | return resolvedVariables; |
| | 0 | 44 | | } |
| | | 45 | | |
| | | 46 | | public Task<IEnumerable<ResolvedVariable>> SetVariablesAsync(WorkflowExecutionContext workflowExecutionContext, IEnu |
| | | 47 | | { |
| | 0 | 48 | | return variableWriter.SetVariables(workflowExecutionContext, variables, cancellationToken); |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | private async Task<WorkflowExecutionContext?> GetWorkflowExecutionContextAsync(string workflowInstanceId, Cancellati |
| | | 52 | | { |
| | 1 | 53 | | var workflowInstance = await workflowInstanceManager.FindByIdAsync(workflowInstanceId, cancellationToken); |
| | | 54 | | |
| | 1 | 55 | | if (workflowInstance == null) |
| | 0 | 56 | | return null; |
| | | 57 | | |
| | 1 | 58 | | var workflowState = workflowInstance.WorkflowState; |
| | | 59 | | |
| | 1 | 60 | | return await GetWorkflowExecutionContextAsync(workflowState, cancellationToken); |
| | 1 | 61 | | } |
| | | 62 | | |
| | | 63 | | private async Task<WorkflowExecutionContext?> GetWorkflowExecutionContextAsync(WorkflowState workflowState, Cancella |
| | | 64 | | { |
| | 1 | 65 | | var workflowGraph = await workflowDefinitionService.FindWorkflowGraphAsync(workflowState.DefinitionVersionId, ca |
| | | 66 | | |
| | 1 | 67 | | if (workflowGraph == null) |
| | 0 | 68 | | return null; |
| | | 69 | | |
| | 1 | 70 | | return await WorkflowExecutionContext.CreateAsync( |
| | 1 | 71 | | serviceProvider, |
| | 1 | 72 | | workflowGraph, |
| | 1 | 73 | | workflowState, |
| | 1 | 74 | | cancellationToken: cancellationToken); |
| | 1 | 75 | | } |
| | | 76 | | } |