EzDevInfo.com

IronJS

IronJS - A JavaScript implementation for .NET IronJS Blog | All things IronJS and F# all things ironjs and f# (by fredrik holmström)

Anyone using IronJS yet?

I'm just wondering if there is anyone else using IronJS within their apps yet?

IronJS is really awesome as it's JavaScript on the DLR. Personally, I've been waiting to be able to write both server-side and client-side code in ASP.NET / ASP.NET MVC using JavaScript. It's too bad Microsoft abandoned Managed JScript, but no worries since IronJS is really showing promise.

I am wondering if anyone has started using it in any of their apps yet?

Lately, I've been playing around a little bit with adding the ability to code ASP.NET MVC Controller Actions in JavaScript using IronJS.


Source: (StackOverflow)

How to invoke a function written in a javascript file from C# using IronJS

I just download the Iron JS and after doing some 2/3 simple programs using the Execute method, I am looking into the ExecuteFile method.

I have a Test.js file whose content is as under

function Add(a,b)
{
    var result = a+b;
    return result;
}

I want to invoke the same from C# using Iron JS. How can I do so? My code so far

var o = new IronJS.Hosting.CSharp.Context();
dynamic loadFile = o.ExecuteFile(@"d:\test.js");
var result = loadFile.Add(10, 20);

But loadfile variable is null (path is correct)..

How to invoke JS function ,please help... Also searching in google yielded no help.

Thanks


Source: (StackOverflow)

Advertisements

Can't use the .length property with IronJS and ArrayObject

I am using IronJs's latest version (0.2.0.1) and my js scripts do not properly retrieve the length of an array that has been set to the js engine using an IronJs.Runtime.ArrayObject. However, my variable is well recognized as an array, as shown in C# code below.

var jsCode = @"myArray.length;";
var javascriptEngine = new IronJS.Hosting.CSharp.Context();
var array = new ArrayObject(javascriptEngine.Environment, 2);//array of size 2
array.Put(0, 12.0);//mock values
array.Put(1, 45.1);

javascriptEngine.SetGlobal<ArrayObject>("myArray", array);

var result = javascriptEngine.Execute(jsCode);
Console.WriteLine(result);

var jsCode2 = @"myArray instanceof Array;";
var result2 = javascriptEngine.Execute<bool>(jsCode2);
Console.WriteLine(result2);

We get the following output

undefined
True

Source: (StackOverflow)

IronJS CommonObject, are dynamic properties possible?

In IronJS, we have a custom object derived from CommonObject. We're wanting to intercept calls to undefined properties on the object, and provide dynamic responses. (This is required, as it is not possible in our situation to preregister all the properties.)

We can capture function calls on this object by overriding the BoxedValue Get(string name) function, and provide functions "on the fly" without preregistering them on the object.

We're hoping we can do the same with properties, but none of the overrides seem to be able to handle this. I'm hoping that someone has enough experience with IronJS to suggest how we can better approach this.

Hopefully this clarifies what we're trying to achieve:

IronJS.Hosting.CSharp.Context ctx = new IronJS.Hosting.CSharp.Context();
ctx.SetGlobal("data", new MyCustomObject());
string script = @"var x = data.mydynamicproperty;";
ctx.Execute(script);

When the script executes, we are wanting to be able to override and return a custom value. For example (on the MyCustomObject class declaration):

public override BoxedValue Get(string name) {
    if (name == "mydynamicproperty") {
        return BoxedValue.Box("test");
    }
}

The above override is called for functions (e.g. var x = data.mydynamicfunction();) but not for properties.

Any help or suggestions would be greatly appreciated.


Source: (StackOverflow)

IronJS / Twilio Browser Soft Phone

I'm creating a Fiddler extension that is simplifying my interaction with Twilio during development. I'm about to release it to the wild, but I would like one more feature before I do so.

I'm able to return the various phone numbers on my Twilio Account, and list them with the various URLS that are required.

I would like to select on of the numbers, and "Click-To-Test" whick will dial the selected phone number. I would then like to interact with my Twilio service via my computer rather than picking up a phone.. I should be able listen to the voice prompts, and interact by dialing 1, 2, 3 etc. when prompted.

Twilio offers this JavaScript library here (Twilio in the Browser), and give an example here via Azure (Twilio in Javascript Application), or here via MVC (Hello Monkey Client)

All of which leverage a Javascript library which creates a Twilio Device on the client side. I'm NOT a Javascript guy (yet, but it looks like that's next on my every growing learn-this-technology list), but I have to think that the same functionality could be implmented in C#.

I've attempted to host the device in a browser control, but I'm not getting to far with it, and the integration still remains on how to pass a select item in C# to a executing Java Script library running in a browser.

I've also looked into IronJS run the JavaScript via the Dynamic Run Time, but I'm not sure if that will work in the end. The Twilio Library looks for a script tag in the web page, and hooks up several event handlers. Running the library in IronJS, causes it to fail as there is no web page, and my Java chops are not up to hacking this piece out.

My question is: Can't this Javascript Library be ported to C#, and create a full client that Twilio sees like the Javascript soft phone? I would think this would not only be helpful for me, but also for Win 8 dev, and Windows Phone 8 Dev as well.


Source: (StackOverflow)

ironjs: returning objects to JS

Using Ironjs. I have a c# function registered as a JS function (via SetGlobal)

It gets called , but I want to return a value to from that function. The value is an IEnumerable of CLR objects. Using Jint this just works: I return the object and can foreach it etc, how do I do the same thing in IronJS (Why not use Jint, well it has bugs, for example it wont compile underscore.js)

EDIT: Since I am not a fluent F# person I cannot answer this question myself by reading the code. So instead I fixed Jint. However it would still be nice to know the answer


Source: (StackOverflow)

IronJS: How to parse JSON(send as string parameter) to a method in JavaScript function

I am new to IronJS and facing difficulty parsing JSON in JavaScript method.

My C# Code

string jsonString = "{\"Name\": \"Ankur\", \"Sex\": \"Male\"}";
var o = new IronJS.Hosting.CSharp.Context();
o.ExecuteFile(@"C:\CustomScript.js");
var handleJson = o.Globals.GetT<FunctionObject>("HandleJson");
var result = handleJson.Call(o.Globals, jsonString).Unbox<string>();
Console.WriteLine(result);

JavaScript method in CustomScript.js

function HandleJson(jsonStr) {
obj = JSON.parse(jsonStr);
return obj.Name;
}

Everytime I do this, I get error message saying "ReferenceError: JSON is not defined"

Guess, "JSON.parse" method is native to browser and which isn't available server side. I can use jQuery method obj = $.parseJSON(jsonStr); as well but don't know how to load jQuery file.

Any thoughts on what I am doing wrong or how to fix it?

Thanks.


Source: (StackOverflow)

Predefined type CallSite is defined in multiple locations

I get errors from both build and website precompile on App Harbor that seem to originate from multiple versions of the C# dynamic assemblies. They both start with warnings that look like:

2>CSC : warning CS1685: The predefined type 'System.Runtime.CompilerServices.CallSite' is defined in multiple assemblies in the global alias; using definition from 'd:\temp\qb3ydb5o.xoq\input\packages\IronJS.Core.0.2.0.1\lib\net40\Microsoft.Scripting.Core.dll' [D:\temp\qb3ydb5o.xoq\input\...csproj]

The build passes, but website precompile has these warnings but fails:

(0): error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember'
d:\temp\qb3ydb5o.xoq\output\_PublishedWebsites\...cshtml(4): error CS1969: One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?

I wonder if it has anything to do with how IronJS is packaged? Can someone help me troubleshoot this error?


Source: (StackOverflow)

Information about IronJS

Can any one point out as where can I get some tutorials about IronJS and how to call a method written in IronJS from C# 4.0

Thanks

C#4.0, IronJS


Source: (StackOverflow)