C# WorkFlow Foundation - Create a Custom Activity (Visual Studio 2017)
C# WorkFlow Foundation - Create a Custom Activity (Visual Studio 2017)
- Create a new project (File > New > Project)
- Choose “Workflow” and WorkFlow Console Application
- Name it and click OK
- This is what you should get by now:
- Grab Flowchart from the toolbox
- Grab flow decision
- Grab WriteLine and copy it three times
- Grab Delay shape
- Arrange all the artefacts in a similar manner as at the below picture
- Go to the properties of the Delay shape and type 00:00:05 in the Duration box
- Click on the Variables tab, in the left bottom corner and click on “Create Variable”
- Create a variable of type int32 called “a” initialize it with number 1 by typing 1 in the Default column
- Add four string variables
- “s” with a default value of “START”
- “y” with a default value of “YES”
- “n” with a default value of “NO”
- “n” with a default value of “NO”
- Now go to the properties of the Decision shape and change Condition field to include “a == 1”
- In the three WriteLine activities type s, y and n respectively
- Add another variable and another WriteLine activity in order to display “END” at the end of the program
- This is exactly what you should get:
- Overall - your Workflow should now be ready. Run it to check if everything works fine
- The Workflow that you’ve just created will, encounter the first WriteLine shape and it will display “START”, then it will proceed to checking if the variable a has a value of 1 it will display the word “YES” or “NO” respectively. It will then encounter another WriteLine activity and will display the word “END” it will then proceed to another shape and it will delay for 5 seconds (otherwise the command line just blinks at you and disappears immediately)
- Change the value of the variable a to 0 and se what’s the result
Add a custom activity
- Right click on the WorkFlowExample project > Add > New Item > Code Activity
- Name the Code Activity CustomActivity.cs and click OK
- Now edit the CustomActivity.cs
- Modify the Execute method
- Open the Toolbox and scroll right down to the bottom - your CustomActivity should it there
- Drag and drop it to your Workflow
- Run the project
- The final result:
Comments
Post a Comment