Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running scripts inside C#

Tags:

c#

scripting

I want to run javascript/Python/Ruby inside my application.

I have an application that creates process automatically based on user's definition. The process is generated in C#. I want to enable advanced users to inject script in predefined locations. Those scripts should be run from the C# process. For example, the created process will have some activities and in the middle the script should be run and then the process continues as before. Is there a mechanism to run those scripts from C#?

like image 785
Ragoler Avatar asked Sep 23 '08 07:09

Ragoler


1 Answers

Basically, you have two problems: how to define point of injections in your generated code, and how to run python / ruby / whatev scripts from there.

Depending on how you generate the process, one possible solution would be to add a function to each possible point of injection. The function would check, whether the user has associated any scripts with given points, and if so, runs the script by invoking IronPython / IronRuby (with optionally given parameters).

Disadvantages include: limited accessibility from the scripts to the created process (basically, only variables passed as parameters could be accessed); as well as implementation limits (IronPython's current version omits several basic system functions).

like image 124
Silver Dragon Avatar answered Sep 19 '22 12:09

Silver Dragon