elsa-core/src/samples/Flowsharp.Samples.Console/Handlers/ReadLineHandler.cs
Sipke Schoorstra 5998cae2dd WIP
2018-10-20 23:24:41 +02:00

42 lines
1.2 KiB
C#

using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Flowsharp.Handlers;
using Flowsharp.Models;
using Flowsharp.Results;
using Flowsharp.Samples.Console.Activities;
namespace Flowsharp.Samples.Console.Handlers
{
public class ReadLineHandler : ActivityHandler<ReadLine>
{
private readonly TextReader input;
public ReadLineHandler()
{
}
public ReadLineHandler(TextReader input)
{
this.input = input;
}
protected override async Task<ActivityExecutionResult> OnExecuteAsync(ReadLine activity, WorkflowExecutionContext workflowContext, CancellationToken cancellationToken)
{
if (input == null)
return Halt();
var value = await input.ReadLineAsync();
workflowContext.SetLastResult(value);
return TriggerEndpoint();
}
protected override ActivityExecutionResult OnResume(ReadLine activity, WorkflowExecutionContext workflowContext)
{
var receivedInput = workflowContext.Workflow.Arguments[activity.ArgumentName];
workflowContext.SetLastResult(receivedInput);
return TriggerEndpoint();
}
}
}