Question

Trying to understand how to use WF rule engine outside of a WWF application. I've only read a blog post on the topic. But I have certain doubts on the feasibility.

My application requirements are as follows:

  1. Web-based UI for writing the rules, and storing them in db.
  2. A windows service will download the rule. A rule execution engine will gather data it requires and execute the rule, and give a result as output.

The rule is simply a set of instructions which must act on a row of a table. The schema of the table is dynamic; however there is some metadata which tells the rule execution engine how to gather the necessary inputs from that row.

I know that rules are usually input using a rules editor; this is a windows form application. This usually generates a *.rules file. The WF rules engine, as per my knowledge, evaluates this file and does the execution of the rule.

The *.rules file is an xml representation of the rule.

Is there any api in the dotnet framework which generates this xml representation? And, can we build a web-based front end for inputting the rules?

Was it helpful?

Solution

Was wondering if there was an api kind of thingy and I came across the following:

http://code.msdn.microsoft.com/windowsdesktop/Creating-Rules-Using-the-23c5d561

It is an api like interface. However it consumes objects from the System.CodeDom namespace (usually various kinds of CodeExpression objects).

To go about using it you have to correctly represent the code expression objects in your front-end via some mechanism (by using xml or json). In the server, i.e. when you post the rule to the server, you have to create the necessary code expression correctly (via parsing) and feed those things to the api.

You need two types of code expression objects - one for evaluation of the rule condition, and the other for the stuff to execute when the rule passes or fails. (I only need stuff to execute when rule passes).

The sample provided there gives you an idea of how to use the api. The rest is something you'd have to build on.

A program source code is commonly represented in memory using an AST. All you'd have to design for is making your own implementation.

OTHER TIPS

If you want to use Windows Workflow Foundation (WF), you must have WF XAML generated - not .rules or XML representation of that (whatever that is). Here is an example of a Workflow XAML file. There are basically three ways to generate this (starting with the least complex method)

  1. By using the designer in Visual Studio
  2. By generating a DynamicActivity-instance runtime and serializing it
  3. By implementing your own generator

To answer your question: Yes - it's option #2. If your rules are very simple (if-then-else) and you don't anticipate them to increase in complexity in the future, option #3 may be a viable alternative as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top