Till now what we saw is creating a basic activity and play with it. Now in this post, we will move ahead and see how to achieve the same functionality of creating custom activity. However in this post we will create custom sequence activity instead of simple basic activity.
If you haven’t gone through the previous post, then I recommend reading Creating custom activity in Workflow Part – 1 first and then continue reading further.
Remember this is not a custom composite activity, this is custom sequence activity. Creating custom composite activity will take a lot of effort. We will put on those efforts in subsequent post.
First let us understand and create custom sequence activity. Add new workflow activity library project to your solution. Name it whatever you want but make sure you inherit the activity from sequence activity rather than activity.
Let me give you highlights of what are we going to do in this activity. We will have one code activity which will get the Employee ID as a parameter. Internally we will get the employee from the table and then we will have if else condition, checking for each employee’s performance rate. Based on performance rate, we will shoot mail to manager with different subject and body line in mail.
So go ahead and add one Code activity in the designer surface, then drag one if else activity on surface. And then drag code activity and place on left branch, drag one more code activity and put on right branch.
Give Name “GetEmployeeSalary” to the First Code Activity which is outside of If else condition. Give Name “SendMailForLowPerformance” to left code activity and give Name “SendMailForGoodPerformance” for right side code activity.
Double click on each code activity to generate its respective handlers. Still you will notice one red circle for not setting branching condition. So go ahead and add declarative rule based condition for left branch if else activity.
Before adding that, write down following code. You will automatically have handlers for code activities as we generated few steps ago.
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 Sequential_Custom_Activity
{
public partial class Activity1 : SequenceActivity
{
public Activity1()
{
InitializeComponent();
}
public static DependencyProperty EmployeeIDProperty = DependencyProperty.Register
("EmployeeID", typeof(string), typeof(Activity1));
public string EmployeeID
{
get
{
return Convert.ToString(base.GetValue(EmployeeIDProperty));
}
set
{
base.SetValue(EmployeeIDProperty, value);
}
}
double _PerformanceRate;
public double PerformanceRate
{
get
{
return _PerformanceRate;
}
set
{
_PerformanceRate = value;
}
}
private void GetEmployeeSalary_ExecuteCode(object sender, EventArgs e)
{
}
private void SendMailForLowPerformance_ExecuteCode(object sender, EventArgs e)
{
}
private void SendMailForGoodPerformance_ExecuteCode(object sender, EventArgs e)
{
}
}
Go ahead and add declarative condition as shown in figure below.
As of now we haven’t done anything fancy.
Build the project. You should not find any error. Now create new console application workflow. Add our custom activity DLL to the toolbox. Drag and drop the custom sequence activity to the console workflow application. So should find something like shown below. Note that you are not allowed to make any changes in any of the branching conditions or nor the code condition as they are indicated by lock symbol.
Now in next post, we will be adding code in these blocks and will make it work.
No comments:
Post a Comment