Question

I have one question about Windows Workflow Foundation 4. I have an activity named PositionArrayActivity. This activity has a Sequence activity inside it. I need that in Execute method (during the workflow execution) oneFund variable mapping his value to PORTFOLIO_NAME that is created in Create method.... What have I to do to mapping oneFund value to PORTFOLIO_NAME at runtime?

Thanks

public sealed class PositionArrayActivity : NativeActivity, IActivityTemplateFactory
{
    [Browsable(false)]
    public Dictionary<string, List<Entity>> dictionary = new Dictionary<string, List<Entity>>();
    public ActivityAction<Entity[]> Body { get; set; }
    public Entity[] PositionList { get; set; }
    public SqlDataReader rdr;
    public SqlDataReader sdr;
    public Entity[] positionArray;
    public List<String> fundList;
    public String oneFund { get; set; }
    public String date { get; set; }
    public List<Entity> listToArrayPositions;

    protected override void CacheMetadata(NativeActivityMetadata metadata)
    {
        metadata.AddDelegate(Body);
    }

    protected override void Execute(NativeActivityContext context)
    {
       // A lot of code.... 
    }


    public Activity Create(DependencyObject target)
    {
        Variable<string> var = new Variable<string>
        {
            Name = "PORTFOLIO_NAME"
        };

        var fef = new PositionArrayActivity();  
        var aa = new ActivityAction<Entity[]>();
        var da = new DelegateInArgument<Entity[]>();
        da.Name = "positions";
        fef.Body = aa;
        aa.Argument = da;
        aa.Handler = new Sequence
        {
            Variables = { var }
        };

        return fef;
    }
}
Was it helpful?

Solution

You need to have an ActivityContext to set a variable value so first move the declaration of the var (did that name actually compile?) to a higher scope.

Then in Execute var.Set(activityContext, oneFund);

One thing though, the oneFund property will only be set once at application startup so you may have some surprising results. If you wanted that to be for each instance, you need an inargument.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top