3

I need advice regarding a requirement in one of our project. What we are trying to achieve is that we want to control flow of methods calls from a text or XML file.

For example:

string response = new Assembly1.Class1().DoStuff();
if (response == "OK")
{
  new Assembly1.Class2().DoStuff();
}
else if (response == "NOTOK")
{
  new Assembly2.Class1().DoStuff();
}

How can i represent above code in some format that can be altered by non-technical user to modify the sequence of function calls.

Naveed
  • 75
  • 5

3 Answers3

2

Fundamentally, you have to decide what you are trying to accomplish.

C# code contains a certain amount of complexity in it, but all that complexity is there because C# code is very flexible.

You have to decide how much flexibility you want to give your non-technical users. If you want to give them the same flexibility as C#, well, you might as well just have them program in C#.

Otherwise, the first step is going to be to invent a domain-specific language that describes the configuration that they are going to do. Before you do that, though, you might want to research if there are any existing domain specific languages that already do what you're describing.

The next step, having defined a domain specific language, is to parse and interpret that language. This is relatively complicated, and is usually the subject of a one-semester long course in college called Compilers. If you haven't taken a compilers course, there are books you can read. You may be able to skip a lot of steps by using a markup language like XML and a standard XML parsing library.

Joel Spolsky
  • 33,372
  • 17
  • 89
  • 105
  • i checked simple state machine project (http://simplestatemachine.codeplex.com/) that uses DSL written in boo but doesn't serve exactly the purpose. Is DSL the right way to go since in my case the workflow won't be that complicated; there will be simple function calls and if statements. – Naveed Dec 09 '10 at 06:00
  • A state machine is definitely the right way to go if you are trying to alter the control flow based on input data. State machines are VERY easy to implement and figure out... if you're going to use one, just learn enough to write your own, it's a beginning programming problem. As to which DSL you want to use, that is really a design decision. You can invent your own or try to find someone that has done something similar. – Joel Spolsky Dec 09 '10 at 06:02
0

I think you may use reflection for this purpose or generating code on-fly from xml. There are a lot of samples here.

acoolaum
  • 2,132
  • 2
  • 15
  • 24
  • Is there any simple open-source project that can do the job for me. Any good recommendation for "customizable workflow processes" solution. – Naveed Dec 09 '10 at 05:51
  • @Naveed, I don't know anyone, sorry. You may create your own simple DSL as Joel said. – acoolaum Dec 09 '10 at 06:10
0

Factory design pattern may be of good help to you. With factory pattern you can assign the objects at runtime and let those object decide the flow of the process...

You should build different classes with a method say WorkFlow() (referenced in a interface). The method should be able to call other methods based on the need.

At the beginning of the process, you just read the XML file and create an object for the appropriate class and call the workflow method of that class, which will inturn execute the pre-determined sequence.

The King
  • 4,600
  • 3
  • 39
  • 58