Every business process or flow depends on data. When you think of data there are three elements to it as listed below -
- Variables - for storing data
- Arguments - for passing data
- Expressions - for manipulating data.
Let us first look at the variables. Variables are storage locations for data. Variables are declared before using them just like in any other languages like C# or VB.Net. Variables are defined with a specific scope. When you create a variable in an activity the scope of the variable becomes that activity's scope. Variables can also have access modifiers like None, Mapped or ReadOnly. Let us look at an example where we will create two variables and assign a scope to them along with access modifiers.
//Declare a sequence activitiy
Sequence seqWf = new Sequence();
//declare a variable of type string with default value = Hello
Variable
//specify access modifier as readOnly
vGreeting.Modifiers = VariableModifiers.ReadOnly;
Variable
vGreeting.Modifiers = VariableModifiers.ReadOnly;
//add variable to variables collection of an activity
seqWf.Variables.Add(vGreeting);
seqWf.Variables.Add(vGreetingPart);
//invoke the workflow
WorkflowInvoker.Invoke(seqWf);
In the above code sample we are creating two variables vGreeting and vGreetingPart. Both these variables are of type string Variable
//Declare a sequence activitiy
Sequence seqWf = new Sequence();
//declare a variable of type string with default value = Hello
Variable
Variable
//declare an assign activity
Assign
//specify the value to assign or input argument
assignment.Value = new InArgument
//specify the variable to set or output argument
assignment.To = new OutArgument
//add variable to variables collection of an activity
seqWf.Variables.Add(vGreeting);
seqWf.Variables.Add(vGreetingDuplicate);
//add activity to activities collection of the root activity
seqWf.Activities.Add(assignment);
//invoke the workflow
WorkflowInvoker.Invoke(seqWf);
In the above example we created two variables one vGreeting and another vGreetingDuplicate. Both of string type. Then we created an activity called Assign
We will discuss passing arguments in and out of a workflow in a separate post.
Lastly we have the expressions. Expressions are activities that you can use to operate on data. You can use expressions to set arguments. Expressions derive from Activity
//Declare a sequence activitiy
Sequence seqWf = new Sequence();
//declare a variable of type string
Variable
Variable
//declare an assign activity
Assign
//specify the variable to set or output argument
assignment.To = new OutArgument
//specify the value to assign or input argument
assignment.Value = new InArgument
//add variable to variables collection of an activity
seqWf.Variables.Add(vGreeting);
seqWf.Variables.Add(vGreetingPart);
//add activity to activities collection of the root activity
seqWf.Activities.Add(assignment);
//invoke the workflow
WorkflowInvoker.Invoke(seqWf);
Here we are manipulating the data before assigning it to a variable using a VisualBasicExpression - assignment.Value = new InArgument
There are many more expressions and you can create your own expression activities. Some basic expressions are -
- VariableValue
- VariableReference
- VisualBasicValue
- VisualBasicReference
Note - VisualBasicValue expression use visual basic syntax even when you are using c# to develop your workflow and its activities.
Comments