ramlicious Blogs by Tina & Prabhu

December 5, 2011

Creating your first Workflow Foundation project

Filed under: .NET,C#,Programming,WF — Prabhuram @ 4:48 pm

First my thanks goes to Christophe Geers for making me put my first Workflow Foundation project. I am currently working on a project that requires WF for creating Business Rules. So here it goes. I have put a very simple solution that will help the reader understand about how to create a WF project.
First let us see what we are going to do. My new rule object will interpret an object called Person and will generate a message to address a person like:

Good afternoon Mr.Prabhuram Venkatesan

To start, let’s first create a business object called Person.

public enum GenderType { Male, Female };
public class Person
{
	public bool IsMarried { get; set; }
	public bool IsMinor { get; set; }
	public GenderType Gender { get; set; }
	public string FirstName { get; set; }
	public string LastName { get; set; }
}

Our business rule is going to be embedded in a Workflow Console Application called Rules, within a Activity design called Addresser.xaml. I have implemented the business rules using the Flowchart, FlowDecision, and Assign toolbox controls using the Workflow designer, though you can apply your creativeness to do the same in a different ways. Additionally I created Flowchart variables called Salutation and Greetings, an In argument called ThePerson which is of type Person and an Out argument called the Message which is of type String. The usage of the variables can be seen in this figure below.

So to apply the rule, the input arguments has to be passed through the invoker and the output arguments can be received from the returned object.

Dictionary input = new Dictionary();
input.Add("ThePerson", new Person(){ FirstName="Prabhuram", LastName = "Venkatesan", Gender = GenderType.Male, IsMarried =true});

Dictionary output = (Dictionary)WorkflowInvoker.Invoke(new Addresser(), input);
Console.WriteLine(output["Message"].ToString());
Console.ReadLine();

I haven’t provided the complete code sample because I want the reader to put some effort to perform some findings by their own to figure out the components necessary.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress