Some refactorings
This commit is contained in:
parent
1c2b92deb9
commit
a459a05517
|
|
@ -18,8 +18,4 @@
|
|||
<PackageReference Include="YamlDotNet.NetStandard" Version="4.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Serialization\Converters" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System.Threading.Tasks;
|
|||
using Flowsharp.Models;
|
||||
using Flowsharp.Results;
|
||||
|
||||
namespace Flowsharp.Services
|
||||
namespace Flowsharp.Handlers
|
||||
{
|
||||
public abstract class ActivityHandler<T> : IActivityHandler where T : IActivity
|
||||
{
|
||||
|
|
@ -23,7 +23,7 @@ namespace Flowsharp.Services
|
|||
protected virtual ActivityExecutionResult OnResume(T activity, WorkflowExecutionContext workflowContext) => Noop();
|
||||
|
||||
protected HaltResult Halt() => new HaltResult();
|
||||
protected ActivateEndpointResult ActivateEndpoint(string name = null) => new ActivateEndpointResult(name);
|
||||
protected TriggerEndpointResult TriggerEndpoint(string name = null) => new TriggerEndpointResult(name);
|
||||
protected ScheduleActivityResult ScheduleActivity(IActivity activity) => new ScheduleActivityResult(activity);
|
||||
protected ReturnValueResult SetReturnValue(object value) => new ReturnValueResult(value);
|
||||
protected FinishWorkflowResult Finish() => new FinishWorkflowResult();
|
||||
|
|
@ -4,7 +4,7 @@ using System.Threading.Tasks;
|
|||
using Flowsharp.Models;
|
||||
using Flowsharp.Results;
|
||||
|
||||
namespace Flowsharp.Services
|
||||
namespace Flowsharp.Handlers
|
||||
{
|
||||
public interface IActivityHandler
|
||||
{
|
||||
|
|
@ -20,7 +20,7 @@ namespace Flowsharp.Handlers
|
|||
protected override async Task<ActivityExecutionResult> OnExecuteAsync(IfElse activity, WorkflowExecutionContext workflowContext, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await expressionEvaluator.EvaluateAsync(activity.ConditionExpression, workflowContext, cancellationToken);
|
||||
return ActivateEndpoint(result ? "True" : "False");
|
||||
return TriggerEndpoint(result ? "True" : "False");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ namespace Flowsharp.Handlers
|
|||
{
|
||||
var value = await expressionEvaluator.EvaluateAsync(activity.ValueExpression, workflowContext, cancellationToken);
|
||||
workflowContext.CurrentScope.SetVariable(activity.VariableName, value);
|
||||
return ActivateEndpoint();
|
||||
return TriggerEndpoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,9 +6,9 @@ namespace Flowsharp.Results
|
|||
/// <summary>
|
||||
/// A result that carries information about the next activity to execute.
|
||||
/// </summary>
|
||||
public class ActivateEndpointResult : ActivityExecutionResult
|
||||
public class TriggerEndpointResult : ActivityExecutionResult
|
||||
{
|
||||
public ActivateEndpointResult(string endpointName = null)
|
||||
public TriggerEndpointResult(string endpointName = null)
|
||||
{
|
||||
EndpointName = endpointName;
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Flowsharp.Services
|
||||
namespace Flowsharp.Serialization.Formatters
|
||||
{
|
||||
public interface ITokenFormatter
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using Flowsharp.Models;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Flowsharp.Services
|
||||
namespace Flowsharp.Serialization
|
||||
{
|
||||
public interface IWorkflowSerializer
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using Flowsharp.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Flowsharp.Services
|
||||
namespace Flowsharp.Serialization.Tokenizers
|
||||
{
|
||||
public interface ITokenizer
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using Flowsharp.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Flowsharp.Services
|
||||
namespace Flowsharp.Serialization.Tokenizers
|
||||
{
|
||||
public interface ITokenizerInvoker
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using Flowsharp.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Flowsharp.Services
|
||||
namespace Flowsharp.Serialization.Tokenizers
|
||||
{
|
||||
public abstract class Tokenizer<T> : ITokenizer
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Flowsharp.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Flowsharp.Services
|
||||
namespace Flowsharp.Serialization.Tokenizers
|
||||
{
|
||||
public class TokenizerInvoker : ITokenizerInvoker
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Flowsharp.Handlers;
|
||||
using Flowsharp.Models;
|
||||
using Flowsharp.Services;
|
||||
using Newtonsoft.Json;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Flowsharp.Models;
|
||||
using Flowsharp.Serialization.Formatters;
|
||||
using Flowsharp.Serialization.Tokenizers;
|
||||
using Flowsharp.Services;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flowsharp.Handlers;
|
||||
using Flowsharp.Models;
|
||||
using Flowsharp.Results;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@ namespace Flowsharp.Services
|
|||
{
|
||||
IActivityInvoker ActivityInvoker { get; }
|
||||
Task<WorkflowExecutionContext> InvokeAsync(Workflow workflow, IActivity startActivity = default, CancellationToken cancellationToken = default);
|
||||
Task<WorkflowExecutionContext> ResumeAsync(Workflow workflow, IActivity startActivity = default, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,12 @@ namespace Flowsharp.Services
|
|||
return workflowExecutionContext;
|
||||
}
|
||||
|
||||
public Task<WorkflowExecutionContext> ResumeAsync(Workflow workflow, IActivity startActivity = default, CancellationToken cancellationToken = default)
|
||||
{
|
||||
workflow.Status = WorkflowStatus.Resuming;
|
||||
return InvokeAsync(workflow, startActivity, cancellationToken);
|
||||
}
|
||||
|
||||
private async Task<ActivityExecutionResult> ExecuteActivityAsync(WorkflowExecutionContext workflowContext, IActivity activity, bool isResuming, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flowsharp.Handlers;
|
||||
using Flowsharp.Models;
|
||||
using Flowsharp.Results;
|
||||
using Flowsharp.Samples.Console.Activities;
|
||||
|
|
@ -28,7 +29,7 @@ namespace Flowsharp.Samples.Console.Handlers
|
|||
|
||||
var value = await input.ReadLineAsync();
|
||||
workflowContext.SetLastResult(value);
|
||||
return ActivateEndpoint();
|
||||
return TriggerEndpoint();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +37,7 @@ namespace Flowsharp.Samples.Console.Handlers
|
|||
{
|
||||
var receivedInput = workflowContext.Workflow.Arguments[activity.ArgumentName];
|
||||
workflowContext.SetLastResult(receivedInput);
|
||||
return ActivateEndpoint();
|
||||
return TriggerEndpoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flowsharp.Expressions;
|
||||
using Flowsharp.Handlers;
|
||||
using Flowsharp.Models;
|
||||
using Flowsharp.Results;
|
||||
using Flowsharp.Samples.Console.Activities;
|
||||
|
|
@ -31,7 +32,7 @@ namespace Flowsharp.Samples.Console.Handlers
|
|||
{
|
||||
var text = await evaluator.EvaluateAsync(activity.TextExpression, workflowContext, cancellationToken);
|
||||
await output.WriteLineAsync(text);
|
||||
return ActivateEndpoint();
|
||||
return TriggerEndpoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flowsharp.Samples.Console.Workflows;
|
||||
using Flowsharp.Serialization;
|
||||
using Flowsharp.Services;
|
||||
|
||||
namespace Flowsharp.Samples.Console.Programs
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using Flowsharp.Models;
|
||||
using Flowsharp.Samples.Console.Workflows;
|
||||
using Flowsharp.Serialization;
|
||||
using Flowsharp.Services;
|
||||
|
||||
namespace Flowsharp.Samples.Console.Programs
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ using System.Linq;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flowsharp.Models;
|
||||
using Flowsharp.Samples.Console.Activities;
|
||||
using Flowsharp.Serialization;
|
||||
using Flowsharp.Services;
|
||||
|
||||
namespace Flowsharp.Samples.Console.Programs
|
||||
|
|
@ -29,20 +31,19 @@ namespace Flowsharp.Samples.Console.Programs
|
|||
|
||||
while (workflowContext.Workflow.Status == WorkflowStatus.Halted)
|
||||
{
|
||||
workflowContext = await ReadAndResumeAsync(workflowContext.Workflow, "x", cancellationToken);
|
||||
workflowContext = await ReadAndResumeAsync(workflowContext.Workflow, "y", cancellationToken);
|
||||
workflowContext = await ReadAndResumeAsync(workflowContext.Workflow, "tryAgain", cancellationToken);
|
||||
workflowContext = await ReadAndResumeAsync(workflowContext.Workflow, cancellationToken);
|
||||
workflowContext = await ReadAndResumeAsync(workflowContext.Workflow, cancellationToken);
|
||||
workflowContext = await ReadAndResumeAsync(workflowContext.Workflow, cancellationToken);
|
||||
}
|
||||
|
||||
System.Console.WriteLine(data);
|
||||
}
|
||||
|
||||
private async Task<WorkflowExecutionContext> ReadAndResumeAsync(Workflow workflow, string argumentName, CancellationToken cancellationToken)
|
||||
private async Task<WorkflowExecutionContext> ReadAndResumeAsync(Workflow workflow, CancellationToken cancellationToken)
|
||||
{
|
||||
var haltedActivity = workflow.HaltedActivities.Single();
|
||||
workflow.Arguments[argumentName] = System.Console.ReadLine();
|
||||
workflow.Status = WorkflowStatus.Resuming;
|
||||
return await workflowInvoker.InvokeAsync(workflow, haltedActivity, cancellationToken);
|
||||
var haltedActivity = (ReadLine)workflow.HaltedActivities.Single();
|
||||
workflow.Arguments[haltedActivity.ArgumentName] = System.Console.ReadLine();
|
||||
return await workflowInvoker.ResumeAsync(workflow, haltedActivity, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue