How to customize activity in re-hosted Workflow 4 Designer?
This article shows how to create a custom activity in a rehosted Workflow designer (with Workflow Foundation 4). In that example, a MyDelayActivity
is created by implementing the IActivityTemplateFactory
interfa开发者_Go百科ce, and specifying the default value to the Delay
inputs.
However, is it possible to modify the inputs of the activity as well?
For example, let's say I want to add a new StartProcess
activity which takes a string and run the process specified by the string. I can implement this with the native activities by adding a InvokeMethod
activity, specifying Process.Start
as the method and a Collection containing the string as the parameter.
Can I simplify all these by just having a StartProcess
box with only a string input?
Sure, just create the activity to do the work and add InArgument properties to provide the data you need. When you drop the activity on the design surface you can use the property sheet to set the arguments. Alternatively you can create an activity designer to do the same on the design surface like for example the WriteLine activity.
Example:
public sealed class MyWriteLine : CodeActivity
{
public InArgument<string> Text { get; set; }
protected override void Execute(CodeActivityContext context)
{
string text = context.GetValue(this.Text);
Console.WriteLine(text);
}
}
Additional information, there are two very helpful video tutorials in the MSDN website: Developing custom activities and Activity designers, and I assume the speaker is the same Maurice as the accepted answerer :)
精彩评论