Windows工作流自定义序列活动 [英] Windows Workflow Custom Sequence Activity

查看:101
本文介绍了Windows工作流自定义序列活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows Workflow 4,并且我需要创建一个C#活动,该活动基本上是从Sequence活动中继承的。我希望它看起来像Sequence活动,因此用户可以从设计器中将其他活动拖放到该活动上。但是,它在代码中的行为有所不同(也许我想以不同的顺序运行它们,或者在每个命令之间执行特殊操作,这都没有关系)。

I'm working with Windows Workflow 4, and I need to create a C# activity that, basically, inherits from the Sequence activity. I want it to look just like the Sequence activity, so a user can drag and drop other activities onto it from the designer. But, it acts differently in the code (maybe I want to run them in a different order, or do special actions between each one, it shouldn't matter).

我怎样才能做到这一点?我看到了类似问了一个问题,只有一个人回答,该建议仅适用于Windows Workflow3。在版本4中,至少可以说,序列活动不能继承。

How can I do this? I see a similar question was asked about this, and only one person responded with a suggestion that only applies to Windows Workflow 3. In version 4, a sequence activity can't be inherited from, to say the least.

这似乎不是一个遥不可及的概念。 Sequence活动作为内置活动提供。因此,它应该是可复制的,或者至少是可继承的,这似乎合乎逻辑,因此我可以为Sequence活动定制版本。

This doesn't seem like a very far fetched concept. A Sequence activity is provided as a built in activity. So, it seems logical that it should be reproducible, or at least inheritable, so I can have a customized version of a Sequence activity.

有人有什么想法吗?

Anyone have any ideas?

推荐答案

WF 4中已经提供了 System.Activities.Core.Presentation.SequenceDesigner设计器。然后可以编写Sequence活动。并将此设计器用于外部类。

The "System.Activities.Core.Presentation.SequenceDesigner" designer is already available in WF 4. One can then compose a Sequence activity and use this designer for the outer class.

这是一个工作示例:

using System.Activities;
using System.Activities.Statements;
using System.Collections.ObjectModel;
using System.ComponentModel;

[Designer("System.Activities.Core.Presentation.SequenceDesigner, System.Activities.Core.Presentation")]
public class MySeq : NativeActivity
{
    private Sequence innerSequence = new Sequence();

    [Browsable(false)]
    public Collection<Activity> Activities
    {
        get
        {
            return innerSequence.Activities;
        }
    }

    [Browsable(false)]
    public Collection<Variable> Variables
    {
        get
        {
            return innerSequence.Variables;
        }
    }

    protected override void CacheMetadata(NativeActivityMetadata metadata)
    {
        metadata.AddImplementationChild(innerSequence);
    }

    protected override void Execute(NativeActivityContext context)
    {
        context.ScheduleActivity(innerSequence);
    }

}

这是在转发实际行为到私有的innerSequence,这可能会使这段代码看起来毫无用处,但是请注意,在Execute方法中,它使我们有机会在执行之前和之后执行操作。如果我们要提供自定义的行为,则必须实现它,而不是转发到内部私人活动。

This is forwarding the real behavior on to a private innerSequence, which might make this code seem useless, but note that in the Execute method it gives us a chance to do things before and after execution. If we want to provide customized behavior, we'd have to implement it instead of forwarding to an inner private activity.

这篇关于Windows工作流自定义序列活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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