Update activity type providers
This commit is contained in:
parent
c892a11de7
commit
8a0fd05973
|
|
@ -40,19 +40,26 @@ namespace Elsa.Activities.Conductor.Providers.ActivityTypes
|
|||
|
||||
private async Task<ActivityType> CreateActivityTypeAsync(CommandDefinition command, CancellationToken cancellationToken)
|
||||
{
|
||||
var descriptor = await _describesActivityType.DescribeAsync<SendCommand>(cancellationToken);
|
||||
async ValueTask<ActivityDescriptor> CreateDescriptorAsync()
|
||||
{
|
||||
var des = await _describesActivityType.DescribeAsync<SendCommand>(cancellationToken);
|
||||
|
||||
descriptor.Type = command.Name;
|
||||
descriptor.DisplayName = command.DisplayName ?? command.Name;
|
||||
descriptor.Description = command.Description;
|
||||
descriptor.InputProperties = descriptor.InputProperties.Where(x => x.Name != nameof(SendCommand.CommandName)).ToArray();
|
||||
des.Type = command.Name;
|
||||
des.DisplayName = command.DisplayName ?? command.Name;
|
||||
des.Description = command.Description;
|
||||
des.InputProperties = des.InputProperties.Where(x => x.Name != nameof(SendCommand.CommandName)).ToArray();
|
||||
|
||||
return des;
|
||||
}
|
||||
|
||||
var descriptor = await CreateDescriptorAsync();
|
||||
|
||||
return new ActivityType
|
||||
{
|
||||
Type = typeof(SendCommand),
|
||||
TypeName = descriptor.Type,
|
||||
DisplayName = descriptor.DisplayName,
|
||||
Describe = () => descriptor,
|
||||
DescribeAsync = CreateDescriptorAsync,
|
||||
Description = descriptor.Description,
|
||||
ActivateAsync = async context =>
|
||||
{
|
||||
|
|
@ -66,7 +73,7 @@ namespace Elsa.Activities.Conductor.Providers.ActivityTypes
|
|||
};
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<CommandDefinition>> GetCommandsAsync(CancellationToken cancellationToken) =>
|
||||
private async Task<IEnumerable<CommandDefinition>> GetCommandsAsync(CancellationToken cancellationToken) =>
|
||||
await _scopedCommandsProviders.UseServiceAsync(async commandProviders => await GetCommandsAsync(commandProviders, cancellationToken).ToListAsync(cancellationToken));
|
||||
|
||||
private static async IAsyncEnumerable<CommandDefinition> GetCommandsAsync(IEnumerable<ICommandsProvider> commandProviders, [EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
|
|
|
|||
|
|
@ -40,20 +40,27 @@ namespace Elsa.Activities.Conductor.Providers.ActivityTypes
|
|||
|
||||
private async Task<ActivityType> CreateActivityTypeAsync(EventDefinition eventDefinition, CancellationToken cancellationToken)
|
||||
{
|
||||
var descriptor = await _describesActivityType.DescribeAsync<EventReceived>(cancellationToken);
|
||||
async ValueTask<ActivityDescriptor> CreateDescriptorAsync()
|
||||
{
|
||||
var des = await _describesActivityType.DescribeAsync<EventReceived>(cancellationToken);
|
||||
|
||||
descriptor.Type = eventDefinition.Name;
|
||||
descriptor.DisplayName = eventDefinition.DisplayName ?? eventDefinition.Name;
|
||||
descriptor.Description = eventDefinition.Description;
|
||||
descriptor.InputProperties = Array.Empty<ActivityInputDescriptor>();
|
||||
descriptor.Outcomes = eventDefinition.Outcomes?.ToArray() ?? new[] { OutcomeNames.Done };
|
||||
des.Type = eventDefinition.Name;
|
||||
des.DisplayName = eventDefinition.DisplayName ?? eventDefinition.Name;
|
||||
des.Description = eventDefinition.Description;
|
||||
des.InputProperties = Array.Empty<ActivityInputDescriptor>();
|
||||
des.Outcomes = eventDefinition.Outcomes?.ToArray() ?? new[] { OutcomeNames.Done };
|
||||
|
||||
return des;
|
||||
}
|
||||
|
||||
var descriptor = await CreateDescriptorAsync();
|
||||
|
||||
return new ActivityType
|
||||
{
|
||||
Type = typeof(EventReceived),
|
||||
TypeName = descriptor.Type,
|
||||
DisplayName = descriptor.DisplayName,
|
||||
Describe = () => descriptor,
|
||||
DescribeAsync = CreateDescriptorAsync,
|
||||
Description = descriptor.Description,
|
||||
ActivateAsync = async context =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -40,20 +40,27 @@ namespace Elsa.Activities.Conductor.Providers.ActivityTypes
|
|||
|
||||
private async Task<ActivityType> CreateActivityTypeAsync(TaskDefinition taskDefinition, CancellationToken cancellationToken)
|
||||
{
|
||||
var descriptor = await _describesActivityType.DescribeAsync<RunTask>(cancellationToken);
|
||||
async ValueTask<ActivityDescriptor> CreateDescriptorAsync()
|
||||
{
|
||||
var des = await _describesActivityType.DescribeAsync<RunTask>(cancellationToken);
|
||||
|
||||
descriptor.Type = taskDefinition.Name;
|
||||
descriptor.DisplayName = taskDefinition.DisplayName ?? taskDefinition.Name;
|
||||
descriptor.Description = taskDefinition.Description;
|
||||
descriptor.InputProperties = Array.Empty<ActivityInputDescriptor>();
|
||||
descriptor.Outcomes = taskDefinition.Outcomes?.ToArray() ?? new[] { OutcomeNames.Done };
|
||||
des.Type = taskDefinition.Name;
|
||||
des.DisplayName = taskDefinition.DisplayName ?? taskDefinition.Name;
|
||||
des.Description = taskDefinition.Description;
|
||||
des.InputProperties = Array.Empty<ActivityInputDescriptor>();
|
||||
des.Outcomes = taskDefinition.Outcomes?.ToArray() ?? new[] { OutcomeNames.Done };
|
||||
|
||||
return des;
|
||||
}
|
||||
|
||||
var descriptor = await CreateDescriptorAsync();
|
||||
|
||||
return new ActivityType
|
||||
{
|
||||
Type = typeof(RunTask),
|
||||
TypeName = descriptor.Type,
|
||||
DisplayName = descriptor.DisplayName,
|
||||
Describe = () => descriptor,
|
||||
DescribeAsync = CreateDescriptorAsync,
|
||||
Description = descriptor.Description,
|
||||
ActivateAsync = async context =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,19 +59,26 @@ namespace Elsa.Activities.Telnyx.Providers.ActivityTypes
|
|||
|
||||
private async Task<ActivityType> CreateWebhookActivityTypeAsync(Type payloadType, WebhookAttribute webhookAttribute, CancellationToken cancellationToken)
|
||||
{
|
||||
var descriptor = await _describesActivityType.DescribeAsync<Webhook>(cancellationToken);
|
||||
async ValueTask<ActivityDescriptor> CreateDescriptorAsync()
|
||||
{
|
||||
var des = await _describesActivityType.DescribeAsync<Webhook>(cancellationToken);
|
||||
|
||||
descriptor.Description = webhookAttribute.Description;
|
||||
descriptor.DisplayName = webhookAttribute.DisplayName;
|
||||
descriptor.Type = webhookAttribute.ActivityType;
|
||||
des.Description = webhookAttribute.Description;
|
||||
des.DisplayName = webhookAttribute.DisplayName;
|
||||
des.Type = webhookAttribute.ActivityType;
|
||||
|
||||
var outputProperties = descriptor.OutputProperties.Where(x => x.Name != nameof(Webhook.Output)).ToList();
|
||||
outputProperties.Add(new ActivityOutputDescriptor(nameof(Webhook.Output), payloadType));
|
||||
descriptor.OutputProperties = outputProperties.ToArray();
|
||||
var outputProperties = des.OutputProperties.Where(x => x.Name != nameof(Webhook.Output)).ToList();
|
||||
outputProperties.Add(new ActivityOutputDescriptor(nameof(Webhook.Output), payloadType));
|
||||
des.OutputProperties = outputProperties.ToArray();
|
||||
|
||||
return des;
|
||||
}
|
||||
|
||||
var descriptor = await CreateDescriptorAsync();
|
||||
|
||||
return new ActivityType
|
||||
{
|
||||
Describe = () => descriptor,
|
||||
DescribeAsync = CreateDescriptorAsync,
|
||||
Description = descriptor.Description,
|
||||
DisplayName = descriptor.DisplayName,
|
||||
TypeName = descriptor.Type,
|
||||
|
|
|
|||
|
|
@ -54,52 +54,57 @@ namespace Elsa.Activities.Webhooks.ActivityTypes
|
|||
var activityTypeName = webhook.Name.EndsWith(WebhooksActivityTypeSuffix) ? webhook.Name : $"{webhook.Name}{WebhooksActivityTypeSuffix}";
|
||||
var activityDisplayName = activityTypeName.Humanize();
|
||||
|
||||
var descriptor = new ActivityDescriptor
|
||||
ValueTask<ActivityDescriptor> CreateDescriptorAsync()
|
||||
{
|
||||
Type = activityTypeName,
|
||||
DisplayName = activityDisplayName,
|
||||
Category = WebhooksActivityCategory,
|
||||
Outcomes = new[] { OutcomeNames.Done },
|
||||
Traits = ActivityTraits.Trigger,
|
||||
InputProperties = new[]
|
||||
var descriptor = new ActivityDescriptor
|
||||
{
|
||||
new ActivityInputDescriptor(
|
||||
nameof(HttpEndpoint.Path),
|
||||
typeof(PathString),
|
||||
ActivityInputUIHints.SingleLine,
|
||||
"Path",
|
||||
"The relative path that triggers this activity.",
|
||||
null,
|
||||
default,
|
||||
0,
|
||||
webhook.Path,
|
||||
SyntaxNames.Literal,
|
||||
new[] { SyntaxNames.Literal },
|
||||
true
|
||||
Type = activityTypeName!,
|
||||
DisplayName = activityDisplayName!,
|
||||
Category = WebhooksActivityCategory,
|
||||
Outcomes = new[] { OutcomeNames.Done },
|
||||
Traits = ActivityTraits.Trigger,
|
||||
InputProperties = new[]
|
||||
{
|
||||
new ActivityInputDescriptor(
|
||||
nameof(HttpEndpoint.Path),
|
||||
typeof(PathString),
|
||||
ActivityInputUIHints.SingleLine,
|
||||
"Path",
|
||||
"The relative path that triggers this activity.",
|
||||
null,
|
||||
default,
|
||||
0,
|
||||
webhook.Path,
|
||||
SyntaxNames.Literal,
|
||||
new[] { SyntaxNames.Literal },
|
||||
true
|
||||
),
|
||||
new ActivityInputDescriptor(
|
||||
nameof(HttpEndpoint.Methods),
|
||||
typeof(HashSet<string>),
|
||||
ActivityInputUIHints.CheckList,
|
||||
"Request Method",
|
||||
"Specify what request method this webhook should handle. Leave empty to handle both GET and POST requests",
|
||||
new[] { "GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD" },
|
||||
default,
|
||||
1,
|
||||
new[] { "GET", "POST" },
|
||||
SyntaxNames.Json,
|
||||
new[] { SyntaxNames.Json, SyntaxNames.JavaScript, SyntaxNames.Liquid }
|
||||
new ActivityInputDescriptor(
|
||||
nameof(HttpEndpoint.Methods),
|
||||
typeof(HashSet<string>),
|
||||
ActivityInputUIHints.CheckList,
|
||||
"Request Method",
|
||||
"Specify what request method this webhook should handle. Leave empty to handle both GET and POST requests",
|
||||
new[] { "GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD" },
|
||||
default,
|
||||
1,
|
||||
new[] { "GET", "POST" },
|
||||
SyntaxNames.Json,
|
||||
new[] { SyntaxNames.Json, SyntaxNames.JavaScript, SyntaxNames.Liquid }
|
||||
)
|
||||
},
|
||||
OutputProperties = new[]
|
||||
{
|
||||
new ActivityOutputDescriptor
|
||||
(
|
||||
"Request",
|
||||
typeof(Models.WebhookRequestModel),
|
||||
"The received HTTP request."
|
||||
)
|
||||
}
|
||||
},
|
||||
OutputProperties = new[]
|
||||
{
|
||||
new ActivityOutputDescriptor
|
||||
(
|
||||
"Request",
|
||||
typeof(Models.WebhookRequestModel),
|
||||
"The received HTTP request."
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
return new ValueTask<ActivityDescriptor>(descriptor);
|
||||
};
|
||||
|
||||
async ValueTask<IActivity> ActivateActivityAsync(ActivityExecutionContext context)
|
||||
|
|
@ -123,7 +128,7 @@ namespace Elsa.Activities.Webhooks.ActivityTypes
|
|||
[WebhookMarkerAttribute] = true,
|
||||
["Path"] = webhook.Path,
|
||||
},
|
||||
Describe = () => descriptor
|
||||
DescribeAsync = CreateDescriptorAsync
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue