Work Flow Engine With C# .Net MVC

Mehmet Alper KARAŞAHİN
4 min readOct 9, 2018

In this article I will explain how to develop a simple work flow engine (WFE) with C# .Net MVC platform. Firstly, we will design a work flow using with Process, Condition, Decision Point and Sub Process. After designing the work flow, our engine will orient this flow.

Main features of WFE

Work flow can be design visually.

Work flow diagram can be shown visually with Mermaid.js.

Batch jobs of system can be run automatically with HangFire

All process and their status can be shown visually.

All actions are traced and listed

Class Structure of WFE

Entity class

Service class

Controller class

How work flow engine works?

When we add any process (process, condition, decision point, sub process ) to the work flow, first node of work flow will be computed automatically.

When we add a process, we can select form type standard or special form. If we select special form we must determine form type. In all process types, we can choose monitoring roles and enter process complete messages for this roles.

If we add any decision point, we must set the decision method. This method is called automatically with reflection when the workflow reaches to this point. If decision method causes a recursion, a job is created to run this method at certain interval by hour.

All custom forms and decision methods can be seen inside work flow design area.

To save value of decision point and condition result, we can set a parameter name when we design the work flow. This parameter is set when the work flow process is changed.

Work Flow parameters are reachable inside decision methods.

public char IsCandidateColorBlind(string id)
{
var rslt = 'N';
int ownerId = GetOwnerIdFromId(int.Parse(id));
var variableEyeCondition = GetVariable("EYECONDITION", ownerId);
if (variableEyeCondition.CompareTo("COLORBLIND") == 0)
{
rslt = 'Y';
}
return rslt;
}

User can go back to any suitable and permitted previous step inside the work flow.

Sub processes can be added any point of work flow. Determined task instances are started when the flow reaches to this point.

Conclusion

Most enterprise applications contain a lot of forms which are related with each other via some condition. This relations causes confusion after the number of forms increases. This situation will affect not only developer and development time, but also application user learning time. Separation of forms’ business logic and relation of each other is provided by work flow engine. With the help of the workflow engine, the developer is only interested in the content of the form, the user can see the which point is in the workflow and how much work is left. This structure can be used for Electronic Document Management System (EDMS) or Purchasing Systems. Sample code can be downloaded from https://github.com/alperkarasahin/WorkFlowEngine

--

--