Add Default Syntax and Supported Syntax activity property attributes
This commit is contained in:
parent
2f12ed68cc
commit
09892074bb
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Elsa.Attributes
|
||||
{
|
||||
|
|
@ -49,5 +50,15 @@ namespace Elsa.Attributes
|
|||
/// The type that provides a default value.
|
||||
/// </summary>
|
||||
public Type? DefaultValueProvider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The syntax to use by default when evaluating the value. Only used when the property definition doesn't have a syntax specified.
|
||||
/// </summary>
|
||||
public string? DefaultSyntax { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The syntax to use by default when evaluating the value. Only used when the property definition doesn't have a syntax specified.
|
||||
/// </summary>
|
||||
public string[]? SupportedSyntaxes { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Elsa.Metadata
|
||||
{
|
||||
public class ActivityPropertyDescriptor
|
||||
|
|
@ -6,23 +10,39 @@ namespace Elsa.Metadata
|
|||
{
|
||||
}
|
||||
|
||||
public ActivityPropertyDescriptor(string name, string uiHint, string label, string? hint = default, object? options = default, string? category = default, object? defaultValue = default)
|
||||
public ActivityPropertyDescriptor(
|
||||
string name,
|
||||
Type type,
|
||||
string uiHint,
|
||||
string label,
|
||||
string? hint = default,
|
||||
object? options = default,
|
||||
string? category = default,
|
||||
object? defaultValue = default,
|
||||
string? defaultSyntax = "Literal",
|
||||
IEnumerable<string>? supportedSyntaxes = default)
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
UIHint = uiHint;
|
||||
Label = label;
|
||||
Hint = hint;
|
||||
Options = options;
|
||||
Category = category;
|
||||
DefaultValue = defaultValue;
|
||||
DefaultSyntax = defaultSyntax;
|
||||
SupportedSyntaxes = supportedSyntaxes?.ToList() ?? new List<string>();
|
||||
}
|
||||
|
||||
|
||||
public string Name { get; set; } = default!;
|
||||
public Type Type { get; set; } = default!;
|
||||
public string UIHint { get; set; } = default!;
|
||||
public string Label { get; set; } = default!;
|
||||
public string? Hint { get; set; }
|
||||
public object? Options { get; set; }
|
||||
public string? Category { get; set; }
|
||||
public object? DefaultValue { get; set; }
|
||||
public string? DefaultSyntax { get; set; }
|
||||
public IList<string> SupportedSyntaxes { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
|
|
@ -57,12 +57,15 @@ namespace Elsa.Metadata
|
|||
yield return new ActivityPropertyDescriptor
|
||||
(
|
||||
(activityPropertyAttribute.Name ?? propertyInfo.Name).Pascalize(),
|
||||
propertyInfo.PropertyType,
|
||||
_uiHintResolver.GetUIHint(propertyInfo),
|
||||
activityPropertyAttribute.Label ?? propertyInfo.Name.Humanize(LetterCasing.Title),
|
||||
activityPropertyAttribute.Hint,
|
||||
_optionsResolver.GetOptions(propertyInfo),
|
||||
activityPropertyAttribute.Category,
|
||||
_defaultValueResolver.GetDefaultValue(propertyInfo)
|
||||
_defaultValueResolver.GetDefaultValue(propertyInfo),
|
||||
activityPropertyAttribute.DefaultSyntax,
|
||||
activityPropertyAttribute.SupportedSyntaxes
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using Elsa.ActivityProviders;
|
||||
using Elsa.Builders;
|
||||
using Elsa.Expressions;
|
||||
using Elsa.Models;
|
||||
using Elsa.Services.Models;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
@ -73,20 +74,21 @@ namespace Elsa.Services
|
|||
foreach (var activityDefinition in activityDefinitions)
|
||||
{
|
||||
var activityType = await _activityTypeService.GetActivityTypeAsync(activityDefinition.Type, cancellationToken);
|
||||
var type = activityType.Type;
|
||||
var props = type.GetProperties();
|
||||
var activityDescriptor = activityType.Describe();
|
||||
var propertyDescriptors = activityDescriptor.Properties;
|
||||
|
||||
foreach (var property in activityDefinition.Properties)
|
||||
{
|
||||
var prop = props.FirstOrDefault(x => x.Name == property.Name);
|
||||
|
||||
if (prop == null)
|
||||
var propertyDescriptor = propertyDescriptors.FirstOrDefault(x => x.Name == property.Name);
|
||||
|
||||
if (propertyDescriptor == null)
|
||||
{
|
||||
_logger.LogWarning("Could not find the specified property '{PropertyName}' for activity type {ActivityTypeName}. Was the activity property renamed/removed/refactored after the workflow definition was created?", property.Name, activityType.Type.Name);
|
||||
_logger.LogWarning("Could not find the specified property '{PropertyName}' for activity type {ActivityTypeName}", property.Name, activityType.TypeName);
|
||||
continue;
|
||||
}
|
||||
|
||||
var provider = new ExpressionActivityPropertyValueProvider(property.Expression, property.Syntax ?? "Literal", prop.PropertyType);
|
||||
var syntax = property.Syntax ?? propertyDescriptor.DefaultSyntax ?? SyntaxNames.Literal;
|
||||
var provider = new ExpressionActivityPropertyValueProvider(property.Expression, syntax, propertyDescriptor.Type);
|
||||
propertyProviders.AddProvider(activityDefinition.ActivityId, property.Name, provider);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue