If you are new to WF pls read my previous posts on WF before proceeding with this.
In this post i will cover following :
- How to use IfElse Activity in sequential workflow provided by WF framework
- Authoring conditions using code instead of declarative rules.
To start follow the first three steps as in following post.
In the next step drag and drop the IfElse activity on to the empty workflow file. The ifElseActivity with two ifElseBranchActivity will be added to your workflow.
- Next step is to define the methods which will contain the condition logic for both of the ifElseBranch Activities.
- In the properties window of the first ifElseBranch Activity set the value of Condition parameter as 'Code Condition' and method name as 'Condition1'.
- For second ifElseBranch Activity set the values as 'Code Condition' and 'Condition2'
- For both of the conditions. methods will be generated as below
private void Condition1(object sender, ConditionalEventArgs e)
{
}
private void Condition2(object sender, ConditionalEventArgs e)
{
}
- Next add CodeActivity to both of the ifElseBranch Activities. The Code Activity will get executed whenever the corresponding ifElseBranch activity will get evaluated to true.
- Add code method names conditionCode1 and conditionCode2 for the above Code Activities.
- Both the condition code methods will get instance of ConditionalEventArgs as parameters. When the Result property of this instance is set as true, the condition is assumed to be satisfied.
- Modify the code in Workflow1.xoml.cs as below :
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
namespace SequentialWF
{
public partial class Workflow1 : SequentialWorkflowActivity
{
private void Condition1(object sender, ConditionalEventArgs e)
{
Console.WriteLine("condition one evaluated");
e.Result=true;
}
private void Condition2(object sender, ConditionalEventArgs e)
{
Console.WriteLine("condition two evaluated");
e.Result=false;
}
private void conditionCode1(object sender, EventArgs e)
{
Console.WriteLine("condition one executed");
}
private void conditionCode2(object sender, EventArgs e)
{
Console.WriteLine("condition two executed");
}
}
}
- When the above workflow is executed the output shown is :
condition one evaluated
condition one executed -
- Similarly if second condition is set to true and first as false the output shown is :
condition one evaluated
condition two evaluated
condition two executed - Any number of ifElseBranch activities can be added to the workflow.
~bye & take care~
Other Posts
- Defining Conditions based WorkFlow
- How to develop a simple sequential workflow
- Components required to develop WorkFlow (WF) enabled applications
- Windows WorkFlow Foundation (WF) : An Overview
- DinnerNow : Showcase of .Net Technologies
- ASP.NET Dynamic Code compilation trick
- Enhancements coming up in Orcas
- LINQ : .NET Language Integrated Query
No comments:
Post a Comment