News of the world

This blog is in the first case meant for myself so I don't forget interesting stuff. So you will find lots of useless topics, but there will certainly be also readings that might interest you. Lots of the items will go about my family, things we do or don't do but also about software, cars, gadgets, music, etc ... .

11 jul 2006

WinFX revisited

Ok, I promised you guys that was going to create some nifty WinFX applications. But unfortunately yours truly did not have enough time to do so. What I can say though is that I had a hell of a time installing WinFX.

Last week I installed the latest version of WinFX, called dotNet framework 3.0 right now. And instead of looking at WPF I started with WF - Workflow foundation. I found out that it isn't easy at all to find some good "getting started" tutorials. Although I came across a web site containing some short videos on how to build some basic workflows.

I started with WF, because it seems an ideal candidate for a project I am currently working on. So I'll certainly keep you posted about my WF findings... .

I'll start with parameter passing - how to inject parameters in your workflow?!
In the workflow you want to use the parameters you define a property that serves as the container for the property. To be able to pass parameters to your workflow you need to define a parameters Dictionary that will hold your parameters. And when you create the workflow instance you provide this Dictionary as a parameter to the CreateWorkflow method of the WF runtime.

Here is some code - I want to pass a list of people into my workflow - so I create a property for it:

namespace WorkflowConsoleApplication1
{
public sealed partial class Workflow1: SequentialWorkflowActivity
{
public class Person
{
private string firstname;

public string Firstname
{
get { return firstname; }
set { firstname = value; }
}

private string lastname;

public string Lastname
{
get { return lastname; }
set { lastname = value; }
}

public Person(string firstname, string lastname)
{
this.firstname = firstname;
this.lastname = lastname;
}
}

private List people;

public List People
{
get { return people; }
set { people = value; }
}


public Workflow1()
{
InitializeComponent();
}

private void WriteHelloWorld(object sender, EventArgs e)
{
foreach (Person p in People)
{
Console.WriteLine("Person: {0} {1}", p.Firstname, p.Lastname);
}
}
}
}

Next I create the Dictionary to hold the parameters for it

Dictionary parameters = new Dictionary();

List people = new List();
// populate it
people.Add(new WorkflowConsoleApplication1.Workflow1.Person("Jan", "Moons"));
people.Add(new WorkflowConsoleApplication1.Workflow1.Person("Biance", "Van Eynde"));

parameters.Add("people", people);

// create the instance with the parameters...
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleApplication1.Workflow1), parameters);

Very short explanation, but I think it is usefull when starting with WF and need to have some parameter passing.