| | | 1 | | using System.ComponentModel; |
| | | 2 | | using System.ComponentModel.DataAnnotations; |
| | | 3 | | using System.Reflection; |
| | | 4 | | using Elsa.Abstractions; |
| | | 5 | | using Elsa.Extensions; |
| | | 6 | | using Elsa.Models; |
| | | 7 | | using Humanizer; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowActivationStrategies.List; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Returns list of available <see cref="IWorkflowActivationStrategy" /> implementations. |
| | | 13 | | /// </summary> |
| | | 14 | | internal class List(IEnumerable<IWorkflowActivationStrategy> strategies) : ElsaEndpointWithoutRequest<ListResponse<Workf |
| | | 15 | | { |
| | | 16 | | public override void Configure() |
| | | 17 | | { |
| | | 18 | | Get("/descriptors/workflow-activation-strategies"); |
| | | 19 | | ConfigurePermissions("read:workflow-activation-strategies"); |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | public override Task<ListResponse<WorkflowActivationStrategyDescriptor>> ExecuteAsync(CancellationToken cancellation |
| | | 23 | | { |
| | | 24 | | var descriptors = strategies.Select(WorkflowActivationStrategyDescriptor.FromStrategy).OrderBy(x => x.DisplayNam |
| | | 25 | | var response =new ListResponse<WorkflowActivationStrategyDescriptor>(descriptors); |
| | | 26 | | return Task.FromResult(response); |
| | | 27 | | } |
| | | 28 | | } |
| | | 29 | | |
| | 0 | 30 | | internal record WorkflowActivationStrategyDescriptor(string DisplayName, string Description, string TypeName) |
| | | 31 | | { |
| | | 32 | | public static WorkflowActivationStrategyDescriptor FromStrategy(IWorkflowActivationStrategy strategy) |
| | | 33 | | { |
| | 0 | 34 | | var type = strategy.GetType(); |
| | 0 | 35 | | var displayNameAttribute = type.GetCustomAttribute<DisplayNameAttribute>(); |
| | 0 | 36 | | var descriptionAttribute = type.GetCustomAttribute<DescriptionAttribute>(); |
| | 0 | 37 | | var displayAttribute = type.GetCustomAttribute<DisplayAttribute>(); |
| | 0 | 38 | | var displayName = displayNameAttribute?.DisplayName ?? displayAttribute?.Name ?? type.Name.Replace("Strategy", " |
| | 0 | 39 | | var description = descriptionAttribute?.Description ?? displayAttribute?.Description ?? ""; |
| | | 40 | | |
| | 0 | 41 | | return new WorkflowActivationStrategyDescriptor(displayName, description, type.GetSimpleAssemblyQualifiedName()) |
| | | 42 | | } |
| | | 43 | | } |