Using If/Else activity in Workflow Foundation

Introduction

In this post I will explain how to utilize the IF\Else activity and a declarative condition in the workflow to perform the conditional processing.

This workflow evaluates the order by taking the order value and if the order value  < $1000 then it will approved by Manager other wise it requires vice president  approval.

1. Create a new workflow project by selecting File->New->Project menu command visual studio displays the New Project dialogue window.

2. Select the Empty Workflow Project template from the dialogue box and say ok.

IfElse

3. Add the new item to the empty workflow project and select the Sequential Workflow (with code separation) template from the above dialogue box.

4. Start the workflow by writing the following code in Main program.cs file.

program

In above code we have started the workflow runtime and loaded the workflow type that we are going to design in the next step.

Notice that we are also passing the OrderValue as the parameter to the workflow.

5. Add the IF/ELSE activity to the workflow designer from the toolbox.

Ifelseworkflow

6. Add the condition to the ifElseBranch1 by selecting the ConditioName from the properties window.

condition

7. Similarly Add the condition to the ifElseBranch2 by selecting the condition name from the properties window.

8. Add the code activities below the both ifElseBranch1 and ifElseBranch2 branches and attach the event handlers to the ExecuteCode property.

9.  The code besides file of the workflow will look like

workflowcode

10. You can attach the ManagerApprovalHandler to one branch and VPApprovalHandler to another branch by selecting the code activities and assign the value to the Executecode property.

11.  You will see the following output after executing the application

console

Conclusion

We discussed about using the If/Else activity in workflow and evaluating the conditions using the activity. In the next post we discuss about other important activities in the workflow.


  • Permanent link to this post Permalink 
  • Share this post! Share It! 
  • View this post's comments Comments (189) 
  • RSS Feed for this post's comments Comment RSS
  •    


Windows Workflow Foundation Key Concepts with example

Introduction

This post discusses the key concepts of workflow foundation, authoring the sequential workflow using the visual studio 2008 designer for WF and debugging the workflows using visual studio 2008 designer.

You can Get the overview on windows workflow foundation before going to read this post.

1. Create the new workflow project by selecting the File->New->Project in

    VS 2008 it displays the following dialogue box

new

select the Sequential Workflow Console Application template and say ok.

2. We now have a workflow project with workflow1.cs file in the solution. You delete this file and right click on the project and say Add->New Item from the context menu.

WFnew

Select the Sequential Workflow (with code separation) template from the above dialogue box.

3. Drag and drop the Code activity to the design surface of the workflow.

WFSeq

Enter the value codeActivity1_CodeHandler for the ExecuteCode property.

4. Notice that codebeside class is a partial class and inheriting from the SequentialWorkflowActivity Base class.

codebeside

5. Right click the codeactivity in workflow design and select the insert break point option from the context menu.

6. Compile and run the application by pressing F5 then it starts the workflow instance and that instance will break in the debugger when it gets in to the code activity.

clip_image002

Conclusion

This post discussed the basic workflow application and concepts and next post am going to explain using the if else activity in workflow designer.


  • Permanent link to this post Permalink 
  • Share this post! Share It! 
  • View this post's comments Comments (46) 
  • RSS Feed for this post's comments Comment RSS
  •    


Windows Workflow Foundation Overview

Introduction

Windows Workflow Foundation is Framework for building the workflow enabled applications on windows. It consisting the workflow engine and designer. Workflow foundation supports both human and system workflow.

The Workflow Foundation can be used in the following scenarios

    • Workflow within Line-of-business applications.
    • User interface page flow
    • Human workflow
    • Workflow for SOA applications
    • Business rule driven workflow

Workflow foundation enables you to develop the applications with WCF and WPF technologies. Full support for VB.NET and C#, Debugging, a graphical designer for developing the workflow in code or  markup.It also provides model and designer to build custom activities that encapsulate the workflow functionality for end users and can be reused across multiple projects.

Workflow Overview

A workflow is a set of activities which describes the process. It describes the short or long-running work.

Workflow Runtime

Every workflow instance is created and maintained by an in-process engine referred as the workflow runtime engine. There can be multiple workflow runtime engines in an application.

Workflow model can be executed inside any windows process including console applications, forms-based applications, Windows services, ASP.NET Web sites and web services. Because a workflow is hosted in process, workflow can easily communicate with its host application.

clip_image001[4]

Activities Overview

Activities are elemental units in workflow. Activities are added to given flow path till it is completed then we say workflow instance is completed.

An activity can perform a single action, Example: writing a value to a database. It can be composite activity consist a set of activities. Activities have two types of behaviour design time and runtime.

WWF contains a library of standard activities and provides the mechanism for creating our own activity. This enables the extensibility and reusability between workflows.

Conclusion

This post explained the basic overview of workflow foundation and where can be it deployed. The coming posts discuss more in detail about the workflow foundation.


  • Permanent link to this post Permalink 
  • Share this post! Share It! 
  • View this post's comments Comments (118) 
  • RSS Feed for this post's comments Comment RSS
  •    


About Me

Deepak Kamboj

Deepak Kamboj, MCTS, JCP
ASP.NET/C# Web Developer
Chandigarh, India

RSS Contact Twitter Facebook LinkedIn

Yahoo: DeepakKamboj@yahoo.com
GTalk: DeepakKamboj@gmail.com
Skype: DeepakKamboj

Recent Comments