using System.Runtime.CompilerServices;
using System.Text.Json;
using Elsa.Expressions.Models;
using Elsa.Extensions;
using Elsa.Http.Bookmarks;
using Elsa.Http.UIHints;
using Elsa.Workflows;
using Elsa.Workflows.Attributes;
using Elsa.Workflows.UIHints;
using Elsa.Workflows.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Patterns;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.Http;
///
/// Wait for an inbound HTTP request that matches the specified path and methods.
///
[Activity("Elsa", "HTTP", "Wait for an inbound HTTP request that matches the specified path and methods.", DisplayName = "HTTP Endpoint")]
[Output(IsSerializable = false)]
public class HttpEndpoint : Trigger
{
internal const string HttpContextInputKey = "HttpContext";
internal const string PathInputKey = "Path";
///
public HttpEndpoint([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
{
}
///
/// The path to associate with the workflow.
///
[Input(
Description = "The path to associate with the workflow.",
UIHint = InputUIHints.SingleLine,
UIHandler = typeof(HttpEndpointPathUIHandler)
)]
public Input Path { get; set; } = null!;
///
/// The HTTP methods to accept.
///
[Input(
Description = "The HTTP methods to accept.",
Options = new[] { "GET", "POST", "PUT", "HEAD", "DELETE" },
UIHint = InputUIHints.CheckList)]
public Input> SupportedMethods { get; set; } = new(ObjectLiteral.From(new[] { HttpMethods.Get }));
///
/// Allow authenticated requests only.
///
[Input(Description = "Allow authenticated requests only.", Category = "Security")]
public Input Authorize { get; set; } = new(false);
///
/// Provide a policy to evaluate. If the policy fails, the request is forbidden.
///
[Input(Description = "Provide a policy to evaluate. If the policy fails, the request is forbidden.", Category = "Security")]
public Input Policy { get; set; } = new(default(string?));
///
/// The maximum time allowed to process the request.
///
[Input(Description = "The maximum time allowed to process the request.", Category = "Upload")]
public Input RequestTimeout { get; set; } = null!;
///
/// The maximum request size allowed in bytes.
///
[Input(Description = "The maximum request size allowed in bytes.", Category = "Upload")]
public Input RequestSizeLimit { get; set; } = null!;
///
/// The maximum request size allowed in bytes.
///
[Input(Description = "The maximum file size allowed in bytes for an individual file.", Category = "Upload")]
public Input FileSizeLimit { get; set; } = null!;
///
/// The allowed file extensions,
///
[Input(Description = "Only file extensions in this list are allowed. Leave empty to allow all extensions", Category = "Upload", UIHint = InputUIHints.MultiText)]
public Input> AllowedFileExtensions { get; set; } = null!;
///
/// The allowed file extensions,
///
[Input(Description = "File extensions in this list are forbidden. Leave empty to not block any extension.", Category = "Upload", UIHint = InputUIHints.MultiText)]
public Input> BlockedFileExtensions { get; set; } = null!;
///
/// The allowed file extensions,
///
[Input(Description = "Only MIME types in this list are allowed. Leave empty to allow all types", Category = "Upload", UIHint = InputUIHints.MultiText)]
public Input> AllowedMimeTypes { get; set; } = null!;
///
/// A value indicating whether to expose the "Request too large" outcome.
///
[Input(Description = "A value indicating whether to expose the \"Request too large\" outcome.", Category = "Outcomes")]
public bool ExposeRequestTooLargeOutcome { get; set; }
///
/// A value indicating whether to expose the "File too large" outcome.
///
[Input(Description = "A value indicating whether to expose the \"File too large\" outcome.", Category = "Outcomes")]
public bool ExposeFileTooLargeOutcome { get; set; }
///
/// A value indicating whether to expose the "Invalid file extension" outcome.
///
[Input(Description = "A value indicating whether to expose the \"Invalid file extension\" outcome.", Category = "Outcomes")]
public bool ExposeInvalidFileExtensionOutcome { get; set; }
///
/// A value indicating whether to expose the "Invalid file MIME type" outcome.
///
[Input(Description = "A value indicating whether to expose the \"Invalid file MIME type\" outcome.", Category = "Outcomes")]
public bool ExposeInvalidFileMimeTypeOutcome { get; set; }
///
/// The parsed request content, if any.
///
[Output(Description = "The parsed request content, if any.")]
public Output