Example of c# based rule language? - c#

Can you provide a good example of rule definition language written in C#.
Java guys have JESS, is there anything good for C#?

This page shows some examples of open-source rules engines in C#: http://csharp-source.net/open-source/rule-engines

You can use the forward chaining inference engine that is part of Windows Workflow Foundation (.NET 3.5 and higher) The best part is that this has a free runtime licensing.
You can use the Rule Manager from Acumen Business and install the Windows Workflow Foundation adapter. Once installed, export the rules as WFRules (*.rules).
A visual studio .NET solution will be generated that shows how the rule engine can be invoked standalone (no workflow is necessary)
See also http://bizknowledge.blogspot.com/search/label/Windows%20Workflow%20Foundation

Try http://rulesengine.codeplex.com
It has a fluent-interface wrapper for creating rules.
It's lightweight and simple to use.

You could use Windows Workflow Foundation's (WF) workflow engine with C#. I'd started a small and simple project using WF as the workflow engine, it's actually quite straightforward to use. Check out the first part entry I've been developing on this here.
What is interesting about WF is that you don't have to use the whole thing if you want to - if you only want to write some custom rules against some entities or objects, you can - quite ingenious! Also, it's a lot less to take on board than BizTalk's BRE (and no licensing cost).
You need to add a reference to the following .Net assemblies, available in the .Net Framework v3.0 and onwards:
System.Workflow.Activities
System.Workflow.ComponentModel
System.Workflow.Runtime
Check out the article for more info.

There is the Microsoft Business Rules Engine: http://msdn.microsoft.com/en-us/library/aa561216.aspx. Not sure if it can only be used inside Biztalk - it does says it is a .Net Class Library.

Microsoft Business Rule Engine(BRE) is quite nice. But(and that's a big BUT) you'll need a BizTalk Server license to use it.

Take a look at Jetfire on codeplex. It supports forward chaining 'rules'.

Related

Can we use JAVA based drools rules in .Net

I have a JAVA application which using drools rules.I need create a similar application in .Net.
Can i use same drools rule file in .Net application?.
If it need to be converted ,Is there any automated way to achieve it?
A quick google search found this - http://droolsdotnet.codehaus.org/, the key bit here seems to be:
Drools.NET is a Business Rules Engine (BRE) based on Charles Forgy's Rete algorithm. Developers can now exploit a powerful Rule Engine through a completely managed .NET code base! Drools.NET is based on Jboss Rules, and comes with all the features of that Rules Engine.
So I would guess this might be what you are after from the point of view of using any existing rules and definitions - I'm assuming you'll be rewriting the code itself regardless.
Drools is a Java application, and there is no port that would enable you to re-use DRL in a .NET application.
If you want to re-use your knowledge base, then you should expose it as a web service and call that from your .NET application.

What workflow framework to use in C#

I have to create a workflow in C# capable of moving an object (persisted as a database record) through an approval workflow where people are required to perform some sort of action or validation.
We initially looked at Windows Workflow Foundation but shied away from it because it seemed so infrastructure-heavy (and besides we don't really like Microsoft products). We looked at ObjectFlow because it's lightweight, but I'm having trouble figuring out how to persist & resume workflow states. It almost seems like it's too lightweight.
Does anyone have a particular favorite framework for doing workflow? I'm open to ideas (even to WWF, if you can explain why it's your favorite).
Now at the end of 2022 I recommend Elsa Workflows library which is free and open source.In this case state machine workflows works. I have used it in multiple projects witch success. It is flexible, has a web workflow designer and acceptable documents
As the question #gsharp linked to says, WF 4 isn't entirely easy to use. However, ObjectFlow has an easy fluent interface that is light and built with solid design principles. Given the apparent lack of decent workflow frameworks, I decided to pitch in and extend ObjectFlow with an IStatefulWorkflow that contains a .Yield() method capable of yielding workflow processing to the calling method so that it's state can be persisted.
The end result of my work will be a new release at codeplex in a couple weeks. Until then, you can follow my progress at github.
Have you looked at Drools.Net?
Drools.NET is a Business Rules Engine (BRE) based on Charles Forgy's Rete algorithm. Developers can now exploit a powerful Rule Engine through a completely managed .NET code base! Drools.NET is based on Jboss Rules, and comes with all the features of that Rules Engine.
I have recently developed a C# Workflow library that leverages the fluent syntax and provides compile time validation between workflow steps. A Workflow's steps can be consolidated in a single location providing maintainable code. The library is very light weight and performant.
https://www.nuget.org/packages/NetWorkflow
https://github.com/Tmarndt1/NetWorkflow

writing a DSL for the .Net platform

I am thinking of writing a DSL to be run in the .Net environment. I am most likely to implement this in C#, though I am flexible on this.
Is there a recommended online resources that show the main steps involved in writing a DSL for the .Net platform?
Ideally, I would like a resource that would provide at least an overview on the following:
'Spec'ing a DSL
How to map the specs to the .Net framework
Preferably a helloworld example of a trivial DSL implemented in a .Net language
[Edit]
Actually, I have just seen this article - but it is slightly dated. Does anyone have a view on whether the article is a good starting point or not (the .Net framework and C# seem to evolve at a very rapid pace)
If you are willing to buy a book on the topic, I highly recommend "DSLs in Boo: Domain Specific Languages in .NET" by Ayende Rahien. Very informative and gently takes you through the process of writing a DSL. The author uses a lightweight .NET language called Boo to serve as basis for the DSL's syntax.
Also you can look into VS2012 corner:
Microsoft Visual Studio 2012 Visualization & Modeling SDK
Microsoft Visual Studio 2010 Visualization & Modeling SDK
There's a bunch of different solutions you could use, including the article you linked, but some other examples from MS...
FsLex/FsYacc - Ports of the popular Lex and Yacc lexer/parsers for F#, but don't be turned off right away. If you've not used it before, F# has a feature called "pattern matching", which allows you to match very complex constructs (such as walking a tree), without an extensive amount of if/else/or blocks all over. This is perfectly suited to language compiling - because almost all DSL solutions you will find will work by parsing the language into an AST (Abstract syntax tree). In this F# solution, you get a strongly typed tree to work with. You can grab the F# Parsed Language Started to get you going. (There's plenty of existing grammars for Lex/Yacc that can help you out too).
SQL Server Modeling Tools (formerly "Oslo") - Contains a language called M, formerly broken into several parts, one being MGrammar. It's quite an advanced parser and can save you plenty of time over other grammars - code patterns (or generic grammar rules) and precedence are built in and easy to use. I would perhaps recommend this if you're starting out with parsing, because it comes with a visual tool - Intellipad, which has a 3-panel DSL mode, where you type in your language and some example code - and it'll show you the output AST as you type - it's quite productive to use. The generated AST is a valid M language constructor (MGraph), which can be used with services like SQL and XML. A downside to MGrammar IMO, is that walking the AST from C# or elsewhere is a tiresome process. There's nothing strongly typed, and you're working with objects and searching with strings - awkward and easy to make mistakes. There's some samples on msdn, and some vids on channel9 which can help you get started like this lengthy overview
The Visualization and Modeling SDK - An entire solution built into VS, which focuses largely on building your with Visual Studio's design tools over code. It comes with a minimum language starter template to help you. Haven't any experience with this to recommend it.
There's plenty of other non-MS solutions, like the one you've mentioned, C# targets for ANTLR etc. These are particularly useful if you're re-using existing grammars - because there's dozens already out there.
You could try JetBrains' MPS. It is a very rich and robust ecosystem for generating DSLs. I've never used it myself, so caveat emptor, but it's free so I guess it can't hurt (much) to give it a go.
Check out my open source project meta#. It sounds like what you are looking for.

Building An App With Plug-in Support

I'm starting a new project which would greatly benefit from program add-ons. The program in its most basic form reads data from a serial port and parses it into database records. Examples of add-ons that could be written would be an auto-archive add-on, an add-on to filter records, etc. I'm writing both the program and the add-ons, but some customers need custom solutions, so instead of branching off and making a completely separate program, add-ons would be great. The simplest add-on would probably be a form who's constructor takes an object reference, manipulates the object in some way, then closes.
Unfortunately, I have absolutely no idea where to start coding, and almost as little idea where to search. Everything I search for turns up browser add-ons. From what I have gathered, I need to look into dynamic loading DLLs. Besides that, I'm clueless. Does anyone have any good resources or examples I that they know of?
I'm happy to provide more details, but this project is in its inception, so I don't have a ton of specific details (specifics kind of defeats the point of add-ons, too.)
You should seriously consider using the Managed Extensibility Framework (MEF) to handle your plugin architecture. It requires thinking about things a little differently, but it is well worth the mind-stretch.
This is a simple example to illustrate the basic technique.
codeproject.com - Plugin Architecture using C#
This article demonstrates to you how
to incorporate ... as a
plugin for another application or use
it as a standalone application.
in .NET 4 you now have the Managed Extensibility Framework (MEF) to do much of the plumbing.
In .NET 3.5 you had the System.AddIn but it was deemed by many to be far too complex.
codeproject.com - AddIn Enabled Applications with System.AddIn
AddIns (sometimes called Plugins) are
seperately compiled components that an
application can locate, load and make
use of at runtime (dynamically). An
application that has been designed to
use AddIns can be enhanced (by
developing more AddIns) without the
need for the orginal application to be
modified or recompiled and tested
You really need to look at Managed Extensibility Framework (MEF). This is specifically designed to help support add-ons and other extensibility.
A very basic description (basically, your plugins must implement a special interface):
http://martinfowler.com/eaaCatalog/plugin.html
Much better article, in C#:
http://www.drdobbs.com/184403942;jsessionid=TVLM2PGYFZZB1QE1GHPCKHWATMY32JVN
I think Reflection will play a major role.
I expirimented with an app that had a plugin folder. A filesystem watcher would watch the folder, and when a new DLL was placed in it, it would use reflection to determine which types of plugins it included, loaded them, and added them to the list of available classes, etc.
Try using the term 'add-in' or 'plug-in' for your research instead of 'add-on'. That should help some.
If you're using .Net 4, there's an add-in namespace in the framework that will get you partway there.
Writing plug-in support for an app is no simple task. You'll have to maintain pretty strict separation-of-concerns across your interfaces, you'll need to provide an interop library that defines ALL of the supported plug-in types, and you'll want to do some research into dependency injection & inversion of control, in addition to the previously-suggested reflection research.
It sounds like you might have a busy weekend doing research.

Ontologies in .NET

I need to make use of some OWL ontologies in c#. Does anyone have a suggestion where I can start? Or if there are any libraries available for .NET please?
Take a look at ROWLEX:
ROWLEX is a powerful open source toolkit for software developers. It has been built to simplify the use of fundamental semantic web technologies (RDF and OWL) under Microsoft’s .NET platform.
Use Protege this is a open source tool of ontology editor and a knowledge acquisition system. It gives a GUI to define ontologies.
You can use RDFSharp on Microsoft Codeplex. It has a semantic extension capable of modeling, validating and reasoning on OWL-DL ontologies.

Categories

Resources