public sealed class Parent : NativeActivity
{
public Parent()
{
Childrens = new Collection<Activity>();
Variables = new Collection<Variable>();
_currentActivityIndex = new Variable<int>();
CurrentCustomTypeInstance= new Variable<MyCustomType>();
}
[Browsable(false)]
public Collection<Activity> Childrens { get; set; }
protected override void Execute(NativeActivityContext context)
{
_currentActivityIndex.Set(context, 0);
context.ScheduleActivity(FirstActivity, Callback);
}
private void Callback(NativeActivityContext context, ActivityInstance completedInstance, MyCustomType customTypeInstance)
{
CurrentCustomTypeInstance.Set(context, customTypeInstance);
ScheduleNextChildren(context, completedInstance);
}
private void ScheduleNextChildren(NativeActivityContext context, ActivityInstance completedInstance)
{
int nextActivityIndex = _currentActivityIndex.Get(context) + 1;
if (nextActivityIndex >= Childrens.Count)
return;
Activity nextActivity = Childrens[nextActivityIndex];
IFoo nextActivityAsIFoo = nextActivity as IFoo;
if (nextActivityAsIFoo != null)
{
var currentCustomTypeInstance = CurrentCustomTypeInstance.Get(context);
// HERE IS MY EXCEPTION
nextActivityAsIFoo.FooField.Set(context, currentCustomTypeInstance);
}
context.ScheduleActivity(nextActivity);
_currentActivityIndex.Set(context, nextActivityIndex);
}
}
And in register metadata:
metadata.SetChildrenCollection(Childrens);
I’ve already read http://msmvps.com/blogs/theproblemsolver/archive/2011/04/05/scheduling-child-activities-with-input-parameters.aspx but in my case, parent does not know the child activity
Edit
Similar to: Activity cannot set a Variable defined within its scope?
Activity '1.1: Parent' cannot access this variable because it is declared at the scope
of activity '1.1: Parent'. An activity can only access its own implementation variables.
But in my case, I don’t need to get the return value, so, hope to be easier. Just need to pass FooField implicitly instead of leting it to flow author.
I need to do it implicitly! If it doesn’t work at all, I will go with NativeActivityContext Properties
Got it! Looking at the Maurice’s blog I got inspired to do it
Workflow(very very simple!)
Output
Implementation
If anyone know how to do it in a better way please fell free to tell me. I will also need to pass the values to nested activities