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
public List
{
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
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.