| | | 1 | | using System.Reflection; |
| | | 2 | | using Elsa.Workflows.Attributes; |
| | | 3 | | using Elsa.Workflows.Models; |
| | | 4 | | using Microsoft.Extensions.DependencyInjection; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Workflows; |
| | | 7 | | |
| | | 8 | | /// <inheritdoc /> |
| | 528 | 9 | | public class PropertyUIHandlerResolver(IServiceScopeFactory scopeFactory) : IPropertyUIHandlerResolver |
| | | 10 | | { |
| | | 11 | | /// <inheritdoc /> |
| | | 12 | | public async ValueTask<IDictionary<string, object>> GetUIPropertiesAsync(PropertyInfo propertyInfo, object? context, |
| | | 13 | | { |
| | 17337 | 14 | | var inputAttribute = propertyInfo.GetCustomAttribute<InputAttribute>(); |
| | 17337 | 15 | | var result = new Dictionary<string, object>(); |
| | | 16 | | |
| | 17337 | 17 | | var uiHandlers = new List<Type>(); |
| | | 18 | | |
| | 17337 | 19 | | if (inputAttribute?.UIHandler != null) |
| | 1160 | 20 | | uiHandlers.Add(inputAttribute.UIHandler); |
| | | 21 | | |
| | 17337 | 22 | | if (inputAttribute?.UIHandlers != null) |
| | 0 | 23 | | uiHandlers.AddRange(inputAttribute.UIHandlers); |
| | | 24 | | |
| | 17337 | 25 | | using var scope = scopeFactory.CreateScope(); |
| | 17337 | 26 | | var uiHintHandlers = scope.ServiceProvider.GetServices<IUIHintHandler>(); |
| | | 27 | | |
| | 17337 | 28 | | var isWrapperProperty = typeof(Input).IsAssignableFrom(propertyInfo.PropertyType); |
| | 17337 | 29 | | var wrapperPropertyType = !isWrapperProperty ? propertyInfo.PropertyType : propertyInfo.PropertyType.GenericType |
| | 17337 | 30 | | var uiHint = ActivityDescriber.GetUIHint(wrapperPropertyType, inputAttribute); |
| | 17337 | 31 | | if (!string.IsNullOrWhiteSpace(uiHint)) |
| | | 32 | | { |
| | 73158 | 33 | | var uiHintHandler = uiHintHandlers.FirstOrDefault(x => x.UIHint == uiHint); |
| | | 34 | | |
| | 17337 | 35 | | if (uiHintHandler != null) |
| | | 36 | | { |
| | 3003 | 37 | | var defaultHandlers = await uiHintHandler.GetPropertyUIHandlersAsync(propertyInfo, cancellationToken); |
| | 3003 | 38 | | uiHandlers.AddRange(defaultHandlers); |
| | | 39 | | } |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | // Handlers are sorted by priority so that those with higher priority are processed last. |
| | | 43 | | // This allows them to override any existing property values set by lower-priority handlers. |
| | | 44 | | // For example, a default UI hint handler might provide dropdown options, but a custom module can supply its own |
| | 135431 | 45 | | var availablePropertyUIHandlers = scope.ServiceProvider.GetServices<IPropertyUIHandler>().OrderBy(x => x.Priorit |
| | 136591 | 46 | | var matchedPropertyHandlers = availablePropertyUIHandlers.Where(x => uiHandlers.Contains(x.GetType())).OrderBy(x |
| | | 47 | | |
| | 42872 | 48 | | foreach (var handler in matchedPropertyHandlers) |
| | | 49 | | { |
| | 4099 | 50 | | var properties = await handler.GetUIPropertiesAsync(propertyInfo, context, cancellationToken); |
| | | 51 | | |
| | 12798 | 52 | | foreach (var property in properties) |
| | 2300 | 53 | | result[property.Key] = property.Value; |
| | | 54 | | } |
| | | 55 | | |
| | 17337 | 56 | | return result; |
| | 17337 | 57 | | } |
| | | 58 | | } |