How to add programming to my application

I am writing an application, which is essentially a rule engine. Users want to be able to define custom rules. Some of them will be fairly simple algebraic expressions, many of them will include some if-then branching logic, and some will be even more complex. What are my options for this?

My users are pretty smart, own T-SQL and Excel commands, and are usually familiar with programming constructs, but they are not “programmers” as such.

I was thinking about using VBA / VSTA; interaction with Excel somehow; integration of some scripting language (Ruby? Perl? Tcl?); or collapse my own.

In the best of all possible worlds, I will give them a color-coded editor and online help like IntelliSense, an immediate runtime for testing and experimentation, and a step debugger. They should also be able to save, retrieve, edit, and follow their rules. Flaming speed is not significant.

My environment is Windows / .Net 3.5 / C #

Any ideas?

+7
c # scripting
source share
13 answers

I am not a Windows person, so my answers will not exactly match your situation. I would recommend embedding a full-blown scripting interpreter in your application. We expose some primitives (i.e., Parts of your rule engine that you want to publish), and then provide a full-blown interpreter. I know that TCL, Python, and Guile are designed to be installed this way. I personally recommended Python, as Scheme (guile) is a little esoteric, and TCL seems to be losing at all.

+5
source share

Any implementation like this is full of risks. I would start with the smallest possible set of settings, and then gradually build up your capabilities from there.

Do not try to program all kinds of extensions on it if you do not already have a large number of skills. Choose one simple feature at a time - run standard SQL queries and returned recordsets or something else.

+3
source share

This is not quite what you are asking for, but depending on your needs, I would research Boo. It is relatively painless to create a DSL in Boo that is relatively readable by business people, which has great advantages, even if they are not the ones who directly code the rules.

Oren Eini Building Domain The specific languages ​​in Boo are pretty good and just came out in final form. The rule engine is one example of the DSL implementation that he is considering. Boo is a fully-built statically typed Python language for .Net, with a small but powerful community, and makes changing the language according to specific needs easier than almost any other alternative, thanks to the extensible compiler pipeline and a very nice semantic mass-macro system .

The good thing about Boo is that most DSLs are simply built on a common base class that provides you with a “language” but is not very different from the code you write in hard-coded rules. You can make the language look the way you want, but you don’t have to worry about manually analyzing or writing control flow commands or about all the things you expect from the language.

There are some drawbacks: this is not quite like Python or Ruby, the documentation is mostly in the Boo source code, and the community is, yes, not enough. But if you can "teach by example," you can get pretty far. The main caveat that applies to your wishlist is code completion; code completion has limited support with some VS plugins and with SharpDevelop, but that pretty much evaporates when creating a DSL.

+2
source share

Since .NET is your platform, you may need to implement ironpython. In fact, the author of one of the ironpython books used ironpython in a product that seems (on the surface) to have a lot in common with what you are doing. I think this is called Resolver One.

Edit

It's called Resolver One.

Here is a link to his book .

+2
source share

Do not invent your own scripting language! It is bad to learn a new language for a single system. I would try using Python, which is relatively easy to learn and understand.

0
source share

Windows built in Windows Script a host engine with two interpreters for VBScript and JScript. You can easily use them. Just check the MSDN for the appropriate COM interfaces.

0
source share

Lua may be a good solution. I'm really curious how complicated it can be to integrate your rule engine with a scripting language that allows users to write their own rules.

A good approach may be to embed everything (the rules mechanism) into the script interpreter, otherwise you will end up writing a lot of code to minimize what the user writes in the script, with the appropriate rules used in your program.

However, when developing such a programming feature, you need to pay a lot of attention to what your language should do, starting with a small kernel of utilities and then expanding it; or you can really plan a lot before you start the entire implementation, but for my experience (I wrote, like up to 3-4 translators), the best way is to put it during its development, of course, with user feedback: this will be because that you can assume how good they are, but I would not count on that.

0
source share

For the rules of honesty toward God, you can study Clips . Clips are an OpenSource expert system that you can embed in your own applications.

If you want to use true scripts, there are many tools for adding scripts to applications with languages ​​such as Lua, TCL, REXX, etc.

No matter what you do, you should carefully review licensing. Embedding other code in your system often has implications for how you can license the resulting program.

0
source share

Speaking from experience, because our core software has a scripting function.

We use Actipro SyntaxEditor as our scripting developer. Our initial requirement was "The user must write a formula for the field. This formula will be used to verify the contents of the field."

From this we used Dynamic Linq . The user was able to write the formula, while still having the ability to add math functions and user-defined functions. At that time, we did not need more, but now we see a limitation on the use of Dynamic Linq.

If we want to create a new version of our scripting engine, we will now rely on the use of a new language with DLR support: IronPython and IronRuby

0
source share

We are currently using Mozilla SpiderMonkey to complete this task in our web application. This is a javascript engine, so you can create your own functions and objects that match the actual business logic in your application. Javascript :: SpiderMonkey is a perl module that interacts, but I believe more languages ​​work with it.

0
source share

If the structure and rules are clear, then I would simulate the query interface contained in Lucene (java and .net). Basically, your rules become types of requests, and you can and / or them together just like Lucen does.

Finally, you can create an interface that allows your users to do the job. The critical part will be query types and associated metadata that can serve as elements to act on.

For example, suppose your rule engine is an e-commerce engine, and you allow your users to define rules that will reward customers for the discount if they add a specific product to their cart.

They will select the ProductQuery type that matches the product number, and then successfully completing the productquery will automatically reduce the discount.

Hope this helps.

0
source share

As others have stated, LUA is a fairly quick and easy way to embed a scripting language in your application. Our company product has a macro function, and I briefly got acquainted with the idea of ​​introducing full support for scripts as part of it. But in the end, we decided that the training would be a nightmare.

Despite this, this is a pretty good introduction to the built-in LUA in C # if you choose this route: http://blog.apterainc.com/software/embedding-lua-and-c/

0
source share

Instead of the built-in hint language, think about programming a graphic language or tool, if you can define all the possible rules and match them with the corresponding code, you can offer the end user a simple and easy way to add behavior and action to their workflow visually.

The UI-based rule engine is easier to learn and more convenient for non-programs. And you can always add a built-in scripting language to customize previous actions, last ones.

It is also a common tool used in ETLs, for example, to create business rules.

0
source share

All Articles