2023-09-22 09:13:23 +00:00
|
|
|
using System.Reflection;
|
2023-08-06 18:55:24 +00:00
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using Elsa.Extensions;
|
Add a more generic UIHandler to customize how inputAttributes can be handle by UI (#4688)
* 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>
2023-12-26 17:56:29 +00:00
|
|
|
using Elsa.Workflows;
|
|
|
|
|
using Elsa.Workflows.Attributes;
|
|
|
|
|
using Elsa.Workflows.Contracts;
|
|
|
|
|
using Elsa.Workflows.UIHints;
|
|
|
|
|
using Elsa.Workflows.Models;
|
2023-08-06 18:55:24 +00:00
|
|
|
|
|
|
|
|
namespace Elsa.Http;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Send an HTTP request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Activity("Elsa", "HTTP", "Send an HTTP request.", DisplayName = "HTTP Request (flow)", Kind = ActivityKind.Task)]
|
2023-09-22 09:13:23 +00:00
|
|
|
public class FlowSendHttpRequest : SendHttpRequestBase, IActivityPropertyDefaultValueProvider
|
2023-08-06 18:55:24 +00:00
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public FlowSendHttpRequest([CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(source, line)
|
|
|
|
|
{
|
|
|
|
|
}
|
2023-09-22 09:13:23 +00:00
|
|
|
|
2023-08-06 18:55:24 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// A list of expected status codes to handle.
|
|
|
|
|
/// </summary>
|
2023-09-22 09:13:23 +00:00
|
|
|
[Input(
|
|
|
|
|
Description = "A list of expected status codes to handle.",
|
|
|
|
|
UIHint = InputUIHints.MultiText,
|
|
|
|
|
DefaultValueProvider = typeof(FlowSendHttpRequest)
|
|
|
|
|
)]
|
2023-08-06 18:55:24 +00:00
|
|
|
public Input<ICollection<int>> ExpectedStatusCodes { get; set; } = default!;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override async ValueTask HandleResponseAsync(ActivityExecutionContext context, HttpResponseMessage response)
|
|
|
|
|
{
|
|
|
|
|
var expectedStatusCodes = ExpectedStatusCodes.GetOrDefault(context) ?? new List<int>(0);
|
|
|
|
|
var statusCode = (int)response.StatusCode;
|
|
|
|
|
var hasMatchingStatusCode = expectedStatusCodes.Contains(statusCode);
|
2023-11-22 19:46:12 +00:00
|
|
|
var outcome = expectedStatusCodes.Any() ? hasMatchingStatusCode ? statusCode.ToString() : "Unmatched status code" : default;
|
|
|
|
|
var outcomes = new List<string>();
|
2023-08-06 18:55:24 +00:00
|
|
|
|
2023-11-22 19:46:12 +00:00
|
|
|
if (outcome != null)
|
|
|
|
|
outcomes.Add(outcome);
|
|
|
|
|
|
|
|
|
|
outcomes.Add("Done");
|
|
|
|
|
await context.CompleteActivityWithOutcomesAsync(outcomes.ToArray());
|
2023-08-06 18:55:24 +00:00
|
|
|
}
|
2023-09-07 18:34:53 +00:00
|
|
|
|
2023-09-10 19:31:57 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override async ValueTask HandleRequestExceptionAsync(ActivityExecutionContext context, HttpRequestException exception)
|
|
|
|
|
{
|
|
|
|
|
await context.CompleteActivityWithOutcomesAsync("Failed to connect");
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-18 13:56:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override async ValueTask HandleTaskCanceledExceptionAsync(ActivityExecutionContext context, TaskCanceledException exception)
|
|
|
|
|
{
|
|
|
|
|
await context.CompleteActivityWithOutcomesAsync("Timeout");
|
|
|
|
|
}
|
2023-09-22 09:13:23 +00:00
|
|
|
|
|
|
|
|
object IActivityPropertyDefaultValueProvider.GetDefaultValue(PropertyInfo property)
|
|
|
|
|
{
|
|
|
|
|
if (property.Name == nameof(ExpectedStatusCodes))
|
|
|
|
|
{
|
|
|
|
|
return new List<int> { 200 };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return default!;
|
|
|
|
|
}
|
2023-08-06 18:55:24 +00:00
|
|
|
}
|