Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/ConductorSharp.Engine/Builders/DecisionTaskBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ public DecisionTaskBuilder<TWorkflow> AddCase(string caseName)
return this;
}

public DecisionTaskBuilder<TWorkflow> WithTask<F, G>(
Expression<Func<TWorkflow, SubWorkflowTaskModel<F, G>>> referrence,
Expression<Func<TWorkflow, F>> input
) where F : IRequest<G>
{
var builder = new SubWorkflowTaskBuilder<F, G>(referrence.Body, input.Body);
_caseDictionary[_currentCaseName].Add(builder);

return this;
}

public DecisionTaskBuilder<TWorkflow> WithTask<F, G>(
Expression<Func<TWorkflow, LambdaTaskModel<F, G>>> taskSelector,
Expression<Func<TWorkflow, F>> expression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<None Remove="Samples\Tasks\CustomerGet.json" />
<None Remove="Samples\Tasks\EmailPrepare.json" />
<None Remove="Samples\Workflows\Arrays.json" />
<None Remove="Samples\Workflows\ConditionallySendCustomerNotificationOutput.json" />
<None Remove="Samples\Workflows\NestedObjects.json" />
<None Remove="Samples\Workflows\SendCustomerNotification.json" />
<None Remove="Samples\Workflows\StringInterpolation.json" />
Expand Down Expand Up @@ -41,4 +42,8 @@
<ProjectReference Include="..\..\src\ConductorSharp.Engine\ConductorSharp.Engine.csproj" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Samples\Workflows\ConditionallySendCustomerNotificationOutput.json" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,16 @@ public void BuilderReturnsCorrectDefinitionArrayTask()

Assert.Equal(expectedDefinition, definition);
}

[Fact]
public void BuilderReturnsCorrectDefinitionSubworkflowInDecision()
{
var definition = SerializationUtil.SerializeObject(new ConditionallySendCustomerNotification().GetDefinition());
var expectedDefinition = EmbeddedFileHelper.GetLinesFromEmbeddedFile(
"~/Samples/Workflows/ConditionallySendCustomerNotificationOutput.json"
);

Assert.Equal(expectedDefinition, definition);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace ConductorSharp.Engine.Tests.Samples.Workflows;

#region models
public class ConditionallySendCustomerNotificationInput : WorkflowInput<ConditionallySendCustomerNotificationOutput>
{
public dynamic ShouldSendNotification { get; set; }
public dynamic CustomerId { get; set; }
}

public class ConditionallySendCustomerNotificationOutput : WorkflowOutput { }
#endregion
[OriginalName("NOTIFICATION_conditionally_send_to_customer")]
public class ConditionallySendCustomerNotification : Workflow<ConditionallySendCustomerNotificationInput, ConditionallySendCustomerNotificationOutput>
{
public DecisionTaskModel SendNotificationDecision { get; set; }
public SendCustomerNotificationV1 SendNotificationSubworkflow { get; set; }

public override WorkflowDefinition GetDefinition()
{
var builder = new WorkflowDefinitionBuilder<ConditionallySendCustomerNotification>();

builder.AddTask(
wf => wf.SendNotificationDecision,
wf => new() { CaseValueParam = wf.WorkflowInput.ShouldSendNotification },
("YES", builder => builder.WithTask(c => c.SendNotificationSubworkflow, wf => new() { CustomerId = wf.WorkflowInput.CustomerId }))
);

return builder.Build(opts => opts.Version = 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"ownerApp": null,
"createTime": 0,
"updateTime": 0,
"createdBy": null,
"updatedBy": null,
"name": "NOTIFICATION_conditionally_send_to_customer",
"description": "{\"description\":null,\"labels\":null}",
"version": 1,
"tasks": [
{
"queryExpression": null,
"name": "DECISION_send_notification_decision",
"taskReferenceName": "send_notification_decision",
"description": null,
"inputParameters": {
"case_value_param": "${workflow.input.should_send_notification}"
},
"type": "DECISION",
"dynamicTaskNameParam": null,
"caseValueParam": "case_value_param",
"caseExpression": null,
"expression": null,
"evaluatorType": null,
"scriptExpression": null,
"decisionCases": {
"YES": [
{
"queryExpression": null,
"name": "NOTIFICATION_send_to_customer",
"taskReferenceName": "send_notification_subworkflow",
"description": "{\"description\":null}",
"inputParameters": {
"customer_id": "${workflow.input.customer_id}"
},
"type": "SUB_WORKFLOW",
"dynamicTaskNameParam": null,
"caseValueParam": null,
"caseExpression": null,
"expression": null,
"evaluatorType": null,
"scriptExpression": null,
"decisionCases": null,
"dynamicForkJoinTasksParam": null,
"dynamicForkTasksParam": null,
"dynamicForkTasksInputParamName": null,
"defaultCase": null,
"forkTasks": null,
"startDelay": 0,
"subWorkflowParam": {
"name": "NOTIFICATION_send_to_customer",
"version": 1,
"taskToDomain": null,
"workflowDefinition": null
},
"joinOn": null,
"sink": null,
"optional": false,
"taskDefinition": null,
"rateLimited": false,
"defaultExclusiveJoinTask": null,
"asyncComplete": false,
"loopCondition": null,
"loopOver": null
}
]
},
"dynamicForkJoinTasksParam": null,
"dynamicForkTasksParam": null,
"dynamicForkTasksInputParamName": null,
"defaultCase": null,
"forkTasks": null,
"startDelay": 0,
"subWorkflowParam": null,
"joinOn": null,
"sink": null,
"optional": false,
"taskDefinition": null,
"rateLimited": false,
"defaultExclusiveJoinTask": null,
"asyncComplete": false,
"loopCondition": null,
"loopOver": null
}
],
"inputParameters": [
"{\"should_send_notification\":{\"value\":\"\",\"description\":\" (optional)\"},\"customer_id\":{\"value\":\"\",\"description\":\" (optional)\"}}"
],
"outputParameters": null,
"failureWorkflow": null,
"schemaVersion": 2,
"restartable": true,
"workflowStatusListenerEnabled": true,
"ownerEmail": null,
"timeoutPolicy": null,
"timeoutSeconds": 0,
"variables": null
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
namespace ConductorSharp.Engine.Tests.Samples.Workflows;

#region models
public class SendNotificationInput : IRequest<SendNotificationOutput>
{
public dynamic CustomerId { get; set; }
}

public class SendNotificationOutput { }

[OriginalName("NOTIFICATION_send_to_customer")]
public class SendCustomerNotificationV1 : SubWorkflowTaskModel<SendNotificationInput, SendNotificationOutput> { }

public class SendCustomerNotificationInput : WorkflowInput<SendCustomerNotificationOutput>
{
public dynamic CustomerId { get; set; }
Expand All @@ -9,7 +20,7 @@ public class SendCustomerNotificationOutput : WorkflowOutput
{
public dynamic EmailBody { get; set; }
}

#endregion
[OriginalName("NOTIFICATION_send_to_customer")]
public class SendCustomerNotification : Workflow<SendCustomerNotificationInput, SendCustomerNotificationOutput>
{
Expand Down