elsa-core/src/Flowsharp.Samples.Console/Handlers/ReadLineHandler.cs

42 lines
1.2 KiB
C#
Raw Normal View History

2018-10-15 12:15:36 +00:00
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Flowsharp.Models;
using Flowsharp.Results;
using Flowsharp.Samples.Console.Activities;
using Flowsharp.Services;
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 ActivateEndpoint();
}
protected override ActivityExecutionResult OnResume(ReadLine activity, WorkflowExecutionContext workflowContext)
{
var receivedInput = workflowContext.Workflow.Arguments[activity.ArgumentName];
workflowContext.SetLastResult(receivedInput);
return ActivateEndpoint();
}
}
}