Scenario : I implement a parent activity that performs another activity from an external source (database), following this post by Ron Jacobs .
This approach works, but I have several problems in my case, because WorkflowInvoker does not receive parent extensions:
- Tracking disabled for children
- My user extension for sharing does not work
- Extensions may vary depending on the host, so I canβt just add new ones.
Potential solution : Instead of Invoke for XAML children, I plan it (I believe that it will solve my problems, right?).
CacheMetadata: Download DynamicActivityfrom an external source and call metadata.AddChild(_childActivity);.
Then do:
protected override void Execute(NativeActivityContext context)
{
context.ScheduleActivity(_childActivity, OnActivityComplete);
}
And it worked! The next step is to pass the arguments In, Out, and InOut to the children.
Problem : Schedule for children DynamicActivity loaded from external XAML with parameters InArgument, OutArgument and InOutArgument
Something I do, but only works for OutArguments. In CacheMetadataI called my method_childActivity.BindArguments
public static void BindArguments(this DynamicActivity activity, IDictionary<string, Argument> argumentsToBind)
{
if (argumentsToBind == null)
return;
Type genericPropType, valueType, sourceArgumentType, vbReferenceType;
Argument sourceArgument;
foreach (var destinyArgument in activity.Properties)
{
if (!argumentsToBind.TryGetValue(destinyArgument.Name, out sourceArgument))
continue;
genericPropType = destinyArgument.Type.GetGenericTypeDefinition();
if (genericPropType == typeof(InArgument<>))
{
destinyArgument.Value = new InArgument<string>("It worked! But I need the value from context which is unavaliable since I'm inside CacheMetadata");
}
else
{
valueType = destinyArgument.Type.GetGenericArguments()[0];
sourceArgumentType = genericPropType.MakeGenericType(valueType);
if (sourceArgument != null)
{
vbReferenceType = typeof(VisualBasicReference<>).MakeGenericType(valueType);
object vbReference = Activator.CreateInstance(vbReferenceType,
GetExpressionText(sourceArgument, sourceArgumentType));
object referenceArgument = Activator.CreateInstance(sourceArgumentType, vbReference);
destinyArgument.Value = referenceArgument;
}
}
}
}
So , I need to pass InArguments and InOutArguments, but I need a value from the context, which is impossible, since I'm inside CacheMetadata.
I tried to set DynamicActivityProperty.Valuein the method Execute. But that didn't work either.
After that, I founded this page , which can help you understand my script.