* add a more generic UIHandler to customize how inputAttributes can be handle by the ui * Add IPropertyUIHandlerResolver and update PropertyUIHandlerResolver Introduced a new interface, IPropertyUIHandlerResolver, to resolve UI options for a property. Refactored PropertyUIHandlerResolver to implement this interface and removed the unnecessary partial class structure. Also, cleaned up some unnecessary usings in various files for better code organization. * Refactor variable name and description in InputDescriptor The 'uISpecifications' variable in the InputDescriptor model is renamed to 'uiSpecifications' for better readability. Additionally, the associated comment was revised to explain that the dictionary is used by the UI. * "Refactor codebase for improved organization and cleaner architecture" The codebase has been significantly refactored, moving several classes to more appropriate namespaces for improved organization and cleaner architecture. This includes shifting UI hint handlers, activities, and memory-related components, amongst others. The changes should improve code readability and maintainability, but as this is a broad refactoring effort, thorough regression testing is advised. * Add CheckList UIHint with associated handler and provider This update introduces a new UIHint called CheckList to the Elsa.Workflows.Core. This includes the necessary handler and provider classes. The handler is registered in the WorkflowsFeature.cs, and the CheckList UIHint key has been added to the InputUIHints.cs. Various associated files have been created in both the Elsa.Api.Client and Elsa.Workflows.Core project to support this new UIHint. --------- Co-authored-by: Jérémie DEVILLARD <jdevillard@users.noreply.github.com> Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
79 lines
3.1 KiB
C#
79 lines
3.1 KiB
C#
using Elsa.Expressions.Contracts;
|
|
using Elsa.Expressions.Extensions;
|
|
using Elsa.Expressions.Helpers;
|
|
using Elsa.Extensions;
|
|
using Elsa.Workflows.Memory;
|
|
using Elsa.Workflows.Models;
|
|
|
|
namespace Elsa.Workflows.Management.Mappers;
|
|
|
|
/// <summary>
|
|
/// Maps <see cref="Variable"/>s to <see cref="VariableDefinition"/>s and vice versa.
|
|
/// </summary>
|
|
public class VariableDefinitionMapper
|
|
{
|
|
private readonly IWellKnownTypeRegistry _wellKnownTypeRegistry;
|
|
|
|
/// <summary>
|
|
/// Constructor.
|
|
/// </summary>
|
|
public VariableDefinitionMapper(IWellKnownTypeRegistry wellKnownTypeRegistry)
|
|
{
|
|
_wellKnownTypeRegistry = wellKnownTypeRegistry;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Maps a <see cref="VariableDefinition"/> to a <see cref="Variable"/>.
|
|
/// </summary>
|
|
public Variable? Map(VariableDefinition source)
|
|
{
|
|
if (!_wellKnownTypeRegistry.TryGetTypeOrDefault(source.TypeName, out var type))
|
|
return null;
|
|
|
|
var valueType = source.IsArray ? typeof(ICollection<>).MakeGenericType(type) : type;
|
|
var variableGenericType = typeof(Variable<>).MakeGenericType(valueType);
|
|
var variable = (Variable)Activator.CreateInstance(variableGenericType)!;
|
|
|
|
if(!string.IsNullOrEmpty(source.Id))
|
|
variable.Id = source.Id;
|
|
|
|
variable.Name = source.Name;
|
|
variable.Value = source.Value.ConvertTo(valueType);
|
|
variable.StorageDriverType = !string.IsNullOrEmpty(source.StorageDriverTypeName) ? Type.GetType(source.StorageDriverTypeName) : default;
|
|
|
|
return variable;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Maps a list of <see cref="VariableDefinition"/>s to a list of <see cref="Variable"/>.
|
|
/// </summary>
|
|
public IEnumerable<Variable> Map(IEnumerable<VariableDefinition>? source) =>
|
|
source?
|
|
.Select(Map)
|
|
.Where(x => x != null)
|
|
.Select(x => x!)
|
|
?? Enumerable.Empty<Variable>();
|
|
|
|
/// <summary>
|
|
/// Maps a <see cref="Variable"/> to a <see cref="VariableDefinition"/>.
|
|
/// </summary>
|
|
public VariableDefinition Map(Variable source)
|
|
{
|
|
var variableType = source.GetType();
|
|
var valueType = variableType.IsConstructedGenericType ? variableType.GetGenericArguments().FirstOrDefault() ?? typeof(object) : typeof(object);
|
|
var isArray = valueType.IsCollectionType();
|
|
var elementValueType = isArray ? valueType.GenericTypeArguments[0] : valueType;
|
|
var value = source.Value;
|
|
|
|
var valueTypeAlias = _wellKnownTypeRegistry.GetAliasOrDefault(elementValueType);
|
|
var storageDriverTypeName = source.StorageDriverType?.GetSimpleAssemblyQualifiedName();
|
|
var serializedValue = value.Format();
|
|
|
|
return new VariableDefinition(source.Id, source.Name, valueTypeAlias, isArray, serializedValue, storageDriverTypeName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Maps a list of <see cref="Variable"/>s to a list of <see cref="VariableDefinition"/>s.
|
|
/// </summary>
|
|
public IEnumerable<VariableDefinition> Map(IEnumerable<Variable>? source) => source?.Select(Map) ?? Enumerable.Empty<VariableDefinition>();
|
|
} |