Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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).

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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
196 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

Here's a working example:

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);
    }

}

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...