Home

LinqPad as a business rule engine and management suite (or Shell)

Hi Everyone,

I play with the thought of using LinqPad as a business rule editor/engine.

My reasoning for this is that I like writing/debugging/testing rules within my favorite language and not having to learn some DSL or proprietary language.
I like to be able to edit rules "on the fly" and have them deployed without re-building some library and then deploy them. Editing on the fly headed me into the direction of runtime compilation which is quite easy to setup. But I would need an powerful IDE. This is the point where I finally landed by one of my favourite tools LinqPad.
It would be marvelous if I could write plugins or extensions to LinqPad that would enable me to use it as a full blown rule management suite.

Things that I need to create a management suite
- Rule Repository Browser: Add-In that replaces the "My Queries" (load from repository, save draft, approve, deploy ...)
- Accessing the current query (load, save, edit, run)
- Hooking into the client events (OnSave, OnLoad ...)

Solved bits
- Creating rules as .linq files and executing them from within a windows service is no problem.
- Testing the rules and debugging them with Debugger.Launch and precompiler instructions.
- Adding Extensions and business models via DLLs

This leads me to some questions regarding the current features, api and planned features of LinqPad.

1)

I was wondering if there is a way to access, modify and execute the current query from within an extension. I couldn’t find an answer in the forums.

Something like this:

//load new Query into current query window
LINQPad.Util.CurrentQuery.Load(string filename)

//execute current query
LINQPad.Util.CurrentQuery.Run()

//save current query
LINQPad.Util.CurrentQuery.Save(string filename)

//set new SourceCode for current query window
LINQPad.Util.CurrentQuery.SourceCode = code

//get SourceCode from current query window
code = LINQPad.Util.CurrentQuery.SourceCode

2)

Is there a way to create add-ins? Like a MEF module that has access to the LinqPad client.

I would like to create an add-in that behaves like the “My Queries“ tab with a navigation list that is populated from a database/service with context menu actions.

If there was a way to attach an Extension/Addin to the OnSave event of the client I could even create my own database repository.

3)

Is there a plan to make a LinqPad Shell like the Visual Studio Shell?

This would be my personal dream :-)
- Shell
- MEF Addin-Loader
- UI theming


Thank you for reading my long post and I am looking forward to the discussions :-)

Martin

Comments

  • How often are the rules being executed? What kind of environment? So I assume you are parsing the output of Util.Run's html to figure out if a rule passed?
  • In the scenarios that I have to solve the rules will be mostly used as post-processing rules that trigger further processing events.

    For example after saving a claim or after entering an invoice a rule would be called asynchronously to determine if we have to create reminders or mails. In this case I do not care if the rule would need a couple of seconds to complete as long as I am able to run rules in parallel.

    I will use Json to pass input and output objects between the caller and the rule.

    The environment will be a client-server environment. The client calls an service async (queued) or synced (waiting for the answer; possibly prioritized processing).

    To be honest there will be different kind of rules that pose different challenges. I will make some tests to see how much overhead an speed it will cost to call LinqPad.Util.Run from within a service in comparison to using cached runtime compiled scripts with typed data context.

    My goal is to to be able to write , test and deploy rules fast and with minimal overhead.
  • Interesting idea. I presume that with a rules engine, the purpose of the LINQPad GUI would be to write and test the rules, and another host executable would execute the rules by referencing LINQPad.exe and calling Util.Run?

    As it happens, I'm planning to implement a Util.Compile method soon, which will remove the compilation overhead of calling Util.Run, making this kind of rules engine practical. You will also be able to pass typed parameters to each query, and get a object-typed return value back, avoiding the need to serialize/deserialize to JSON.

    When running rules interactively inside the LINQPad GUI to test them, the parameter values will come from default values, e.g.:
    void Main (string id='foo', int count = 123)
    {
    ...
    }
    For a business rules engine, you could also write a custom data context driver for LINQPad. This is allow allow custom startup/cleanup code to run before/after each query (rule), and give queries a set of typed properties and methods they can use to access the business rules. Or would you want the rules to simply access a database instead?
  • Exactly. One client for writing and testing the rules and a second host that executes the rules.

    Most of the rules will access the database directly. They will be called after the data is persisted to the database.

    I will take a look into the custom driver to get a feeling of what possibilities that gives.

    How will Util.Compile work? Will it generate a compiled dll that you can load in order to execute it?

    Martin
  • Util.Compile is now available in the new beta:
    http://www.linqpad.net/beta.aspx

    For info, see Help | What's new.
Sign In or Register to comment.