elsa-core/src/samples/aspnet/Elsa.Samples.CustomActivities/EchoQueryStringWorkflow.cs

28 lines
910 B
C#
Raw Normal View History

2020-02-18 21:29:44 +00:00
using System.Linq;
using System.Net;
using Elsa.Activities.Http;
using Elsa.Builders;
using Elsa.Services.Models;
using Microsoft.AspNetCore.Http;
namespace Elsa.Samples.CustomActivities
{
public class EchoQueryStringWorkflow : IWorkflow
{
2020-10-21 17:55:21 +00:00
public void Build(IWorkflowBuilder workflow)
2020-02-18 21:29:44 +00:00
{
2020-10-21 17:55:21 +00:00
workflow
.HttpRequestReceived("/test")
2020-02-18 21:29:44 +00:00
.Then<ReadQueryString>()
2020-10-03 10:48:25 +00:00
.WriteHttpResponse(_ => HttpStatusCode.OK, GenerateSomeHtml, _ => "text/html");
2020-02-18 21:29:44 +00:00
}
private string GenerateSomeHtml(ActivityExecutionContext context)
{
2020-10-17 13:45:16 +00:00
var query = (IQueryCollection)context.Input; // the output of the ReadQueryString activity will be available as input to this one.
var items = query!.Select(x => $"<li>{x.Key}: {x.Value}</li>");
2020-10-03 10:48:25 +00:00
2020-02-18 21:29:44 +00:00
return $"<ul>{string.Join("\n", items)}</ul>";
}
}
}