2022-12-31 15:16:43 +00:00
|
|
|
using Elsa.Extensions;
|
2023-07-09 11:12:13 +00:00
|
|
|
using Elsa.Workflows.Core;
|
2022-11-19 21:30:43 +00:00
|
|
|
using Elsa.Workflows.Core.Activities;
|
2023-07-09 11:12:13 +00:00
|
|
|
using Elsa.Workflows.Core.Memory;
|
2022-11-19 21:30:43 +00:00
|
|
|
using Elsa.Workflows.Core.Models;
|
|
|
|
|
|
|
|
|
|
public class AskAge : Composite<int>
|
|
|
|
|
{
|
|
|
|
|
private readonly Variable<string> _age = new();
|
|
|
|
|
|
|
|
|
|
public Input<string> Prompt { get; set; } = new("Please tell me your age:");
|
|
|
|
|
|
|
|
|
|
public AskAge()
|
|
|
|
|
{
|
2023-05-16 09:41:41 +00:00
|
|
|
Variables = new List<Variable> { _age };
|
2022-11-19 21:30:43 +00:00
|
|
|
Root = new Sequence
|
|
|
|
|
{
|
|
|
|
|
Activities =
|
|
|
|
|
{
|
2022-11-20 19:37:56 +00:00
|
|
|
new WriteLine(context => Prompt.Get(context)),
|
2022-11-19 21:30:43 +00:00
|
|
|
new ReadLine(_age)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-25 23:11:10 +00:00
|
|
|
protected override void OnCompleted(ActivityCompletedContext context)
|
2022-11-19 21:30:43 +00:00
|
|
|
{
|
2023-08-25 23:11:10 +00:00
|
|
|
var age = _age.Get<int>(context.TargetContext);
|
|
|
|
|
context.TargetContext.Set(Result, age);
|
2022-11-19 21:30:43 +00:00
|
|
|
}
|
|
|
|
|
}
|