Incremental work on YAML support
This commit is contained in:
parent
8c73693340
commit
ac1d528b72
|
|
@ -15,6 +15,7 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="YamlDotNet.NetStandard" Version="4.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
using System.Dynamic;
|
||||
using Flowsharp.Services;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Flowsharp.Serialization.Formatters
|
||||
{
|
||||
public class YamlTokenFormatter : ITokenFormatter
|
||||
{
|
||||
public YamlTokenFormatter()
|
||||
{
|
||||
}
|
||||
|
||||
public string ToString(JToken token)
|
||||
{
|
||||
var expConverter = new ExpandoObjectConverter();
|
||||
var jsonString = token.ToString(Formatting.None);
|
||||
var expandoObject = JsonConvert.DeserializeObject<ExpandoObject>(jsonString, expConverter);
|
||||
var serializer = new SerializerBuilder().Build();
|
||||
var yaml = serializer.Serialize(expandoObject);
|
||||
|
||||
return yaml;
|
||||
}
|
||||
|
||||
public JToken FromString(string data) => JToken.Parse(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,8 @@
|
|||
<ItemGroup>
|
||||
<None Remove="SampleWorkflow.json" />
|
||||
<EmbeddedResource Include="SampleWorkflow.json" />
|
||||
<None Remove="SampleWorkflow.yaml" />
|
||||
<EmbeddedResource Include="SampleWorkflow.yaml" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ namespace Flowsharp.Samples.Console
|
|||
.AddSingleton<IWorkflowInvoker, WorkflowInvoker>()
|
||||
.AddSingleton<IActivityInvoker, ActivityInvoker>()
|
||||
.AddSingleton<IWorkflowSerializer, WorkflowSerializer>()
|
||||
.AddSingleton<ITokenFormatter, JsonTokenFormatter>()
|
||||
//.AddSingleton<ITokenFormatter, JsonTokenFormatter>()
|
||||
.AddSingleton<ITokenFormatter, YamlTokenFormatter>()
|
||||
.AddSingleton<IWorkflowTokenizer, WorkflowTokenizer>()
|
||||
.AddSingleton<ITokenizerInvoker, TokenizerInvoker>()
|
||||
.AddSingleton<ITokenizer, DefaultTokenizer>()
|
||||
|
|
@ -43,7 +44,8 @@ namespace Flowsharp.Samples.Console
|
|||
.AddSingleton<FileBasedWorkflowProgramLongRunning>();
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var program = serviceProvider.GetRequiredService<FileBasedWorkflowProgramLongRunning>();
|
||||
var program = serviceProvider.GetRequiredService<AdditionWorkflowProgramLongRunning>();
|
||||
//var program = serviceProvider.GetRequiredService<FileBasedWorkflowProgramLongRunning>();
|
||||
|
||||
await program.RunAsync(CancellationToken.None);
|
||||
}
|
||||
|
|
|
|||
153
src/Flowsharp.Samples.Console/SampleWorkflow.yaml
Normal file
153
src/Flowsharp.Samples.Console/SampleWorkflow.yaml
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
status: Idle
|
||||
activities:
|
||||
- id: 1
|
||||
name: WriteLine
|
||||
textExpression:
|
||||
syntax: PlainText
|
||||
expression: Welcome to Addition Workflow - Long Running edition!
|
||||
- id: 2
|
||||
name: WriteLine
|
||||
textExpression:
|
||||
syntax: PlainText
|
||||
expression: Let's run a long-running program.
|
||||
- id: 3
|
||||
name: WriteLine
|
||||
textExpression:
|
||||
syntax: PlainText
|
||||
expression: 'Enter first value:'
|
||||
- id: 4
|
||||
name: WriteLine
|
||||
textExpression:
|
||||
syntax: PlainText
|
||||
expression: 'Enter second value:'
|
||||
- id: 5
|
||||
name: WriteLine
|
||||
textExpression:
|
||||
syntax: JavaScript
|
||||
expression: >-
|
||||
var x = workflow.getVariable('x');
|
||||
|
||||
var y = workflow.getVariable('y');
|
||||
|
||||
var sum = parseInt(x) + parseInt(y);
|
||||
|
||||
x + ' + ' + y + ' = ' + sum;
|
||||
- id: 6
|
||||
name: WriteLine
|
||||
textExpression:
|
||||
syntax: PlainText
|
||||
expression: Try again? (Y/N)
|
||||
- id: 7
|
||||
name: WriteLine
|
||||
textExpression:
|
||||
syntax: PlainText
|
||||
expression: Bye!
|
||||
- id: 8
|
||||
name: ReadLine
|
||||
argumentName: x
|
||||
- id: 9
|
||||
name: ReadLine
|
||||
argumentName: y
|
||||
- id: 10
|
||||
name: ReadLine
|
||||
argumentName: tryAgain
|
||||
- id: 11
|
||||
name: SetVariable
|
||||
variableName: x
|
||||
valueExpression:
|
||||
syntax: JavaScript
|
||||
expression: workflow.getLastResult()
|
||||
- id: 12
|
||||
name: SetVariable
|
||||
variableName: y
|
||||
valueExpression:
|
||||
syntax: JavaScript
|
||||
expression: workflow.getLastResult()
|
||||
- id: 13
|
||||
name: SetVariable
|
||||
variableName: tryAgain
|
||||
valueExpression:
|
||||
syntax: JavaScript
|
||||
expression: "'y' === workflow.getLastResult().toLowerCase()"
|
||||
- id: 14
|
||||
name: IfElse
|
||||
conditionExpression:
|
||||
syntax: JavaScript
|
||||
expression: workflow.getVariable('tryAgain')
|
||||
connections:
|
||||
- source:
|
||||
activityId: 1
|
||||
endpoint:
|
||||
target:
|
||||
activityId: 2
|
||||
- source:
|
||||
activityId: 2
|
||||
endpoint:
|
||||
target:
|
||||
activityId: 3
|
||||
- source:
|
||||
activityId: 3
|
||||
endpoint:
|
||||
target:
|
||||
activityId: 8
|
||||
- source:
|
||||
activityId: 8
|
||||
endpoint:
|
||||
target:
|
||||
activityId: 11
|
||||
- source:
|
||||
activityId: 11
|
||||
endpoint:
|
||||
target:
|
||||
activityId: 4
|
||||
- source:
|
||||
activityId: 4
|
||||
endpoint:
|
||||
target:
|
||||
activityId: 9
|
||||
- source:
|
||||
activityId: 9
|
||||
endpoint:
|
||||
target:
|
||||
activityId: 12
|
||||
- source:
|
||||
activityId: 12
|
||||
endpoint:
|
||||
target:
|
||||
activityId: 5
|
||||
- source:
|
||||
activityId: 5
|
||||
endpoint:
|
||||
target:
|
||||
activityId: 6
|
||||
- source:
|
||||
activityId: 6
|
||||
endpoint:
|
||||
target:
|
||||
activityId: 10
|
||||
- source:
|
||||
activityId: 10
|
||||
endpoint:
|
||||
target:
|
||||
activityId: 13
|
||||
- source:
|
||||
activityId: 13
|
||||
endpoint:
|
||||
target:
|
||||
activityId: 14
|
||||
- source:
|
||||
activityId: 14
|
||||
endpoint: True
|
||||
target:
|
||||
activityId: 3
|
||||
- source:
|
||||
activityId: 14
|
||||
endpoint: False
|
||||
target:
|
||||
activityId: 7
|
||||
haltedActivities: []
|
||||
scopes:
|
||||
- id: 1
|
||||
variables: []
|
||||
lastResult:
|
||||
currentScope: 1
|
||||
Loading…
Reference in a new issue