使用参数安排从外部 XAML 加载的子 DynamicActivity [英] Schedule children DynamicActivity loaded from external XAML with parameters

查看:46
本文介绍了使用参数安排从外部 XAML 加载的子 DynamicActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:我正在实施一个父活动,它执行来自外部源(数据库)的其他活动,遵循这个 Ron Jacobs 发布.

Scenario: I'm implementing a parent activity which executes other activity from external source(database), following this Ron Jacobs post.

这种方法有效,但在我的情况下有一些问题,因为 WorkflowInvoker 没有获得父扩展:

This approach works but have a few problems in my case, because WorkflowInvoker don't get the parent extensions:

  • 对儿童禁用跟踪
  • 我的自定义数据共享扩展程序不起作用
  • 扩展程序可能会因主机而异,因此我不能简单地再次添加新的扩展程序.

可能的解决方案:我没有调用子 XAML,而是调度它(我相信它会解决我的问题,对吗?).

Potential solution: Instead of Invoke the children XAML, I'm scheduling it(I believe it will solve my problems, right?).

CacheMetadata:从外部源加载DynamicActivity并调用metadata.AddChild(_childActivity);.

CacheMetadata: load the DynamicActivity from the external source and call metadata.AddChild(_childActivity);.

然后执行:

    protected override void Execute(NativeActivityContext context)
    {
        context.ScheduleActivity(_childActivity, OnActivityComplete);
    }

它奏效了!下一步是将 In、Out 和 InOut 参数传递给孩子.

And it worked! Next step would be pass In, Out and InOut arguments to children.

问题:如何使用 InArgument、OutArgument 和 InOutArgument 值安排从外部 XAML 加载的子 DynamicActivity

Problem: How to Schedule children DynamicActivity loaded from external XAML with InArgument, OutArgument and InOutArgument values

我正在做但仅适用于 OutArguments 的事情.在 CacheMetadata 中,我调用了我的方法 _childActivity.BindArguments

Something I'm doing but is working just for OutArguments. In CacheMetadata I 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;
                }
            }
        }
    }

所以,我也需要传递 InArguments 和 InOutArguments,但我需要上下文中的值,因为我在 CacheMetadata 中,因此该值不可用.

So, I need to pass InArguments and InOutArguments too but I need the value from context which is unavaliable since I'm inside CacheMetadata.

我尝试在 Execute 方法中设置 DynamicActivityProperty.Value.但它也不起作用.

I tried to set the DynamicActivityProperty.Value in the Execute method. But it doesn't worked too.

之后,我创建了这个页面帮助你理解我的场景.

After, I founded this page that may help you to understand my scenario.

推荐答案

您是否考虑过将消息传递给子工作流,而不是执行所有这些操作?托管其他工作流的工作流不是一个得到很好支持的领域(如您所见).相反,工作流向其他工作流发送消息似乎是一种更好的方法.当然,您不能共享跟踪和扩展.我确实想出了一种方法来支持子工作流中的跟踪,但它使用了私有反射.

Instead of doing all of this have you considered passing messages to the child workflow? Workflows hosting other workflows is not an area that is well supported (as you have discovered). Instead Workflows sending messages to other workflows seems to be a better approach. Of course, you can't share tracking and extensions. I did come up with a way to support tracking in the child workflow but it uses private reflection.

这篇关于使用参数安排从外部 XAML 加载的子 DynamicActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆