2022-11-19 21:30:43 +00:00
|
|
|
|
using Elsa.Extensions;
|
2023-10-07 10:47:36 +00:00
|
|
|
|
using Elsa.Samples.ConsoleApp.Composition.Activities;
|
|
|
|
|
|
using Elsa.Samples.ConsoleApp.Composition.Models;
|
2022-11-19 21:30:43 +00:00
|
|
|
|
using Elsa.Workflows.Core.Activities;
|
2023-03-03 21:47:23 +00:00
|
|
|
|
using Elsa.Workflows.Core.Contracts;
|
2023-07-09 11:12:13 +00:00
|
|
|
|
using Elsa.Workflows.Core.Memory;
|
2022-11-19 21:30:43 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
|
|
// Setup service container.
|
|
|
|
|
|
var services = new ServiceCollection();
|
|
|
|
|
|
|
|
|
|
|
|
// Add Elsa services.
|
|
|
|
|
|
services.AddElsa();
|
|
|
|
|
|
|
|
|
|
|
|
// Build service container.
|
|
|
|
|
|
var serviceProvider = services.BuildServiceProvider();
|
|
|
|
|
|
|
|
|
|
|
|
// Declare a workflow variable for use in the workflow.
|
2022-11-20 19:37:56 +00:00
|
|
|
|
var personVariable = new Variable<Person>();
|
2022-11-19 21:30:43 +00:00
|
|
|
|
|
|
|
|
|
|
// Declare a workflow.
|
|
|
|
|
|
var workflow = new Sequence
|
|
|
|
|
|
{
|
2022-11-20 19:37:56 +00:00
|
|
|
|
Variables = { personVariable },
|
2022-11-19 21:30:43 +00:00
|
|
|
|
Activities =
|
|
|
|
|
|
{
|
2022-11-24 20:12:07 +00:00
|
|
|
|
new AskDetails
|
2022-11-19 21:30:43 +00:00
|
|
|
|
{
|
2022-11-27 12:28:53 +00:00
|
|
|
|
NamePrompt = new ("What's your name?"),
|
|
|
|
|
|
AgePrompt = new ("What's your age?"),
|
|
|
|
|
|
Result = new(personVariable)
|
2022-11-19 21:30:43 +00:00
|
|
|
|
},
|
2022-11-20 19:37:56 +00:00
|
|
|
|
new WriteLine(context =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var person = personVariable.Get(context)!;
|
|
|
|
|
|
return $"Your name is {person.Name} and you are {person.Age} years old.";
|
|
|
|
|
|
})
|
2022-11-19 21:30:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Resolve a workflow runner to run the workflow.
|
|
|
|
|
|
var workflowRunner = serviceProvider.GetRequiredService<IWorkflowRunner>();
|
|
|
|
|
|
|
|
|
|
|
|
// Run the workflow.
|
|
|
|
|
|
await workflowRunner.RunAsync(workflow);
|