Question

I am looking to create a custom composite activity in WF 4.5

The problem statement :

Create a custom activity with some pre defined properties and variables. The developer should be able to use this activity as a base and drag and drop other out of the box/ custom activities in it.

I have looked at various samples on the net and I have found the following sample which does exactly what i need.

http://msdn.microsoft.com/en-us/library/Aa480200

However it seems that with WF 4.5 the classes mentioned in the sample above have been deprecated. Is there a way to achieve what is done the sample above in WF 4.5 ?

Any links articles or samples which show how this can be done in WF 4.5 would help.

Was it helpful?

Solution

In WF4 composite activities can be achieved through IActivityTemplateFactory:

public sealed class CompositeActivity : IActivityTemplateFactory
{
    public Activity Create(DependencyObject target)
    {
        return new Sequence
        {
            Variables = {
                new Variable<string>("MyStringVar"),
                new Variable<int>("MyIntegerVar")
            },
            Activities = {
                new WriteLine { Text = "My first activity within the composite" },
                new Delay { Duration = new InArgument<TimeSpan>(a => TimeSpan.FromSeconds(5)) },
                new WriteLine { Text = "My third activity within the composite" }
            }
        };
    }
}

The designer knows IActivityTemplateFactory so it will show up on toolbox as any other activity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top