Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Need demo on foreach #8

@heitorgiacomini

Description

@heitorgiacomini

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions