| | | 1 | | using Elsa.Workflows.Models; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Workflows; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Represents a service used to lookup activity descriptors in the activity registry. |
| | | 7 | | /// </summary> |
| | 851 | 8 | | public class ActivityRegistryLookupService(IActivityRegistry activityRegistry, IEnumerable<IActivityProvider> providers) |
| | | 9 | | { |
| | | 10 | | /// <inheritdoc /> |
| | | 11 | | public Task<ActivityDescriptor?> FindAsync(string type) |
| | | 12 | | { |
| | 102 | 13 | | return FindAsync(() => activityRegistry.Find(type)); |
| | | 14 | | } |
| | | 15 | | |
| | | 16 | | /// <inheritdoc /> |
| | | 17 | | public Task<ActivityDescriptor?> FindAsync(string type, int version) |
| | | 18 | | { |
| | 41148 | 19 | | return FindAsync(() => activityRegistry.Find(type, version)); |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | | 23 | | public Task<ActivityDescriptor?> FindAsync(Func<ActivityDescriptor, bool> predicate) |
| | | 24 | | { |
| | 0 | 25 | | return FindAsync(() => activityRegistry.Find(predicate)); |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <inheritdoc /> |
| | | 29 | | public IEnumerable<ActivityDescriptor> FindMany(Func<ActivityDescriptor, bool> predicate) |
| | | 30 | | { |
| | 0 | 31 | | return activityRegistry.FindMany(predicate); |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | private async Task<ActivityDescriptor?> FindAsync(Func<ActivityDescriptor?> findPredicate) |
| | | 35 | | { |
| | 20304 | 36 | | var descriptor = findPredicate.Invoke(); |
| | 20304 | 37 | | if (descriptor is not null) |
| | 19662 | 38 | | return descriptor; |
| | | 39 | | |
| | 642 | 40 | | await activityRegistry.RefreshDescriptorsAsync(providers); |
| | 642 | 41 | | return findPredicate.Invoke(); |
| | 20304 | 42 | | } |
| | | 43 | | } |