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
43 changes: 43 additions & 0 deletions src/ConductorSharp.Engine/Builders/HumanTaskBuilder.cs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
using ConductorSharp.Client.Model.Common;
using ConductorSharp.Engine.Interface;
using ConductorSharp.Engine.Model;
using ConductorSharp.Engine.Util.Builders;
using Newtonsoft.Json.Linq;
using System;
using System.Linq.Expressions;

namespace ConductorSharp.Engine.Builders
{
public static class HumanTaskExtensions
{
public static ITaskOptionsBuilder AddTask<TWorkflow>(
this ITaskSequenceBuilder<TWorkflow> builder,
Expression<Func<TWorkflow, HumanTaskModel>> reference,
Expression<Func<TWorkflow, HumanTaskInput>> input
) where TWorkflow : ITypedWorkflow
{
var taskBuilder = new HumanTaskBuilder(reference.Body, input.Body, builder.BuildConfiguration);
builder.AddTaskBuilderToSequence(taskBuilder);
return taskBuilder;
}
}

internal class HumanTaskBuilder : BaseTaskBuilder<HumanTaskInput, NoOutput>
{
public HumanTaskBuilder(Expression taskExpression, Expression inputExpression, BuildConfiguration buildConfiguration)
: base(taskExpression, inputExpression, buildConfiguration) { }

public override WorkflowDefinition.Task[] Build() =>
new[]
{
new WorkflowDefinition.Task
{
Name = $"HUMAN_{_taskRefferenceName}",
TaskReferenceName = _taskRefferenceName,
Type = "HUMAN",
InputParameters = _inputParameters,
Description = new JObject { new JProperty("description", _description) }.ToString(Newtonsoft.Json.Formatting.None),
}
};
}
}
9 changes: 9 additions & 0 deletions src/ConductorSharp.Engine/Model/HumanTaskModel.cs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
using MediatR;
using Newtonsoft.Json;

namespace ConductorSharp.Engine.Model
{
public class HumanTaskInput : IRequest<NoOutput> { }

public class HumanTaskModel : TaskModel<HumanTaskInput, NoOutput> { }
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
<None Remove="Samples\Workflows\DecisionInDecision.json" />
<None Remove="Samples\Workflows\DecisionTask.json" />
<None Remove="Samples\Workflows\DynamicTask.json" />
<None Remove="Samples\Workflows\HumanTask.json" />
<None Remove="Samples\Workflows\IndexerWorkflow.json" />
<None Remove="Samples\Workflows\NestedObjects.json" />
<None Remove="Samples\Workflows\OptionalTaskWorkflow.json" />
Expand All@@ -32,9 +33,10 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Samples\Workflows\HumanTask.json" />
<EmbeddedResource Include="Samples\Workflows\WaitTask.json" />
<EmbeddedResource Include="Samples\Workflows\CSharpLambdaWorkflow.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
<EmbeddedResource Include="Samples\Workflows\CSharpLambdaWorkflow.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Samples\Workflows\DecisionInDecision.json" />
</ItemGroup>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,7 @@ public WorkflowBuilderTests()
_containerBuilder.RegisterWorkflow<DecisionTask>();
_containerBuilder.RegisterWorkflow<SwitchTask>();
_containerBuilder.RegisterWorkflow<PassthroughTaskWorkflow>();
_containerBuilder.RegisterWorkflow<HumanTaskWorkflow>();
_containerBuilder.RegisterWorkflow<WaitTaskWorkflow>();
_containerBuilder.RegisterWorkflow<IndexerWorkflow>();

Expand DownExpand Up@@ -227,6 +228,14 @@ public void BuilderReturnsCorrectDefinitionPassthroughTaskWorkflow()
}

[Fact]
public void BuilderReturnsCorrectDefinitionHumanWorkflow()
{
var definition = GetDefinitionFromWorkflow<HumanTaskWorkflow>();
var expectedDefinition = EmbeddedFileHelper.GetLinesFromEmbeddedFile("~/Samples/Workflows/HumanTask.json");

Assert.Equal(expectedDefinition, definition);
}

public void BuilderReturnsCorrectDefinitionWaitTaskWorkflow()
{
var definition = GetDefinitionFromWorkflow<WaitTaskWorkflow>();
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
{
"ownerApp": null,
"createTime": 0,
"updateTime": 0,
"createdBy": null,
"updatedBy": null,
"name": "human_task_workflow",
"description": "{\"description\":null,\"labels\":null}",
"version": 1,
"tasks": [
{
"queryExpression": null,
"name": "HUMAN_human_task",
"taskReferenceName": "human_task",
"description": "{\"description\":null}",
"inputParameters": {},
"type": "HUMAN",
"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": null,
"joinOn": null,
"sink": null,
"optional": false,
"taskDefinition": null,
"rateLimited": false,
"defaultExclusiveJoinTask": null,
"asyncComplete": false,
"loopCondition": null,
"loopOver": null
}
],
"inputParameters": [
"{}"
],
"outputParameters": null,
"failureWorkflow": null,
"schemaVersion": 2,
"restartable": true,
"workflowStatusListenerEnabled": true,
"ownerEmail": null,
"timeoutPolicy": null,
"timeoutSeconds": 0,
"variables": null
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConductorSharp.Engine.Tests.Samples.Workflows
{
public class HumanTaskWorkflowInput : WorkflowInput<HumanTaskWorkflowOutput> { }

public class HumanTaskWorkflowOutput : WorkflowOutput { }

public class HumanTaskWorkflow : Workflow<HumanTaskWorkflow, HumanTaskWorkflowInput, HumanTaskWorkflowOutput>
{
public HumanTaskModel HumanTask { get; set; }

public HumanTaskWorkflow(WorkflowDefinitionBuilder<HumanTaskWorkflow, HumanTaskWorkflowInput, HumanTaskWorkflowOutput> builder)
: base(builder) { }

public override void BuildDefinition()
{
base.BuildDefinition();

_builder.AddTask(wf => wf.HumanTask, wf => new() { });
}
}
}