PropertyKey<int> A = "a";
PropertyKey<int> A2 = "a2";
PropertyKey<int> B = "b";
WorkflowStepBase transform = new TransformStep<int, int>(
A, A2, x => x * 2, false);
WorkflowStepBase falseStepDoNothing = SimpleStepBuilder.New(
"false-step-skip", [], [], null, Functions.Success());
Workflow workflow = WorkflowBuilder.Create("SimpleWorkflow")
.AddProperties(x => x.SetProperty(A, 1))
.AddTransformStep(A, A2, x => x * 2, false)
.AddParallelStep("parallel", [A], [B], TimeSpan.FromSeconds(20),
x => x
.AddBranch(a => a.SimpleStep(
"simple", [A], [B], TimeSpan.FromSeconds(10),
Functions.TryAsync(async (s, c, ct) =>
await Task.Delay(1000.Rand(), ct))))
.AddBranch(a => a.ConditionalStep(
"if-step", [A], [B], TimeSpan.FromSeconds(15), b => b
.WithCondition(ctx => ctx.GetProperty(A) > 0)
.WithTrueStep(t => t.SimpleStep(
"true-step", [A], [B], TimeSpan.FromSeconds(18),
Functions.TryAsync(async (s, c, ct) =>
await Task.Delay(1000.Rand(), ct))))))
.AddBranch(a => a.ConditionalStep(
"if-step2", [A], [B], TimeSpan.FromSeconds(15), b => b
.WithCondition(ctx => ctx.GetProperty(A) < 0)
.WithTrueStep(t => t.SimpleStep(
"true-step2", [A], [B], TimeSpan.FromSeconds(18),
Functions.TryAsync(async (s, c, ct) =>
await Task.Delay(1000.Rand(), ct))))
.WithFalseStep(falseStepDoNothing))))
.ConnectObserver(new CustomObserver())
.Build();
var engine = new WorkflowEngine("default");
WorkflowResult result = await engine.RunWorkflowAsync(workflow);
public class CustomObserver : IStepObserver
{
public void OnStepBegin(
WorkflowStepBase workflowStep,
WorkflowContext context)
{
}
public void OnStepEnd(
WorkflowStepBase workflowStep,
WorkflowContext context,
WorkflowResult? workflowResult)
{
}
}Workflow output may be collected using Workflow.CreateSummary.
await using Stream stream = File.Create("workflow-result.json");
workflow.CreateSummary(workflowResult, stream);Below is a sample output from running the ComplexWorkflow example above.
=== WORKFLOW EXECUTION ANALYSIS ===
Step Performance:
AddProperties: 2ms
Branch1: 0ms
NestedParallel1: 0ms
NestedParallel2: 0ms
Branch2: 1ms
Parallel 1: 2ms
TrueParallel1: 0ms
TrueParallel2: 0ms
Parallel: 0ms
Conditional 2: 0ms
Parallel Execution:
Parallel 1: Ran 2 steps in parallel
Steps: Branch1, Branch2
Parallel 1: Ran 2 steps in parallel
Steps: NestedParallel1, NestedParallel2
Conditional 2: Ran 2 steps in parallel
Steps: TrueParallel1, TrueParallel2
Conditional Steps:
Branch2: Condition=true, Branch=true
Conditional 2: Condition=true, Branch=true
Execution Timeline:
[08:46:07.009] ComplexWorkflow Step[0] AddProperties Started - Starting
[08:46:07.011] ComplexWorkflow Step[0] AddProperties Completed - Completed (2ms)
[08:46:07.015] ComplexWorkflow Step[1] Parallel 1 Started - Starting
[08:46:07.016] ComplexWorkflow Step[1] Parallel 1 ParallelStarted - Starting 2 parallel steps
[08:46:07.016] ComplexWorkflow Step[1] Branch1 Started - Parallel 1
[08:46:07.016] ComplexWorkflow Step[1] Branch1 Completed - Parallel 1 (0ms)
[08:46:07.016] ComplexWorkflow Step[1] Branch2 Started - Parallel 1
[08:46:07.017] ComplexWorkflow Step[1] Branch2 ConditionalEvaluated - Condition: True
[08:46:07.017] ComplexWorkflow Step[1] NestedParallel1 Started
[08:46:07.017] ComplexWorkflow Step[1] Parallel 1 ParallelStarted - Starting 2 parallel steps
[08:46:07.017] ComplexWorkflow Step[1] NestedParallel1 Started - NestedParallel1
[08:46:07.017] ComplexWorkflow Step[1] NestedParallel1 Completed - NestedParallel1 (0ms)
[08:46:07.017] ComplexWorkflow Step[1] NestedParallel2 Started - NestedParallel1
[08:46:07.017] ComplexWorkflow Step[1] NestedParallel2 Completed - NestedParallel1 (0ms)
[08:46:07.017] ComplexWorkflow Step[1] NestedParallel1 Completed
[08:46:07.017] ComplexWorkflow Step[1] Branch2 Completed - Parallel 1 (1ms)
[08:46:07.017] ComplexWorkflow Step[1] Parallel 1 Completed - Completed (2ms)
[08:46:07.017] ComplexWorkflow Step[2] Conditional 2 Started - Starting
[08:46:07.017] ComplexWorkflow Step[2] Conditional 2 ConditionalEvaluated - Condition: True
[08:46:07.017] ComplexWorkflow Step[2] Parallel Started
[08:46:07.017] ComplexWorkflow Step[2] Conditional 2 ParallelStarted - Starting 2 parallel steps
[08:46:07.017] ComplexWorkflow Step[2] TrueParallel1 Started - Parallel
[08:46:07.017] ComplexWorkflow Step[2] TrueParallel1 Completed - Parallel (0ms)
[08:46:07.017] ComplexWorkflow Step[2] TrueParallel2 Started - Parallel
[08:46:07.017] ComplexWorkflow Step[2] TrueParallel2 Completed - Parallel (0ms)
[08:46:07.017] ComplexWorkflow Step[2] Parallel Completed (0ms)
[08:46:07.017] ComplexWorkflow Step[2] Conditional 2 Completed - Completed (0ms)
=== DETAILED LOG (JSON) ===
Additionally, more details are written to workflow-result.json:
{
"workflowName": "ComplexWorkflow",
"workflowId": "1d073e85-83da-4569-8044-8e31ea4d3f86",
"design": [
{
"stepName": "AddProperties",
"producedProperties": [
{
"key": "payment.successful",
"type": "System.Boolean"
}
]
},
{
"stepName": "Parallel 1",
"stepDescription": "Parallel step with 2 sub steps",
"timeout": "00:00:10",
"requiredProperties": [
{
"key": "payment.successful",
"type": "System.Boolean"
}
],
"producedProperties": [],
"subSteps": [
{
"stepName": "Branch1",
"stepDescription": "Simple step",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
},
{
"stepName": "Branch2",
"stepDescription": "Conditional step with true-step and false-step",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [
{
"stepName": "NestedParallel1",
"stepDescription": "Parallel step with 2 sub steps",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [
{
"stepName": "NestedParallel1",
"stepDescription": "Simple step",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
},
{
"stepName": "NestedParallel2",
"stepDescription": "Simple step",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
}
],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
},
{
"stepName": "FalseBranch",
"stepDescription": "Simple step",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
}
],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
}
],
"annotation": [
"Produced properties: none - please set this in the workflow"
]
},
{
"stepName": "Conditional 2",
"stepDescription": "Conditional step with true-step and false-step",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [
{
"stepName": "Parallel",
"stepDescription": "Parallel step with 2 sub steps",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [
{
"stepName": "TrueParallel1",
"stepDescription": "Simple step",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
},
{
"stepName": "TrueParallel2",
"stepDescription": "Simple step",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
}
],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
},
{
"stepName": "FalseBranch",
"stepDescription": "Parallel step with 2 sub steps",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [
{
"stepName": "FalseParallel1",
"stepDescription": "Simple step",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
},
{
"stepName": "FalseParallel2",
"stepDescription": "Simple step",
"requiredProperties": [],
"producedProperties": [],
"subSteps": [],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
}
],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
}
],
"annotation": [
"Required properties: none - please set this in the workflow",
"Produced properties: none - please set this in the workflow"
]
}
],
"isSuccess": true,
"totalDuration": "00:00:00.0079270",
"executionLog": [
{
"stepIndex": 0,
"stepName": "AddProperties",
"timestamp": "2025-09-28T08:46:07.009648Z",
"eventType": "Started",
"message": "Starting",
"properties": {}
},
{
"stepIndex": 0,
"stepName": "AddProperties",
"timestamp": "2025-09-28T08:46:07.01192Z",
"eventType": "Completed",
"message": "Completed",
"durationMs": 2.485,
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 1,
"stepName": "Parallel 1",
"timestamp": "2025-09-28T08:46:07.0151Z",
"eventType": "Started",
"message": "Starting",
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 1,
"stepName": "Parallel 1",
"timestamp": "2025-09-28T08:46:07.016472Z",
"eventType": "ParallelStarted",
"message": "Starting 2 parallel steps",
"properties": {
"parallelStepCount": 2,
"parallelSteps": [
"Branch1",
"Branch2"
]
}
},
{
"stepIndex": 1,
"stepName": "Branch1",
"timestamp": "2025-09-28T08:46:07.01669Z",
"eventType": "Started",
"message": "Parallel 1",
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 1,
"stepName": "Branch1",
"timestamp": "2025-09-28T08:46:07.016696Z",
"eventType": "Completed",
"message": "Parallel 1",
"durationMs": 0.005,
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 1,
"stepName": "Branch2",
"timestamp": "2025-09-28T08:46:07.016724Z",
"eventType": "Started",
"message": "Parallel 1",
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 1,
"stepName": "Branch2",
"timestamp": "2025-09-28T08:46:07.017308Z",
"eventType": "ConditionalEvaluated",
"message": "Condition: True",
"properties": {
"workflow.conditionResult": true,
"workflow.branchTaken": true
}
},
{
"stepIndex": 1,
"stepName": "NestedParallel1",
"timestamp": "2025-09-28T08:46:07.017309Z",
"eventType": "Started",
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 1,
"stepName": "Parallel 1",
"timestamp": "2025-09-28T08:46:07.017315Z",
"eventType": "ParallelStarted",
"message": "Starting 2 parallel steps",
"properties": {
"parallelStepCount": 2,
"parallelSteps": [
"NestedParallel1",
"NestedParallel2"
]
}
},
{
"stepIndex": 1,
"stepName": "NestedParallel1",
"timestamp": "2025-09-28T08:46:07.017365Z",
"eventType": "Started",
"message": "NestedParallel1",
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 1,
"stepName": "NestedParallel1",
"timestamp": "2025-09-28T08:46:07.017366Z",
"eventType": "Completed",
"message": "NestedParallel1",
"durationMs": 0.049,
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 1,
"stepName": "NestedParallel2",
"timestamp": "2025-09-28T08:46:07.017368Z",
"eventType": "Started",
"message": "NestedParallel1",
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 1,
"stepName": "NestedParallel2",
"timestamp": "2025-09-28T08:46:07.017369Z",
"eventType": "Completed",
"message": "NestedParallel1",
"durationMs": 0.001,
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 1,
"stepName": "NestedParallel1",
"timestamp": "2025-09-28T08:46:07.017463Z",
"eventType": "Completed",
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 1,
"stepName": "Branch2",
"timestamp": "2025-09-28T08:46:07.017464Z",
"eventType": "Completed",
"message": "Parallel 1",
"durationMs": 0.743,
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 1,
"stepName": "Parallel 1",
"timestamp": "2025-09-28T08:46:07.017527Z",
"eventType": "Completed",
"message": "Completed",
"durationMs": 2.429,
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 2,
"stepName": "Conditional 2",
"timestamp": "2025-09-28T08:46:07.017537Z",
"eventType": "Started",
"message": "Starting",
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 2,
"stepName": "Conditional 2",
"timestamp": "2025-09-28T08:46:07.017563Z",
"eventType": "ConditionalEvaluated",
"message": "Condition: True",
"properties": {
"workflow.conditionResult": true,
"workflow.branchTaken": true
}
},
{
"stepIndex": 2,
"stepName": "Parallel",
"timestamp": "2025-09-28T08:46:07.017564Z",
"eventType": "Started",
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 2,
"stepName": "Conditional 2",
"timestamp": "2025-09-28T08:46:07.01757Z",
"eventType": "ParallelStarted",
"message": "Starting 2 parallel steps",
"properties": {
"parallelStepCount": 2,
"parallelSteps": [
"TrueParallel1",
"TrueParallel2"
]
}
},
{
"stepIndex": 2,
"stepName": "TrueParallel1",
"timestamp": "2025-09-28T08:46:07.017571Z",
"eventType": "Started",
"message": "Parallel",
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 2,
"stepName": "TrueParallel1",
"timestamp": "2025-09-28T08:46:07.017571Z",
"eventType": "Completed",
"message": "Parallel",
"durationMs": 0,
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 2,
"stepName": "TrueParallel2",
"timestamp": "2025-09-28T08:46:07.017572Z",
"eventType": "Started",
"message": "Parallel",
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 2,
"stepName": "TrueParallel2",
"timestamp": "2025-09-28T08:46:07.017572Z",
"eventType": "Completed",
"message": "Parallel",
"durationMs": 0,
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 2,
"stepName": "Parallel",
"timestamp": "2025-09-28T08:46:07.017573Z",
"eventType": "Completed",
"durationMs": 0.009,
"properties": {
"payment.successful": true
}
},
{
"stepIndex": 2,
"stepName": "Conditional 2",
"timestamp": "2025-09-28T08:46:07.017575Z",
"eventType": "Completed",
"message": "Completed",
"durationMs": 0.038,
"properties": {
"payment.successful": true
}
}
]
}The workflow representation is included in the above and may be used to visualize the workflow. See PlantUmlActivityRenderer.linq for an example of rendering the workflow using PlantUML.
The rendered PlantUML file may be visualized in a tool such as PlantUML.js.