| | | 1 | | using System.Runtime.CompilerServices; |
| | | 2 | | using Elsa.Workflows.Management.Options; |
| | | 3 | | using Elsa.Workflows.Models; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | using Microsoft.Extensions.Options; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Workflows.Management.Providers; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Provides activity descriptors based on a list of activity types registered in the <see cref="ManagementOptions"/>. |
| | | 11 | | /// </summary> |
| | | 12 | | [UsedImplicitly] |
| | | 13 | | public class TypedActivityProvider : IActivityProvider |
| | | 14 | | { |
| | | 15 | | private readonly IActivityDescriber _activityDescriber; |
| | | 16 | | private readonly ManagementOptions _options; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Initializes a new instance of the <see cref="TypedActivityProvider"/> class. |
| | | 20 | | /// </summary> |
| | 324 | 21 | | public TypedActivityProvider(IOptions<ManagementOptions> options, IActivityDescriber activityDescriber) |
| | | 22 | | { |
| | 324 | 23 | | _activityDescriber = activityDescriber; |
| | 324 | 24 | | _options = options.Value; |
| | 324 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | | 28 | | public async ValueTask<IEnumerable<ActivityDescriptor>> GetDescriptorsAsync(CancellationToken cancellationToken = de |
| | | 29 | | { |
| | 2 | 30 | | var activityTypes = _options.ActivityTypes; |
| | 2 | 31 | | var descriptors = await DescribeActivityTypesAsync(activityTypes, cancellationToken).ToListAsync(cancellationTok |
| | 2 | 32 | | return descriptors; |
| | 2 | 33 | | } |
| | | 34 | | |
| | | 35 | | private async IAsyncEnumerable<ActivityDescriptor> DescribeActivityTypesAsync(IEnumerable<Type> activityTypes, [Enum |
| | | 36 | | { |
| | 224 | 37 | | foreach (var activityType in activityTypes) |
| | | 38 | | { |
| | 110 | 39 | | var descriptor = await _activityDescriber.DescribeActivityAsync(activityType, cancellationToken); |
| | 110 | 40 | | yield return descriptor; |
| | | 41 | | } |
| | 2 | 42 | | } |
| | | 43 | | } |