using Elsa.Dsl.Features;
using Elsa.Dsl.Models;
using Elsa.Features.Abstractions;
using Elsa.Features.Attributes;
using Elsa.Features.Services;
using Elsa.Workflows.Management.HostedServices;
using Elsa.Workflows.Management.Options;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.Workflows.Management.Features;
///
/// Installs JavaScript activities.
///
[DependsOn(typeof(DslFeature))]
[PublicAPI]
public class DslIntegrationFeature : FeatureBase
{
private readonly IDictionary _dictionary = new Dictionary();
///
public DslIntegrationFeature(IModule module) : base(module)
{
}
///
/// Maps a function to an activity.
///
/// The name of the function.
/// The name of the activity type.
/// The names of the properties that are mapped to the function arguments.
/// An optional action that can be used to configure the activity.
public void MapActivityFunction(string functionName, string activityTypeName, IEnumerable? propertyNames = default, Action? configure = default)
{
_dictionary.Add(functionName, new FunctionActivityDescriptor(functionName, activityTypeName, propertyNames, configure));
}
///
public override void ConfigureHostedServices()
{
ConfigureHostedService(-1);
}
///
public override void Apply()
{
Services.Configure(options =>
{
options.FunctionActivityDescriptors = _dictionary;
});
}
}