scriptengine

Roslyn VisualBasic.ScriptEngine doesnt recognize hostObject written on C#

人走茶凉 提交于 2019-12-05 14:50:26
Our project need ability to have a simple business rules our customers can script in Visual basic. While our main program is written on C# The script which customers want to execut could be like this (I am considering the simpliest possible case) var vbCode = @" If (Row.Code = 12) Then Row.MappedCode = 1 End If"; So I created a RowData class in C# with Code and MappedCode properties namespace ScriptModel { public class RowData { public int Code { get; set; } public int MappedCode { get; set; } } } I created a simple host object class like namespace ScriptModel { public class HostObjectModel {

ScriptEngineManager and ScriptEngine can not be loaded in Karaf OSGi (Nashorn not found)

拈花ヽ惹草 提交于 2019-12-04 23:48:30
问题 I am trying to use ScriptEngineManager and ScriptEngine to execute some JavaScript code with Java. I use Java 8 I am executing this code under Karaf OSGi. The example I used works fine in a sample Java Class, but packing it in a bundle gives me this error ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider jdk.nashorn.api.scripting.NashornScriptEngineFactory not found When I look to the headers of the bundle, I see that the bundle imports javax.script, the package

Effective way to pass JSON between java and javascript

南笙酒味 提交于 2019-12-04 12:30:20
问题 I'm fairly new to Nashorn and scripting on top of the JVM and wanted to know if I can get my java code and javascripts to communicate more effectively. I'm using a 3rd party JS lib that works with JS objects, and in my java code I have the data I want to pass as a Map<String, Object> data . Because that 3rd party JS expects to work with plain JS objects I can't pass my data as is, although the script engine allows you to access a Map as if it was a plain JS object. The script i'm using uses

Roslyn, passing values through hostObject

前提是你 提交于 2019-12-04 10:05:11
I am trying to send one class through hostObject but apparently it doesn't want to work: using Roslyn.Compilers; using Roslyn.Compilers.CSharp; using Roslyn.Scripting; using Roslyn.Scripting.CSharp; public class ShippingService { public class ShippingDetails//class that I want to send { public decimal total { get; set; } public int quantity { get; set; } public string destination { get; set; } } public static string ShipingCost(decimal total, int quantity, string destination) { var details = new ShippingDetails { total = total, quantity = quantity, destination = destination }; try {

parse and execute JS by C#

眉间皱痕 提交于 2019-12-04 06:49:39
问题 i have simple crawler which crawl and search page. but now i have problem how to execute and parse js link from that page. Does anyone have any idea how to parse and execute js page? example: some_url is simple to parse with webhtmltoolktit JAVASCRIPT:runmeat(1,7,0,2,7,9) is js link which redirect then to some_url2 page and this page i need to crawl then. but problem is how to execute this javascript in C# to get that some_url2 link? 回答1: To answer the question title "How to parse and execute

ScriptEngineManager and ScriptEngine can not be loaded in Karaf OSGi (Nashorn not found)

青春壹個敷衍的年華 提交于 2019-12-03 16:37:38
I am trying to use ScriptEngineManager and ScriptEngine to execute some JavaScript code with Java. I use Java 8 I am executing this code under Karaf OSGi. The example I used works fine in a sample Java Class, but packing it in a bundle gives me this error ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider jdk.nashorn.api.scripting.NashornScriptEngineFactory not found When I look to the headers of the bundle, I see that the bundle imports javax.script, the package of the called classes but it seems that (nashorn) the provider is not found. Thanks Go to file etc

Major Performance Issues with Java 8 ScriptEngine Compared to Java 7

扶醉桌前 提交于 2019-12-03 15:41:45
问题 I have a Java program (compiled using JDK 7u80) which makes extensive use of the "JavaScript" ScriptEngine (JSR-223). I have noticed that my program runs extremely slow when executed under a Java 8 runtime environment (JRE 8u65) in comparison to a Java 7 runtime environment (JRE 7u80). I have put together the following SSCCE to demonstrate the problem and then executed it under Java 7 and Java 8 on the same Windows PC: import javax.script.*; public class SSCCE { public SSCCE() {

Effective way to pass JSON between java and javascript

江枫思渺然 提交于 2019-12-03 07:13:01
I'm fairly new to Nashorn and scripting on top of the JVM and wanted to know if I can get my java code and javascripts to communicate more effectively. I'm using a 3rd party JS lib that works with JS objects, and in my java code I have the data I want to pass as a Map<String, Object> data . Because that 3rd party JS expects to work with plain JS objects I can't pass my data as is, although the script engine allows you to access a Map as if it was a plain JS object. The script i'm using uses 'hasOwnProperty' on the data argument and fails when invoked on an Java object. When I tried using

How to check the classpath where Jython ScriptEngine looks for python module?

人盡茶涼 提交于 2019-12-02 14:05:18
问题 I have this Java code which I am using to run a python script using Jython ScriptEngine : StringWriter writer = new StringWriter(); ScriptEngineManager manager = new ScriptEngineManager(); ScriptContext context = new SimpleScriptContext(); context.setWriter(writer); ScriptEngine engine = manager.getEngineByName("python"); engine.eval(new FileReader("/Users/folder1/test.py"), context); In my python script there are several module import statements and when I run the Java code I get error as

How to check the classpath where Jython ScriptEngine looks for python module?

混江龙づ霸主 提交于 2019-12-02 07:06:20
I have this Java code which I am using to run a python script using Jython ScriptEngine : StringWriter writer = new StringWriter(); ScriptEngineManager manager = new ScriptEngineManager(); ScriptContext context = new SimpleScriptContext(); context.setWriter(writer); ScriptEngine engine = manager.getEngineByName("python"); engine.eval(new FileReader("/Users/folder1/test.py"), context); In my python script there are several module import statements and when I run the Java code I get error as javax.script.ScriptException: ImportError: No module named psycopg2 . All the modules are installed in my