2022-11-23 10:20:00 +00:00
|
|
|
using Elsa.Common.Features;
|
2023-09-19 20:42:53 +00:00
|
|
|
using Elsa.Expressions.Options;
|
2022-12-31 15:16:43 +00:00
|
|
|
using Elsa.Extensions;
|
2022-05-27 10:36:39 +00:00
|
|
|
using Elsa.Features.Abstractions;
|
2022-11-23 10:20:00 +00:00
|
|
|
using Elsa.Features.Attributes;
|
2022-05-27 10:36:39 +00:00
|
|
|
using Elsa.Features.Services;
|
2022-10-25 13:52:55 +00:00
|
|
|
using Elsa.Http.ContentWriters;
|
2023-03-03 21:47:23 +00:00
|
|
|
using Elsa.Http.Contracts;
|
2023-09-17 20:35:13 +00:00
|
|
|
using Elsa.Http.DownloadableContentHandlers;
|
|
|
|
|
using Elsa.Http.FileCaches;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Http.Handlers;
|
2023-04-17 13:23:05 +00:00
|
|
|
using Elsa.Http.HostedServices;
|
2023-03-07 13:54:21 +00:00
|
|
|
using Elsa.Http.Models;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Http.Options;
|
2022-10-25 13:52:55 +00:00
|
|
|
using Elsa.Http.Parsers;
|
2023-03-11 21:14:39 +00:00
|
|
|
using Elsa.Http.PortResolvers;
|
2023-08-23 08:48:12 +00:00
|
|
|
using Elsa.Http.Selectors;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Http.Services;
|
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.Http.UIHints;
|
|
|
|
|
using Elsa.Workflows.Contracts;
|
2023-07-14 17:19:41 +00:00
|
|
|
using Elsa.Workflows.Management.Requests;
|
|
|
|
|
using Elsa.Workflows.Management.Responses;
|
2023-09-17 20:35:13 +00:00
|
|
|
using FluentStorage;
|
2023-01-16 18:42:45 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Routing;
|
2023-09-16 09:43:34 +00:00
|
|
|
using Microsoft.AspNetCore.StaticFiles;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2023-09-21 17:42:41 +00:00
|
|
|
using Microsoft.Extensions.Options;
|
2022-05-26 10:47:31 +00:00
|
|
|
|
2022-05-27 10:36:39 +00:00
|
|
|
namespace Elsa.Http.Features;
|
2022-05-26 10:47:31 +00:00
|
|
|
|
2023-02-15 11:09:45 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Installs services related to HTTP services and activities.
|
|
|
|
|
/// </summary>
|
2022-11-23 10:20:00 +00:00
|
|
|
[DependsOn(typeof(MemoryCacheFeature))]
|
2022-05-27 10:36:39 +00:00
|
|
|
public class HttpFeature : FeatureBase
|
2022-05-26 10:47:31 +00:00
|
|
|
{
|
2023-02-15 11:09:45 +00:00
|
|
|
/// <inheritdoc />
|
2022-05-27 10:36:39 +00:00
|
|
|
public HttpFeature(IModule module) : base(module)
|
2022-05-26 10:47:31 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 18:42:45 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// A delegate to configure <see cref="HttpActivityOptions"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action<HttpActivityOptions>? ConfigureHttpOptions { get; set; }
|
|
|
|
|
|
2023-09-17 20:35:13 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// A delegate to configure <see cref="HttpFileCacheOptions"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action<HttpFileCacheOptions>? ConfigureHttpFileCacheOptions { get; set; }
|
|
|
|
|
|
2023-02-15 11:09:45 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// A delegate that is invoked when authorizing an inbound HTTP request.
|
|
|
|
|
/// </summary>
|
2023-12-28 18:46:38 +00:00
|
|
|
public Func<IServiceProvider, IHttpEndpointAuthorizationHandler> HttpEndpointAuthorizationHandler { get; set; } = sp => sp.GetRequiredService<AuthenticationBasedHttpEndpointAuthorizationHandler>();
|
2023-03-08 08:49:43 +00:00
|
|
|
|
2023-02-15 11:09:45 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// A delegate that is invoked when an HTTP workflow faults.
|
|
|
|
|
/// </summary>
|
2023-09-19 20:42:53 +00:00
|
|
|
public Func<IServiceProvider, IHttpEndpointFaultHandler> HttpEndpointWorkflowFaultHandler { get; set; } = sp => sp.GetRequiredService<DefaultHttpEndpointFaultHandler>();
|
2023-09-17 20:35:13 +00:00
|
|
|
|
2023-09-16 09:43:34 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// A delegate to configure the <see cref="IContentTypeProvider"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Func<IServiceProvider, IContentTypeProvider> ContentTypeProvider { get; set; } = _ => new FileExtensionContentTypeProvider();
|
2022-05-26 10:47:31 +00:00
|
|
|
|
2023-09-17 20:35:13 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// A delegate to configure the <see cref="IFileCacheStorageProvider"/>.
|
|
|
|
|
/// </summary>
|
2023-09-21 17:42:41 +00:00
|
|
|
public Func<IServiceProvider, IFileCacheStorageProvider> FileCache { get; set; } = sp =>
|
2023-09-17 20:35:13 +00:00
|
|
|
{
|
2023-09-21 17:42:41 +00:00
|
|
|
var options = sp.GetRequiredService<IOptions<HttpFileCacheOptions>>().Value;
|
|
|
|
|
var blobStorage = StorageFactory.Blobs.DirectoryFiles(options.LocalCacheDirectory);
|
2023-09-17 20:35:13 +00:00
|
|
|
return new BlobFileCacheStorageProvider(blobStorage);
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-16 18:42:45 +00:00
|
|
|
/// <summary>
|
2023-03-07 12:45:58 +00:00
|
|
|
/// A delegate to configure the <see cref="HttpClient"/> used when by the <see cref="FlowSendHttpRequest"/> activity.
|
2023-01-16 18:42:45 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public Action<IServiceProvider, HttpClient> HttpClient { get; set; } = (_, _) => { };
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A delegate to configure the <see cref="HttpClientBuilder"/> for <see cref="HttpClient"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action<IHttpClientBuilder> HttpClientBuilder { get; set; } = _ => { };
|
|
|
|
|
|
2023-08-23 08:48:12 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// A list of <see cref="IHttpCorrelationIdSelector"/> types to register with the service collection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ICollection<Type> HttpCorrelationIdSelectorTypes { get; } = new List<Type>
|
|
|
|
|
{
|
2023-09-17 20:35:13 +00:00
|
|
|
typeof(HeaderHttpCorrelationIdSelector),
|
2023-08-23 08:48:12 +00:00
|
|
|
typeof(QueryStringHttpCorrelationIdSelector)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A list of <see cref="IHttpWorkflowInstanceIdSelector"/> types to register with the service collection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ICollection<Type> HttpWorkflowInstanceIdSelectorTypes { get; } = new List<Type>
|
|
|
|
|
{
|
2023-09-17 20:35:13 +00:00
|
|
|
typeof(HeaderHttpWorkflowInstanceIdSelector),
|
2023-08-23 08:48:12 +00:00
|
|
|
typeof(QueryStringHttpWorkflowInstanceIdSelector)
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-27 12:28:43 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override void Configure()
|
2022-05-26 10:47:31 +00:00
|
|
|
{
|
2023-01-16 18:42:45 +00:00
|
|
|
Module.UseWorkflowManagement(management =>
|
2022-11-27 12:28:43 +00:00
|
|
|
{
|
2023-01-16 18:42:45 +00:00
|
|
|
management.AddVariableTypes(new[]
|
|
|
|
|
{
|
|
|
|
|
typeof(RouteData),
|
|
|
|
|
typeof(HttpRequest),
|
2023-03-07 13:54:21 +00:00
|
|
|
typeof(HttpResponse),
|
2023-04-10 13:32:40 +00:00
|
|
|
typeof(HttpResponseMessage),
|
2023-12-08 20:53:43 +00:00
|
|
|
typeof(HttpHeaders),
|
2023-09-19 20:42:53 +00:00
|
|
|
typeof(IFormFile)
|
2023-01-16 18:42:45 +00:00
|
|
|
}, "HTTP");
|
2023-03-08 08:49:43 +00:00
|
|
|
|
2023-01-16 18:42:45 +00:00
|
|
|
management.AddActivitiesFrom<HttpFeature>();
|
|
|
|
|
});
|
2022-05-26 10:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-17 13:23:05 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override void ConfigureHostedServices()
|
|
|
|
|
{
|
|
|
|
|
ConfigureHostedService<UpdateRouteTableHostedService>();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-27 12:28:43 +00:00
|
|
|
/// <inheritdoc />
|
2022-05-26 10:47:31 +00:00
|
|
|
public override void Apply()
|
|
|
|
|
{
|
2022-11-19 21:30:43 +00:00
|
|
|
var configureOptions = ConfigureHttpOptions ?? (options =>
|
|
|
|
|
{
|
|
|
|
|
options.BasePath = "/workflows";
|
|
|
|
|
options.BaseUrl = new Uri("http://localhost");
|
|
|
|
|
});
|
2023-01-16 18:42:45 +00:00
|
|
|
|
2023-09-17 20:35:13 +00:00
|
|
|
var configureFileCacheOptions = ConfigureHttpFileCacheOptions ?? (options => { options.TimeToLive = TimeSpan.FromDays(7); });
|
|
|
|
|
|
2022-11-19 21:30:43 +00:00
|
|
|
Services.Configure(configureOptions);
|
2023-09-17 20:35:13 +00:00
|
|
|
Services.Configure(configureFileCacheOptions);
|
2022-05-26 10:47:31 +00:00
|
|
|
|
2023-03-07 12:45:58 +00:00
|
|
|
var httpClientBuilder = Services.AddHttpClient<SendHttpRequestBase>(HttpClient);
|
2023-01-16 18:42:45 +00:00
|
|
|
HttpClientBuilder(httpClientBuilder);
|
|
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
Services
|
|
|
|
|
.AddSingleton<IRouteMatcher, RouteMatcher>()
|
|
|
|
|
.AddSingleton<IRouteTable, RouteTable>()
|
2022-11-19 21:30:43 +00:00
|
|
|
.AddSingleton<IAbsoluteUrlProvider, DefaultAbsoluteUrlProvider>()
|
2023-01-24 20:03:50 +00:00
|
|
|
.AddSingleton<IHttpBookmarkProcessor, HttpBookmarkProcessor>()
|
2023-05-24 12:21:19 +00:00
|
|
|
.AddSingleton<IRouteTableUpdater, DefaultRouteTableUpdater>()
|
2023-09-16 09:43:34 +00:00
|
|
|
.AddSingleton(ContentTypeProvider)
|
2022-10-25 13:52:55 +00:00
|
|
|
.AddHttpContextAccessor()
|
2023-11-14 19:44:42 +00:00
|
|
|
|
|
|
|
|
// Handlers.
|
|
|
|
|
.AddRequestHandler<ValidateWorkflowRequestHandler, ValidateWorkflowRequest, ValidateWorkflowResponse>()
|
|
|
|
|
.AddNotificationHandler<UpdateRouteTable>()
|
2022-10-25 13:52:55 +00:00
|
|
|
|
2023-01-24 21:39:31 +00:00
|
|
|
// Content parsers.
|
2023-01-16 18:42:45 +00:00
|
|
|
.AddSingleton<IHttpContentParser, StringHttpContentParser>()
|
|
|
|
|
.AddSingleton<IHttpContentParser, JsonHttpContentParser>()
|
|
|
|
|
.AddSingleton<IHttpContentParser, XmlHttpContentParser>()
|
2023-12-31 09:11:47 +00:00
|
|
|
.AddSingleton<IHttpContentParser, FormHttpContentParser>()
|
2023-01-16 18:42:45 +00:00
|
|
|
|
2023-01-24 21:39:31 +00:00
|
|
|
// HTTP content factories.
|
2023-01-24 20:48:05 +00:00
|
|
|
.AddSingleton<IHttpContentFactory, TextContentFactory>()
|
|
|
|
|
.AddSingleton<IHttpContentFactory, JsonContentFactory>()
|
2023-01-24 21:39:31 +00:00
|
|
|
.AddSingleton<IHttpContentFactory, XmlContentFactory>()
|
2023-01-24 20:48:05 +00:00
|
|
|
.AddSingleton<IHttpContentFactory, FormUrlEncodedHttpContentFactory>()
|
2023-03-02 09:27:11 +00:00
|
|
|
|
2023-02-15 11:09:45 +00:00
|
|
|
// Activity property options providers.
|
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
|
|
|
.AddSingleton<IPropertyUIHandler, HttpContentTypeOptionsProvider>()
|
2023-05-11 20:58:59 +00:00
|
|
|
|
2023-03-11 21:14:39 +00:00
|
|
|
// Port resolvers.
|
2023-10-15 09:31:24 +00:00
|
|
|
.AddSingleton<IActivityResolver, SendHttpRequestActivityResolver>()
|
2023-03-02 09:27:11 +00:00
|
|
|
|
2023-09-16 09:06:56 +00:00
|
|
|
// HTTP endpoint handlers.
|
2023-05-01 10:06:51 +00:00
|
|
|
.AddSingleton<AuthenticationBasedHttpEndpointAuthorizationHandler>()
|
|
|
|
|
.AddSingleton<AllowAnonymousHttpEndpointAuthorizationHandler>()
|
2023-09-19 20:42:53 +00:00
|
|
|
.AddSingleton<DefaultHttpEndpointFaultHandler>()
|
2023-03-02 09:27:11 +00:00
|
|
|
.AddSingleton(HttpEndpointWorkflowFaultHandler)
|
2023-03-08 08:49:43 +00:00
|
|
|
.AddSingleton(HttpEndpointAuthorizationHandler)
|
2023-09-17 20:35:13 +00:00
|
|
|
|
|
|
|
|
// Downloadable content handlers.
|
2023-09-16 09:06:56 +00:00
|
|
|
.AddSingleton<IDownloadableManager, DefaultDownloadableManager>()
|
2023-09-17 20:35:13 +00:00
|
|
|
.AddSingleton<IDownloadableContentHandler, MultiDownloadableContentHandler>()
|
2023-09-19 20:42:53 +00:00
|
|
|
.AddSingleton<IDownloadableContentHandler, BinaryDownloadableContentHandler>()
|
2023-09-17 20:35:13 +00:00
|
|
|
.AddSingleton<IDownloadableContentHandler, StreamDownloadableContentHandler>()
|
2023-09-19 20:42:53 +00:00
|
|
|
.AddSingleton<IDownloadableContentHandler, FormFileDownloadableContentHandler>()
|
|
|
|
|
.AddSingleton<IDownloadableContentHandler, DownloadableDownloadableContentHandler>()
|
2023-09-17 20:35:13 +00:00
|
|
|
.AddSingleton<IDownloadableContentHandler, UrlDownloadableContentHandler>()
|
|
|
|
|
|
|
|
|
|
// File caches.
|
|
|
|
|
.AddSingleton(FileCache)
|
|
|
|
|
.AddSingleton<ZipManager>()
|
2023-05-11 20:58:59 +00:00
|
|
|
|
|
|
|
|
// AuthenticationBasedHttpEndpointAuthorizationHandler requires Authorization services.
|
|
|
|
|
// We could consider creating a separate module for installing authorization services.
|
|
|
|
|
.AddAuthorization();
|
2023-09-16 09:06:56 +00:00
|
|
|
|
|
|
|
|
// HTTP clients.
|
|
|
|
|
Services.AddHttpClient<IFileDownloader, HttpClientFileDownloader>();
|
2023-09-17 20:35:13 +00:00
|
|
|
|
2023-08-23 08:48:12 +00:00
|
|
|
// Add selectors.
|
2023-09-17 20:35:13 +00:00
|
|
|
foreach (var httpCorrelationIdSelectorType in HttpCorrelationIdSelectorTypes)
|
2023-08-23 08:48:12 +00:00
|
|
|
Services.AddSingleton(typeof(IHttpCorrelationIdSelector), httpCorrelationIdSelectorType);
|
2023-09-17 20:35:13 +00:00
|
|
|
|
2023-08-23 08:48:12 +00:00
|
|
|
foreach (var httpWorkflowInstanceIdSelectorType in HttpWorkflowInstanceIdSelectorTypes)
|
|
|
|
|
Services.AddSingleton(typeof(IHttpWorkflowInstanceIdSelector), httpWorkflowInstanceIdSelectorType);
|
2023-09-19 20:42:53 +00:00
|
|
|
|
|
|
|
|
Services.Configure<ExpressionOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.AddTypeAlias<IFormFile>("FormFile");
|
|
|
|
|
options.AddTypeAlias<IFormFile[]>("FormFile[]");
|
|
|
|
|
});
|
2022-05-26 10:47:31 +00:00
|
|
|
}
|
|
|
|
|
}
|