4

There is a need to have a calculator for our invoices which will be used both in the web UI and in the back-end. This requires two implementations of the same logic in Javascript and C# and the real problem is to keep these two logics in sync when it comes to changing the rules.

At the moment, what we do in the JS side is that we send all the requests for recalculations to the backend through ajax calls in order to use the calculator implemented in C#. This keeps our servers busy and I don't like the idea. I think that there should be a rule engine or something somewhere that we could utilise to keep the calculation logic in a language other than C# or JS and use/interpret it in both the front-end and the back-end.

Has anyone else faced the same problem? Any idea would be appreciated.

Mehrad Sadegh
  • 1,104
  • 10
  • 25
  • 2
    It looks like you'll need to write/find an interpreter for a data format which can be shared across both _C#_ and _JavaScript_ which can describe what actions you want (probably _String_), then define all of your logic in that shared data format, so both implementations can access the same thing. – Paul S. Aug 30 '13 at 01:34
  • 1
    This similar question lists a nice overview: http://stackoverflow.com/questions/16434389/javascript-and-c-sharp-cross-compiling-and-conversion – Dejan Dec 26 '13 at 14:07

3 Answers3

1

You can try using Haxe to implement your rule engine and then cross-compile it to JavaScript and C#. This would give you a common implementation base for both and then - during compilation - your two different language outputs would be formed.

Disclaimer: I haven't used Haxe yet so I can't testify if it'd work for your situation but it supports both languages as targets.

xxbbcc
  • 16,930
  • 5
  • 50
  • 83
1

Faced the same problem and solved it by implementing the logic in javascript and then run it with https://jurassic.codeplex.com/ on the server. Works nicely.

citykid
  • 9,916
  • 10
  • 55
  • 91
  • 1
    Thanks for that. I found few other alternatives on http://stackoverflow.com/questions/16434389/javascript-and-c-sharp-cross-compiling-and-conversion and http://stackoverflow.com/questions/172753/embedding-javascript-engine-into-net-c – Mehrad Sadegh Sep 25 '13 at 03:57
  • 1
    Thanks for that in turn. I worked with ScriptSharp years ago and it was great. Its development stopped some day, but might have taken off again. Would like to hear about your final choice. – citykid Sep 25 '13 at 08:03
  • 1
    I know, but apparently I don't have enough "reputation" to +1 it – Mehrad Sadegh Dec 11 '13 at 02:26
0

You can use any decision-as-a-service platform. They usually expose decisions(bunch of connected business rules with relations and dependencies) as a REST API service. So you can simply interact with the service for execution and management of rules.

For example here is a sample how you can communicate with decision service for execution by passing input parameter values in JavaScript.

Arash Aghlara
  • 330
  • 3
  • 11