Workflow, an under-utilized tech

I went to Edmonton Code Camp yesterday, the presentation is about Workflow. The presenter has a lot of knowledge on WF but that lucky guy failed half of his demos. Anyway, his presentation did clear my cloudy impression to this new gizzmo. I like it very much. Sometimes we developers very easily lost in our initial design, WF’s graphic view should help us out at this scenario.

Can wait for his demo code, so I created my first workflow sample code.

  1. VS2008, File->New->Project->Workfolw->Sequential Workflow Console Application.
  2. Add a IfElse Activity from Toolbox into workflow GUI design painter.
  3. Declare a private variable in workflow class, private int _age = 29;
  4. Change ifElseBranchActivity1’s condition to ‘Declarative Rule Condition’
  5. Add a new Condition: this._age > 30.
  6. Drag Code Activity from Toolbox under ifElseBranchActivity1, view code, a new method is generated in workflow.cs, implement it with
    private void codeActivity1_ExecuteCode(object sender, EventArgs e)
    {
    Console.WriteLine(“Wow! welcome to adult camp! “);
    }
  7. Do the same thing to ifElseBranchActivity2,
    private void codeActivity2_ExecuteCode(object sender, EventArgs e)
    {
    Console.WriteLine(“Hello aaa you are not over 30 yet!”);
    }
  8. Run the app, a console window blinks then disappear, don’t why, then added my pause code to stop the console display.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Workflow.Runtime;
    using System.Workflow.Runtime.Hosting;namespace SampleSequentialWorkflowConsoleApplication
    {
    class Program
    {
    static void Main(string[] args)
    {
    using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
    {
    AutoResetEvent waitHandle = new AutoResetEvent(false);
    workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};
    workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
    {
    Console.WriteLine(e.Exception.Message);
    waitHandle.Set();
    };

    WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(SampleSequentialWorkflowConsoleApplication.SimpleSequentialWorkflow));
    instance.Start();

    Console.WriteLine(“Workflow instance started……”);
    waitHandle.WaitOne();
    Console.ReadKey();
    }
    }
    }
    }

  9. Re-run, wow! This is the famous workflow.
Advertisements

One thought on “Workflow, an under-utilized tech

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s