Skip to content

Commit a373b6f

Browse files
committed
wip
1 parent 371a323 commit a373b6f

File tree

20 files changed

+324
-34
lines changed

20 files changed

+324
-34
lines changed

ReleaseNotes/2.0.0.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,58 @@
11
# Workflow Core 2.0.0
22

33
* Targets .NET Standard 2.0
4-
* Object graphs on input properties
4+
The core library now targets .NET Standard 2.0, in order to leverage newer features.
5+
6+
* Support for YAML definitions
7+
Added support for YAML workflow definitions, which can be loaded as follows
8+
```c#
9+
using WorkflowCore.Services.DefinitionStorage;
10+
...
11+
DefinitionLoader.LoadDefinition(json, Deserializers.Yaml);
12+
```
13+
14+
Existing JSON definitions will be loaded as follows
15+
```c#
16+
using WorkflowCore.Services.DefinitionStorage;
17+
...
18+
DefinitionLoader.LoadDefinition(json, Deserializers.Json);
19+
```
20+
21+
* Object graphs and inline expressions on input properties
22+
You can now pass object graphs to step inputs as opposed to just scalar values
23+
```
24+
"inputs":
25+
{
26+
"Body": {
27+
"Value1": 1,
28+
"Value2": 2
29+
},
30+
"Headers": {
31+
"Content-Type": "application/json"
32+
}
33+
},
34+
```
35+
If you want to evaluate an expression for a given property of your object, simply prepend and `@` and pass an expression string
36+
```
37+
"inputs":
38+
{
39+
"Body": {
40+
"@Value1": "data.MyValue",
41+
"Value2": 2
42+
},
43+
"Headers": {
44+
"Content-Type": "application/json"
45+
}
46+
},
47+
```
48+
549
* Support for enum values on input properties
50+
If your step has an enum property, you can now just pass the string representation of the enum value and it will be automatically converted.
51+
652
* Environment variables available in input expressions
53+
You can now access environment variables from within input expressions.
54+
usage:
55+
```
56+
environment["VARIABLE_NAME"]
57+
```
758

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
using WorkflowCore.Models;
1+
using System;
2+
using WorkflowCore.Models;
3+
using WorkflowCore.Models.DefinitionStorage.v1;
24

35
namespace WorkflowCore.Interface
46
{
57
public interface IDefinitionLoader
68
{
7-
WorkflowDefinition LoadDefinition(string json);
9+
WorkflowDefinition LoadDefinition(string source, Func<string, DefinitionSourceV1> deserializer);
810
}
911
}

src/WorkflowCore/Services/DefinitionStorage/DefinitionLoader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public DefinitionLoader(IWorkflowRegistry registry)
2626
_registry = registry;
2727
}
2828

29-
public WorkflowDefinition LoadDefinition(string json)
29+
public WorkflowDefinition LoadDefinition(string source, Func<string, DefinitionSourceV1> deserializer)
3030
{
31-
var source = JsonConvert.DeserializeObject<DefinitionSourceV1>(json);
32-
var def = Convert(source);
31+
var sourceObj = deserializer(source);
32+
var def = Convert(sourceObj);
3333
_registry.RegisterWorkflow(def);
3434
return def;
3535
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
using SharpYaml.Serialization;
4+
using WorkflowCore.Models.DefinitionStorage.v1;
5+
6+
namespace WorkflowCore.Services.DefinitionStorage
7+
{
8+
public static class Deserializers
9+
{
10+
private static Serializer yamlSerializer = new Serializer();
11+
12+
public static Func<string, DefinitionSourceV1> Json = (source) => JsonConvert.DeserializeObject<DefinitionSourceV1>(source);
13+
14+
public static Func<string, DefinitionSourceV1> Yaml = (source) => yamlSerializer.DeserializeInto(source, new DefinitionSourceV1());
15+
}
16+
}

src/WorkflowCore/WorkflowCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" />
2828
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="2.2.0" />
2929
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
30+
<PackageReference Include="SharpYaml" Version="1.6.5" />
3031
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.7.12" />
3132
<PackageReference Include="System.Threading.Tasks.Parallel" Version="4.3.0" />
3233
<PackageReference Include="System.Threading.ThreadPool" Version="4.3.0" />

src/providers/WorkflowCore.LockProviders.SqlServer/WorkflowCore.LockProviders.SqlServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="System.Data.SqlClient" Version="4.3.1" />
12+
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

src/providers/WorkflowCore.Persistence.MongoDB/WorkflowCore.Persistence.MongoDB.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</ItemGroup>
2626

2727
<ItemGroup>
28-
<PackageReference Include="MongoDB.Driver" Version="2.7.2" />
28+
<PackageReference Include="MongoDB.Driver" Version="2.8.1" />
2929
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
3030
</ItemGroup>
3131

src/providers/WorkflowCore.QueueProviders.RabbitMQ/WorkflowCore.QueueProviders.RabbitMQ.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
<PackageLicenseUrl>https://github.com/danielgerlag/workflow-core/blob/master/LICENSE.md</PackageLicenseUrl>
1313
<RepositoryType>git</RepositoryType>
1414
<RepositoryUrl>https://github.com/danielgerlag/workflow-core.git</RepositoryUrl>
15-
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
16-
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.3' ">$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
1715
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
1816
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1917
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>

src/providers/WorkflowCore.QueueProviders.SqlServer/WorkflowCore.QueueProviders.SqlServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<ItemGroup>
2323
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.0" />
2424
<PackageReference Include="System.Data.Common" Version="4.3.0" />
25-
<PackageReference Include="System.Data.SqlClient" Version="4.3.1" />
25+
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

test/WorkflowCore.IntegrationTests/Scenarios/StoredScenario.cs renamed to test/WorkflowCore.IntegrationTests/Scenarios/StoredJsonScenario.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
namespace WorkflowCore.IntegrationTests.Scenarios
1212
{
13-
public class StoredScenario : JsonWorkflowTest
13+
public class StoredJsonScenario : JsonWorkflowTest
1414
{
15-
public StoredScenario()
15+
public StoredJsonScenario()
1616
{
1717
Setup();
1818
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using WorkflowCore.Interface;
5+
using WorkflowCore.Models;
6+
using Xunit;
7+
using FluentAssertions;
8+
using WorkflowCore.Testing;
9+
using WorkflowCore.TestAssets.DataTypes;
10+
11+
namespace WorkflowCore.IntegrationTests.Scenarios
12+
{
13+
public class StoredYamlScenario : YamlWorkflowTest
14+
{
15+
public StoredYamlScenario()
16+
{
17+
Setup();
18+
}
19+
20+
[Fact(DisplayName = "Execute workflow from stored YAML definition")]
21+
public void should_execute_yaml_workflow()
22+
{
23+
var workflowId = StartWorkflow(TestAssets.Utils.GetTestDefinitionYaml(), new CounterBoard() { Flag1 = true, Flag2 = true });
24+
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30));
25+
26+
var data = GetData<CounterBoard>(workflowId);
27+
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
28+
UnhandledStepErrors.Count.Should().Be(0);
29+
data.Counter1.Should().Be(1);
30+
data.Counter2.Should().Be(1);
31+
data.Counter3.Should().Be(1);
32+
data.Counter4.Should().Be(1);
33+
data.Counter5.Should().Be(0);
34+
data.Counter6.Should().Be(1);
35+
}
36+
}
37+
}

test/WorkflowCore.TestAssets/Properties/Resources.Designer.cs

Lines changed: 19 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/WorkflowCore.TestAssets/Properties/Resources.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120120
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
121-
<data name="stored_definition" type="System.Resources.ResXFileRef, System.Windows.Forms">
121+
<data name="stored_definition_json" type="System.Resources.ResXFileRef, System.Windows.Forms">
122122
<value>..\stored-definition.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
123123
</data>
124+
<data name="stored_definition_yaml" type="System.Resources.ResXFileRef, System.Windows.Forms">
125+
<value>..\stored-definition.yaml;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
126+
</data>
124127
</root>

test/WorkflowCore.TestAssets/Utils.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ public static T DeepCopy<T>(T obj)
2020

2121
public static string GetTestDefinitionJson()
2222
{
23-
//return Properties.Resources.ResourceManager.GetString("stored_definition");
2423
return File.ReadAllText("stored-definition.json");
2524
}
2625

26+
public static string GetTestDefinitionYaml()
27+
{
28+
return File.ReadAllText("stored-definition.yaml");
29+
}
30+
2731
public static string GetTestDefinitionDynamicJson()
2832
{
2933
return File.ReadAllText("stored-dynamic-definition.json");

test/WorkflowCore.TestAssets/WorkflowCore.TestAssets.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
<ItemGroup>
1313
<None Remove="stored-definition.json" />
14+
<None Remove="stored-definition.yaml" />
1415
<None Remove="stored-dynamic-definition.json" />
1516
</ItemGroup>
1617

1718
<ItemGroup>
19+
<EmbeddedResource Include="stored-definition.yaml">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</EmbeddedResource>
1822
<EmbeddedResource Include="stored-dynamic-definition.json">
1923
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2024
</EmbeddedResource>
@@ -28,7 +32,7 @@
2832
</ItemGroup>
2933

3034
<ItemGroup>
31-
<PackageReference Include="FluentAssertions" Version="4.19.0" />
35+
<PackageReference Include="FluentAssertions" Version="4.19.4" />
3236
<PackageReference Include="Moq" Version="4.7.99" />
3337
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
3438
<PackageReference Include="NUnit" Version="3.6.1" />
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Id: Test
2+
Version: 1
3+
DataType: WorkflowCore.TestAssets.DataTypes.CounterBoard, WorkflowCore.TestAssets
4+
Steps:
5+
- Id: Step1
6+
StepType: WorkflowCore.TestAssets.Steps.Counter, WorkflowCore.TestAssets
7+
ErrorBehavior: Retry
8+
Inputs:
9+
Value: data.Counter1
10+
Outputs:
11+
Counter1: step.Value
12+
NextStepId: Step2
13+
- Id: Step2
14+
StepType: WorkflowCore.TestAssets.Steps.Counter, WorkflowCore.TestAssets
15+
Inputs:
16+
Value: data.Counter2
17+
Outputs:
18+
Counter2: step.Value
19+
NextStepId: Step3
20+
- Id: Step3
21+
StepType: WorkflowCore.Primitives.If, WorkflowCore
22+
NextStepId: Step4
23+
Inputs:
24+
Condition: data.Flag1
25+
Do:
26+
- - Id: Step3.1.1
27+
StepType: WorkflowCore.TestAssets.Steps.Counter, WorkflowCore.TestAssets
28+
Inputs:
29+
Value: data.Counter3
30+
Outputs:
31+
Counter3: step.Value
32+
NextStepId: Step3.1.2
33+
- Id: Step3.1.2
34+
StepType: WorkflowCore.TestAssets.Steps.Counter, WorkflowCore.TestAssets
35+
Inputs:
36+
Value: data.Counter4
37+
Outputs:
38+
Counter4: step.Value
39+
- - Id: Step3.2.1
40+
StepType: WorkflowCore.Primitives.WaitFor, WorkflowCore
41+
NextStepId: Step3.2.2
42+
CancelCondition: data.Flag2
43+
Inputs:
44+
EventName: '"Event1"'
45+
EventKey: '"Key1"'
46+
EffectiveDate: DateTime.Now
47+
- Id: Step3.2.2
48+
StepType: WorkflowCore.TestAssets.Steps.Counter, WorkflowCore.TestAssets
49+
Inputs:
50+
Value: data.Counter5
51+
Outputs:
52+
Counter5: step.Value
53+
- Id: Step4
54+
StepType: WorkflowCore.TestAssets.Steps.Counter, WorkflowCore.TestAssets
55+
Inputs:
56+
Value: data.Counter6
57+
Outputs:
58+
Counter6: step.Value

test/WorkflowCore.Testing/JsonWorkflowTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.Extensions.Logging;
99
using WorkflowCore.Interface;
1010
using WorkflowCore.Models;
11+
using WorkflowCore.Services.DefinitionStorage;
1112

1213
namespace WorkflowCore.Testing
1314
{
@@ -55,7 +56,7 @@ protected virtual void ConfigureServices(IServiceCollection services)
5556

5657
public string StartWorkflow(string json, object data)
5758
{
58-
var def = DefinitionLoader.LoadDefinition(json);
59+
var def = DefinitionLoader.LoadDefinition(json, Deserializers.Json);
5960
var workflowId = Host.StartWorkflow(def.Id, data).Result;
6061
return workflowId;
6162
}

0 commit comments

Comments
 (0)