| | | 1 | | using System.ComponentModel; |
| | | 2 | | using System.ComponentModel.DataAnnotations; |
| | | 3 | | using System.Reflection; |
| | | 4 | | using Elsa.Abstractions; |
| | | 5 | | using Elsa.Extensions; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Workflows.Api.Endpoints.StorageDrivers.List; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Returns a list of registered <see cref="IStorageDriver"/> implementations. |
| | | 11 | | /// </summary> |
| | | 12 | | public class List : ElsaEndpointWithoutRequest<Response> |
| | | 13 | | { |
| | | 14 | | private readonly IStorageDriverManager _registry; |
| | | 15 | | |
| | | 16 | | /// <inheritdoc /> |
| | 1 | 17 | | public List(IStorageDriverManager registry) |
| | | 18 | | { |
| | 1 | 19 | | _registry = registry; |
| | 1 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | | 23 | | public override void Configure() |
| | | 24 | | { |
| | 1 | 25 | | Get("/descriptors/storage-drivers"); |
| | 1 | 26 | | ConfigurePermissions("read:*", "read:storage-drivers"); |
| | 1 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <inheritdoc /> |
| | | 30 | | public override Task<Response> ExecuteAsync(CancellationToken ct) |
| | | 31 | | { |
| | 0 | 32 | | var drivers = _registry.List(); |
| | 0 | 33 | | var descriptors = drivers.Select(FromDriver).OrderByDescending(x => x.Priority).ToList(); |
| | 0 | 34 | | var response = new Response(descriptors); |
| | | 35 | | |
| | 0 | 36 | | return Task.FromResult(response); |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | private static StorageDriverDescriptor FromDriver(IStorageDriver driver) |
| | | 40 | | { |
| | 0 | 41 | | var type = driver.GetType(); |
| | 0 | 42 | | var deprecated = type.GetCustomAttribute<ObsoleteAttribute>() != null; |
| | 0 | 43 | | var displayName = type.GetCustomAttribute<DisplayAttribute>()?.Name ?? type.GetCustomAttribute<DisplayNameAttrib |
| | 0 | 44 | | var priority = driver.Priority; |
| | 0 | 45 | | return new StorageDriverDescriptor(type.GetSimpleAssemblyQualifiedName(), displayName, priority, deprecated); |
| | | 46 | | } |
| | | 47 | | } |