2

Is it possible to have an external file which stores some raw code (not C#, possibly something simple like Javascript or VB Script) which contains a number of functions, with arguments containing data from the parent application and catches the return the data back to the C# application. If so, how can it be done?

topherg
  • 4,203
  • 4
  • 37
  • 72
  • You want to run javascript in C# ? – Magnus Dec 12 '11 at 23:03
  • If you want to script things in C#, have you seen LinqPad? – DaveShaw Dec 12 '11 at 23:05
  • 3
    @cgoddard If the stars are aligned, and the proper sacrifice is made, then yes, it can be done. – Matthew Cox Dec 12 '11 at 23:06
  • Yes that is possible. The best way to accomplish that depends on your real goal. If you could describe why you want to do this, you are more likely to get a useful answer. – Eric J. Dec 12 '11 at 23:07
  • 2
    @cgoddard On a more serious note, such questions really warrant some thought as to WHY you would need to before embarking on such an arduous endeavor. – Matthew Cox Dec 12 '11 at 23:07
  • @MatthewCox its so a system can be extended immediately with no down time (10-20 min startup) to add very basic new functionality to the program. Its running on a server with a large number of users connecting simultaneously, I'd have thought the program getting those pieces of code from some script file would have been the best option. – topherg Dec 12 '11 at 23:10
  • @cgoddard Well I suppose if you are okay with sacrifices a decent amount of performance and encorporating a large amount of complexity in order to gain no down time. I am no expert in patching without having to restart but I doubt this is how the pros get it down. – Matthew Cox Dec 12 '11 at 23:13
  • I happen to be working on a C# implementation of V8. Currently only works on 64-bit CPUs though. – bbosak Dec 12 '11 at 23:27

3 Answers3

2

If you want to use a non-CLR language, the simplest way might be using System.Diagnostics.Process to shell out to the executable/interpreter of your choice and parse the stdout from that. You can of course also communicate over more sophisticated mechanisms like named pipes, TCP/IP, HTTP, etc, but that requires writing code on both sides.

There are some on-demand c# 'interpreters' ( http://www.csscript.net/, http://www.codeproject.com/KB/dotnet/nscript.aspx) but I wouldn't recommend them. Mainly because there is no way of knowing what kind of support you are going to get with future versions of .NET.

Chris Shain
  • 50,833
  • 6
  • 93
  • 125
1

If you are looking to create a system that never has down time. I would suggest some alternatives to your idea.

In the end, I don't think your idea is going to pan out. Unless I missed something, at some point when adding new functionality to the raw javascript file, you still need to update C# code to handle the communication to and from that specific section of code. Perhaps you could mitigate this scenario with a lot of xml. BUT, once you start thinking in those terms, you have a TON of IO, marshaling of data, and a maintenance nightmare.

In short, I don't think this is a viable option.

Some alternatives:

Multiple Servers: If you maintain 2 or 3 identical servers, then you could simply shut down one, redirect all your users to your backup, while you update your primary. Once that is done, redirect them back to the primary server and then subsequently update the backup.

Live Patching: Again, I know relatively little about such methods but there are algorithms and approaches for patching dlls live without having to restart. Do some research on this topic because it probably is the most viable option (most of the time people and companies do not just go buy more hardware without a great set of reasons to front the cost).

Matthew Cox
  • 13,566
  • 9
  • 54
  • 72
1

I have written a number of scriptable applications like this. I would recommend IronPython (http://ironpython.codeplex.com/) for starters, along with the instructions at How to use Microsoft.Scripting.Hosting?. There are several languages to choose from... IronPython has suited my needs the best.

Community
  • 1
  • 1
NateTheGreat
  • 2,295
  • 13
  • 9