Friday, May 29, 2009

Creating Custom Activity for Reading Input from User [Console] in WF 4.0

In WF 3.5 we use Dependency Property to set Input and Output variables to the workflow.  Now in WF 4.0 there is no more Dependency Property.

Dependency Property is Replaced with  InArgument and OutArugment. In this Blog post  I am going to write Custom Activity using  OutArgument to read input from user.

Step1 : First Create Activity Library Project.

image

Step2 : Add WrokflowElement Template to the project.

image

Step3: Add Public property OutPut and  Override the  Exectue Method as Shown below.

namespace GetInputFromUser
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.ComponentModel;

[Designer(typeof(SreeniGetInputFromUser))]
public class GetInput : CodeActivity
{
OutArgument<string> outputString;
public OutArgument<string> OutPut
{
get
{
return outputString;
}

set
{
outputString = value;
}
}
protected override void Execute(CodeActivityContext context)
{
string userInput =Console.ReadLine();
context.SetValue(outputString, userInput);
}
}
}





Step4 : Now we are going to add Designer to our Custom Activity  so that it looks good when we add this activity into other Workflow applications.



image



Using XAML you can add Good Look and Feel of the custom activity



image



Step 5: Now add new Sequential workflow console application and Add  Reference as this custom activity project  and starting using custom activity inside newly created Sequential workflow Project.





image



once you finishing the workflow Press F5 to execute.



image



Nandri(Thanks)



R.SeenivasaRagavan,

No comments: