Get IStepExecutionContext in conditions
Parallel Foreach is a useful control structure which can be used in many workflows. Now the context of Parallel Foreach can be used in Input statement however it would be perfect that can be used in other statements like When, If, Output, `WaitFor and others.
Not sure I follow... could you explain this with a code sample?
Absolutely. The workflow that I think about it is:
builder
.StartWith<SayHello>()
.ForEach(data => data.MyCollection)
.Do(x => x
.StartWith<DisplayContext>()
.Input(step => step.Item, (data, context) => context.Item)
.When((data, context) => context.Item == 1).Do(then => then
.StartWith<PrintMessage>()
.Input(step => step.Message, (data, context) => context.Item))
.When((data, context) => context.Item == 2).Do(then => then
.StartWith<PrintMessage>()
.Input(step => step.Message, data => "Outcome was 2"))
.Then<DoSomething>())
.Then<SayGoodbye>();
Gotcha, I believe this is currently possible with JSON workflows, we could look into creating overrides for the fluent API to expose the context parameter in the typed lambdas
https://workflowcore.atlassian.net/browse/WC-2?atlOrigin=eyJpIjoiYmQwZTQ0MGI4NGEyNDYxZThhODM4ZGE0YmY1ZTJjMjciLCJwIjoiaiJ9
Hi Daniel, I have the same issue with the forEach statement. could you give me an idea, when you plan to implement the enhancement? Thanks! Great software!
Hi everyone,
I also have a need for the IStepExecutionContext in many of the existing options (IF, ForEach, UserTask etc)
Here is how I added the context to the UserTask:
public static IUserTaskBuilder<TData> UserTask<TData, TStepBody>(this IStepBuilder<TData, TStepBody> builder, Expression<Func<TData, IStepExecutionContext, string>> userPrompt, Expression<Func<TData, IStepExecutionContext, string>> assigner, Action<IStepBuilder<TData, UserTask>> stepSetup = null)
where TStepBody : IStepBody
{
var newStep = new UserTaskStep();
builder.WorkflowBuilder.AddStep(newStep);
var stepBuilder = new UserTaskBuilder<TData>(builder.WorkflowBuilder, newStep);
stepBuilder.Input(step => step.AssignedPrincipal, assigner);
stepBuilder.Input(step => step.Prompt, userPrompt);
if (stepSetup != null)
stepSetup.Invoke(stepBuilder);
newStep.Name = newStep.Name ?? typeof(UserTask).Name;
builder.Step.Outcomes.Add(new ValueOutcome { NextStep = newStep.Id });
return stepBuilder;
}