Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need demo on foreach #72

Open
heitorgiacomini opened this issue Apr 11, 2024 · 3 comments
Open

Need demo on foreach #72

heitorgiacomini opened this issue Apr 11, 2024 · 3 comments

Comments

@heitorgiacomini
Copy link

heitorgiacomini commented Apr 11, 2024

I need an tutorial on how to set an custon ActivityA that return an list of item, then foreach of then pass the value to Activities B and C.
I'm trying this, but without success

namespace CodeGeneratorWPF.Workflow
{
    public class CodeGenerationWorkflow : WorkflowBase
    {
        protected override ValueTask BuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = default)
        {
            var currentValueVariable = new Variable<EntityDefinition>("current", new EntityDefinition());
            var entities = new Variable<List<EntityDefinition>>("entities", new List<EntityDefinition>());

            builder.Root = new Sequence
            {
                Variables = { currentValueVariable, entities },
                Activities =
                {
                    new GetEntityDefinitionStep()
                    {
                        InputContainerModel = new(entities)
                    },
                    new SetVariable
                    {
                        Variable = entities,
                        Value = new(context =>
                        {
                            return builder.Outputs.FirstOrDefault(x => x.Name == "entities");
                        })
                    },
                    new ForEach<EntityDefinition>((ICollection<EntityDefinition>)entities.Value){
                        CurrentValue = new Output<EntityDefinition>(currentValueVariable),
                        Body = new Sequence
                        {
                            Activities =
                            {
                                new NetCore_EntityFrameworkStep(currentValueVariable)
                                {
                                },
                                new WriteLine(context => $"Counter {currentValueVariable.Get(context)}")
                            }
                        }
                    }
                }
            };
            return ValueTask.CompletedTask;
        }
    }
}
public class GetEntityDefinitionStep : CodeActivityWithResult
{
    public Output<List<EntityDefinition>> OutputEntities { get; set; }
    public List<EntityDefinition> Entities { get; set; }
    public Input<List<string>> InputPathOfClasses { get; set; }
    public Input<ContainerModel> InputContainerModel { get; set; }
    public Output<ContainerModel> OutputContainerModel { get; set; }
    public Output<List<EntityDefinition>> OutputEntityDefinition { get; set; }
    public List<string> PathOfClasses { get; set; }
    class ClassInformatasdfion
    {
        public string Name { get; set; }
        public List<PropertyInfoasdfrmation> Properties { get; set; }
        public bool HasDecorator { get; set; }
        public string SystemType { get; set; }
    }
    class PropertyInfoasdfrmation
    {
        public string Name { get; set; }
        public string Type { get; set; }
        public List<string> Decorators { get; set; } = new List<string>();
    }
    //public GetEntityDefinitionStep(Variable<List<string>> pathOfClasses)
    //{
    //    InputPathOfClasses = new(pathOfClasses);
    //}
    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
    {
        Console.WriteLine("BEGIN - " + this.GetType().Name);
        //var a = InputPathOfClasses.Get(context);
        var containerModel = context.WorkflowInput.FirstOrDefault(x => x.Key == "container").Value;
        var container = GetEntityDefinition(containerModel as ContainerModel);
        Console.WriteLine("END - " + this.GetType().Name);
        //Result.SetPropertyValue("entities", container.Entities);
        OutputContainerModel.Set(context, new Variable<ContainerModel>(container));
        OutputEntityDefinition.Set(context, new Variable<List<EntityDefinition>>(container.Entities));
        context.SetVariable("entities", container.Entities);
    }
}
@sfmskywalker
Copy link
Member

The expression for the ForEach activity looks incorrect. It should be something like this:

new ForEach<EntityDefinition>(context => entities.Get(context))

We could probably add an overload of the ForEach constructor that allows you to pass in the workflow variable directly, i.e.:

new ForEach<EntityDefinition>(entities)

@heitorgiacomini
Copy link
Author

The expression for the ForEach activity looks incorrect. It should be something like this:

new ForEach<EntityDefinition>(context => entities.Get(context))

We could probably add an overload of the ForEach constructor that allows you to pass in the workflow variable directly, i.e.:

new ForEach<EntityDefinition>(entities)

That seens to work. but now how to i get current value?
image
currentValueVariable is null in my step

public NetCore_EntityFrameworkStep(Variable<EntityDefinition> currentValueVariable)
{
    this.currentValueVariable = currentValueVariable;
}

@heitorgiacomini
Copy link
Author

The expression for the ForEach activity looks incorrect. It should be something like this:

new ForEach<EntityDefinition>(context => entities.Get(context))

We could probably add an overload of the ForEach constructor that allows you to pass in the workflow variable directly, i.e.:

new ForEach<EntityDefinition>(entities)

That seens to work. but now how to i get current value? image currentValueVariable is null in my step

public NetCore_EntityFrameworkStep(Variable<EntityDefinition> currentValueVariable)
{
    this.currentValueVariable = currentValueVariable;
}

I got it!

protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
        {
 var tempA = currentValueVariable.Get(context);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants