2022-01-04 08:42:12 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
using Elsa.Attributes;
|
|
|
|
|
|
using Elsa.Management.Models;
|
|
|
|
|
|
using Elsa.Models;
|
2022-02-22 11:51:59 +00:00
|
|
|
|
using Elsa.Modules.Http.Models;
|
2022-01-04 08:42:12 +00:00
|
|
|
|
|
2022-02-01 19:45:11 +00:00
|
|
|
|
namespace Elsa.Modules.Http;
|
2022-01-04 08:42:12 +00:00
|
|
|
|
|
2022-03-04 20:42:27 +00:00
|
|
|
|
public class HttpTrigger : Trigger
|
2022-01-04 08:42:12 +00:00
|
|
|
|
{
|
|
|
|
|
|
[Input] public Input<string> Path { get; set; } = default!;
|
|
|
|
|
|
|
|
|
|
|
|
[Input(
|
|
|
|
|
|
Options = new[] { "GET", "POST", "PUT" },
|
|
|
|
|
|
UIHint = InputUIHints.CheckList
|
|
|
|
|
|
)]
|
|
|
|
|
|
public Input<ICollection<string>> SupportedMethods { get; set; } = new(new[] { HttpMethod.Get.Method });
|
|
|
|
|
|
|
|
|
|
|
|
[Output] public Output<HttpRequestModel>? Result { get; set; }
|
|
|
|
|
|
|
2022-03-04 20:42:27 +00:00
|
|
|
|
protected override IEnumerable<object> GetTriggerPayloads(TriggerIndexingContext context) => GetHashInputs(context.ExpressionExecutionContext);
|
2022-01-13 21:38:01 +00:00
|
|
|
|
protected override void Execute(ActivityExecutionContext context) => context.SetBookmarks(GetHashInputs(context.ExpressionExecutionContext));
|
2022-01-04 08:42:12 +00:00
|
|
|
|
|
2022-01-13 21:38:01 +00:00
|
|
|
|
private IEnumerable<object> GetHashInputs(ExpressionExecutionContext context)
|
2022-01-04 08:42:12 +00:00
|
|
|
|
{
|
2022-01-13 21:38:01 +00:00
|
|
|
|
// Generate a bookmark hash for path and selected methods.
|
|
|
|
|
|
var path = context.Get(Path);
|
|
|
|
|
|
var methods = context.Get(SupportedMethods);
|
2022-02-22 11:51:59 +00:00
|
|
|
|
return methods!.Select(x => new HttpTriggerPayload(path!, x.ToLowerInvariant())).Cast<object>().ToArray();
|
2022-01-04 08:42:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|