Update samples

This commit is contained in:
Sipke Schoorstra 2020-10-17 15:45:16 +02:00
parent 3d0d372de3
commit 39455f339e
7 changed files with 10 additions and 29 deletions

4
.gitignore vendored
View file

@ -50,4 +50,6 @@ node_modules/
#github
.github/
App_Data/
#volatile
App_Data/
*.db

View file

@ -12,17 +12,15 @@ namespace Elsa.Samples.CustomActivities
public void Build(IWorkflowBuilder builder)
{
builder
.ReceiveHttpRequest("/hello")
.ReceiveHttpRequest("/test")
.Then<ReadQueryString>()
.WriteHttpResponse(_ => HttpStatusCode.OK, GenerateSomeHtml, _ => "text/html");
}
private string GenerateSomeHtml(ActivityExecutionContext context)
{
var query = (IQueryCollection)context
.Input; // the output of the previous activity will be available as input to this one.
var items = query.Select(x => $"<li>{x.Key}: {x.Value}</li>");
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>");
return $"<ul>{string.Join("\n", items)}</ul>";
}

View file

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Http;
namespace Elsa.Samples.CustomActivities
{
/// <summary>
/// A basic activity that simply reads the query string and returns them as an output value for consumption by other activities.
/// A basic activity that reads and returns the query string as an output value.
/// </summary>
public class ReadQueryString : Activity
{

View file

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using YesSql.Provider.Sqlite;
namespace Elsa.Samples.CustomActivities
{
@ -8,7 +9,7 @@ namespace Elsa.Samples.CustomActivities
public void ConfigureServices(IServiceCollection services)
{
services
.AddElsa()
.AddElsa(option => option.UsePersistence(db => db.UseSqLite("Data Source=elsa.db;Cache=Shared")))
.AddHttpActivities()
.AddActivity<ReadQueryString>()
.AddWorkflow<EchoQueryStringWorkflow>();

View file

@ -1 +1 @@
GET http://localhost:5000/hello?foo=bar&bar=baz
GET http://localhost:5000/test?foo=bar&bar=baz

View file

@ -19,27 +19,7 @@ namespace Elsa.Samples.Serialization
.AddConsoleActivities()
.BuildServiceProvider();
// Build a new workflow.
var workflow = services.GetService<IWorkflowBuilder>()
//.Then<WriteLine>(writeLine => writeLine.)
.WriteLine("Hello World!")
.Build();
// Get a reference to the workflow serializer.
var serializer = services.GetRequiredService<IWorkflowSerializer>();
// Serialize the workflow.
var json = serializer.Serialize(workflow, SerializationFormats.Json);
Console.WriteLine(json);
// Deserialize the workflow.
var deserializedWorkflow = serializer.Deserialize<WorkflowBlueprint>(json, SerializationFormats.Json);
// Get the workflow host.
var workflowHost = services.GetService<IWorkflowHost>();
// Execute the workflow.
await workflowHost.RunWorkflowAsync(deserializedWorkflow);
}
}