在设计时设置复合 WF4 活动的内部属性

发布于 2024-10-05 03:51:11 字数 303 浏览 5 评论 0原文

我想创建一个复合 Windows 工作流活动(在 .NET 4 下),其中包含预定义的 ReceiveAndSendReply 活动。有些属性是预定义的,但其他属性(特别是 ServiceContractName)需要在设计器中设置。

我可以将其实现为活动模板(与实现 ReceiveAndSendReply 的方式相同),但我宁愿不这样做。如果我稍后更改模板,我必须手动更新所有以前创建的工作流程。模板还允许其他开发人员更改应修复的属性。

有没有办法从 Xaml 活动中执行此操作?我还没有找到将参数值分配给嵌入活动的属性的方法。如果没有,您会建议什么技术?

I want to create a composite Windows Workflow Activity (under .NET 4) that contains a predefined ReceiveAndSendReply Activity. Some of the properties are predefined, but others (particularly ServiceContractName) need to be set in the designer.

I could implement this as an Activity Template (the same way ReceiveAndSendReply is implemented), but would rather not. If I later change the template, I'd have to update all previously created workflows manually. A template would also permit other developers to change properties that should be fixed.

Is there a way to do this from a Xaml Activity? I have not found a way to assign an Argument value to a property of an embedded Activity. If not, what technique would you suggest?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉酒的小男人 2024-10-12 03:51:11

我还没有使用复合 XAML 活动来完成此操作,并且在尝试时遇到一些错误,但通过 NativeActivity 这样做是没有问题的。请参阅下面的示例代码。

public class MyReceiveAndSendReply : NativeActivity
{
    private Receive _receive;
    private SendReply _sendReply;

    public string ServiceContractName { get; set; }
    public string OperationName { get; set; }

    protected override bool CanInduceIdle
    {
        get { return true; }
    }

    protected override void CacheMetadata(NativeActivityMetadata metadata)
    {
        _receive = _receive ?? new Receive();
        _sendReply = _sendReply ?? new SendReply();
        _receive.CanCreateInstance = true;
        metadata.AddImplementationChild(_receive);
        metadata.AddImplementationChild(_sendReply);

        _receive.ServiceContractName = ServiceContractName;
        _receive.OperationName = OperationName;

        var args = new ReceiveParametersContent();
        args.Parameters["firstName"] = new OutArgument<string>();
        _receive.Content = args;

        _sendReply.Request = _receive;

        var results = new SendParametersContent();
        results.Parameters["greeting"] = new InArgument<string>("Hello there");
        _sendReply.Content = results;

        base.CacheMetadata(metadata);
    }

    protected override void Execute(NativeActivityContext context)
    {
        context.ScheduleActivity(_receive, ReceiveCompleted);

    }

    private void ReceiveCompleted(NativeActivityContext context, ActivityInstance completedInstance)
    {
        context.ScheduleActivity(_sendReply);
    }
}

I haven't done this using a composite XAML activity and am getting some errors when I try but doing so through a NativeActivity is no problem. See the example code below.

public class MyReceiveAndSendReply : NativeActivity
{
    private Receive _receive;
    private SendReply _sendReply;

    public string ServiceContractName { get; set; }
    public string OperationName { get; set; }

    protected override bool CanInduceIdle
    {
        get { return true; }
    }

    protected override void CacheMetadata(NativeActivityMetadata metadata)
    {
        _receive = _receive ?? new Receive();
        _sendReply = _sendReply ?? new SendReply();
        _receive.CanCreateInstance = true;
        metadata.AddImplementationChild(_receive);
        metadata.AddImplementationChild(_sendReply);

        _receive.ServiceContractName = ServiceContractName;
        _receive.OperationName = OperationName;

        var args = new ReceiveParametersContent();
        args.Parameters["firstName"] = new OutArgument<string>();
        _receive.Content = args;

        _sendReply.Request = _receive;

        var results = new SendParametersContent();
        results.Parameters["greeting"] = new InArgument<string>("Hello there");
        _sendReply.Content = results;

        base.CacheMetadata(metadata);
    }

    protected override void Execute(NativeActivityContext context)
    {
        context.ScheduleActivity(_receive, ReceiveCompleted);

    }

    private void ReceiveCompleted(NativeActivityContext context, ActivityInstance completedInstance)
    {
        context.ScheduleActivity(_sendReply);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文