| | | 1 | | using Elsa.Common.Models; |
| | | 2 | | using Elsa.Workflows.Management.Entities; |
| | | 3 | | using Elsa.Workflows.Management.Filters; |
| | | 4 | | using Elsa.Workflows.Models; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Workflows.Management.Activities.WorkflowDefinitionActivity; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Provides activity descriptors based on <see cref="WorkflowDefinition"/>s stored in the database. |
| | | 10 | | /// </summary> |
| | 324 | 11 | | public class WorkflowDefinitionActivityProvider(IWorkflowDefinitionStore store, WorkflowDefinitionActivityDescriptorFact |
| | | 12 | | { |
| | | 13 | | /// <inheritdoc /> |
| | | 14 | | public async ValueTask<IEnumerable<ActivityDescriptor>> GetDescriptorsAsync(CancellationToken cancellationToken = de |
| | | 15 | | { |
| | 65 | 16 | | var filter = new WorkflowDefinitionFilter |
| | 65 | 17 | | { |
| | 65 | 18 | | UsableAsActivity = true, |
| | 65 | 19 | | VersionOptions = VersionOptions.All |
| | 65 | 20 | | }; |
| | | 21 | | |
| | 65 | 22 | | var definitions = (await store.FindManyAsync(filter, cancellationToken)).ToList(); |
| | 65 | 23 | | return CreateDescriptors(definitions).ToList(); |
| | 65 | 24 | | } |
| | | 25 | | |
| | | 26 | | private IEnumerable<ActivityDescriptor> CreateDescriptors(ICollection<WorkflowDefinition> definitions) |
| | | 27 | | { |
| | 829 | 28 | | return definitions.Select(x => CreateDescriptor(x, definitions)); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | private ActivityDescriptor CreateDescriptor(WorkflowDefinition definition, ICollection<WorkflowDefinition> allDefini |
| | | 32 | | { |
| | 764 | 33 | | var latestPublishedVersion = allDefinitions |
| | 9178 | 34 | | .Where(x => x.DefinitionId == definition.DefinitionId && x.IsPublished) |
| | 1379 | 35 | | .MaxBy(x => x.Version); |
| | 764 | 36 | | return workflowDefinitionActivityDescriptorFactory.CreateDescriptor(definition, latestPublishedVersion); |
| | | 37 | | } |
| | | 38 | | } |