workflow-core icon indicating copy to clipboard operation
workflow-core copied to clipboard

Get IStepExecutionContext in conditions

Open hifeamin opened this issue 6 years ago • 6 comments

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.

hifeamin avatar Jul 09 '19 09:07 hifeamin

Not sure I follow... could you explain this with a code sample?

danielgerlag avatar Jul 10 '19 02:07 danielgerlag

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>();

hifeamin avatar Jul 10 '19 07:07 hifeamin

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

danielgerlag avatar Jul 17 '19 03:07 danielgerlag

https://workflowcore.atlassian.net/browse/WC-2?atlOrigin=eyJpIjoiYmQwZTQ0MGI4NGEyNDYxZThhODM4ZGE0YmY1ZTJjMjciLCJwIjoiaiJ9

danielgerlag avatar Jul 17 '19 03:07 danielgerlag

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!

ssm-dev avatar Aug 19 '19 10:08 ssm-dev

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;
    }

IvanJosipovic avatar Sep 30 '22 22:09 IvanJosipovic