Click here to Skip to main content
15,894,017 members
Articles / Programming Languages / C#

Workflow Foundation Project Using Visual Studio 2008 Express Edition

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
2 Nov 2008CPOL4 min read 60.1K   806   19  
Sequential WF example using VS 2008 Express Edition.
using System;
using System.ComponentModel;
using System.Workflow.Activities;

namespace FirstWF
{

        public sealed class SequentialWorkflow : SequentialWorkflowActivity
        {
            private IfElseActivity IsUnderLimitIfElseActivity;
            private IfElseBranchActivity YesIfElseBranch;
            private CodeActivity ApprovePO;
            private IfElseBranchActivity NoIfElseBranch;
            private CodeActivity RejectPO;

            /*
             * Initialization of the Activities for this Sequential Workflow
             * */
            public SequentialWorkflow()
            {
                this.CanModifyActivities = true;
                System.Workflow.Activities.CodeCondition codecondition1 = new System.Workflow.Activities.CodeCondition();
                this.IsUnderLimitIfElseActivity = new System.Workflow.Activities.IfElseActivity();
                this.YesIfElseBranch = new System.Workflow.Activities.IfElseBranchActivity();
                this.NoIfElseBranch = new System.Workflow.Activities.IfElseBranchActivity();
                this.ApprovePO = new System.Workflow.Activities.CodeActivity();
                this.RejectPO = new System.Workflow.Activities.CodeActivity();
                // 
                // IsUnderLimitIfElseActivity
                // 
                this.IsUnderLimitIfElseActivity.Activities.Add(this.YesIfElseBranch);
                this.IsUnderLimitIfElseActivity.Activities.Add(this.NoIfElseBranch);
                this.IsUnderLimitIfElseActivity.Name = "IsUnderLimitIfElseActivity";
                // 
                // YesIfElseBranch
                // 
                this.YesIfElseBranch.Activities.Add(this.ApprovePO);
                codecondition1.Condition += new System.EventHandler<System.Workflow.Activities.ConditionalEventArgs>(this.IsUnderLimit);
                this.YesIfElseBranch.Condition = codecondition1;
                this.YesIfElseBranch.Name = "YesIfElseBranch";
                // 
                // NoIfElseBranch
                // 
                this.NoIfElseBranch.Activities.Add(this.RejectPO);
                this.NoIfElseBranch.Name = "NoIfElseBranch";
                // 
                // ApprovePO
                // 
                this.ApprovePO.Name = "ApprovePO";
                this.ApprovePO.ExecuteCode += new System.EventHandler(this.OnApproved);
                // 
                // RejectPO
                // 
                this.RejectPO.Name = "RejectPO";
                this.RejectPO.ExecuteCode += new System.EventHandler(this.OnRejected);
                // 
                // SequentialWorkflow
                // 
                this.Activities.Add(this.IsUnderLimitIfElseActivity);
                this.Name = "SequentialWorkflow";
                this.CanModifyActivities = false;
            }

            // The event handler that executes on ExecuteCode event of the ApprovePO activity
            private void OnApproved(object sender, EventArgs e)
            {
                Console.WriteLine("Purchase Order Approved.");
            }

            // The event handler that executes on ExecuteCode event of the RejectPO activity
            private void OnRejected(object sender, EventArgs e)
            {
                Console.WriteLine("Purchase Order Rejected.");
            }

            // Code condition to evaluate whether to take the first branch, YesIfElseBranch
            // Since it always returns true, the first branch is always taken.
            private void IsUnderLimit(object sender, ConditionalEventArgs e)
            {
                e.Result = true;
            }
        }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Professional Service House in Sydney - Australia
Australia Australia
My name is Ayman Amin, I live and work in Australia .. I have been working in IT Development, Consultancy and currently in Solution Architecture domain for more than 16 Years.
I would like to share ideas on Software Engineering and IT Technology as it is my passion and occupation.

If i am not doing anything with Computers then i should either be Swimming, Driving or hanging around with my mates here in Sydney. I fly so often to Egypt, my home land so either i am a Regular tourist in Egypt or a Permenant visitor in Australia.

Comments and Discussions