Quantcast
Are you the publisher? Claim or contact us about this channel


Embed this content in your HTML

Search

Report adult content:

click to rate:

Account: (login)

More Channels


Showcase


Channel Catalog



Channel Description:

ClearScript is a library that makes it easy to add scripting to your .NET applications. It currently supports JavaScript (via V8 and JScript) and VBScript.

older | 1 | .... | 63 | 64 | (Page 65) | 66 | 67 | .... | 115 | newer

    0 0


    Great Library, really helpful!

    I ran into one situation where we have some existing VBScripts, the have subroutines and functions that take ByRef scalar types such as ints, double and the values are being changed in the function.


    Here is the code I tested:

    VBScriptEngine scriptEngine = new VBScriptEngine(WindowsScriptEngineFlags.EnableDebugging);
    double byRefValue = 10.0;
    scriptEngine.Execute(@"sub TestSub(ByRef MyParam) : MyParam=20.0 : end sub");
    scriptEngine.Script.TestSub(ref byRefValue);


    Basically what I was trying to accomplish , was the double values should end up being set to 20.0 , but it always remains at 10.0

    I tried changing the double to an object and dynamic and it didn't make a difference.

    Any thoughts on how to support this scenario.

    Thanks!

    Comments: Fixed in [Version 5.4.1](https://clearscript.codeplex.com/SourceControl/changeset/c2200cbd6b77300484927906517035caef3ae323).

    0 0

    Hi!
    AddHostObject works very slowly for an object of type Microsoft.Office.Interop.Excel.Workbook.
    ```
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Threading.Tasks;
    using Microsoft.Office.Interop.Excel;

    namespace ClearScriptTest
    {
    class Program
    {
    static void Main(string[] args)
    {
    Application ExcelApplication = null;
    try
    {
    ExcelApplication = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
    }
    catch (COMException)
    {
    Type type = Type.GetTypeFromProgID("Excel.Application");
    ExcelApplication = (Application)System.Activator.CreateInstance(type);
    }
    Workbook ExcelDocument = (Workbook)ExcelApplication.Workbooks.Add();
    Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
    engine.AddHostObject("ExcelObject", ExcelApplication);
    engine.AddHostObject("DocumentObject", ExcelDocument); // Too long
    engine.Execute(@"ExcelObject.ScreenUpdating = True
    ExcelObject.Visible = True");
    }
    }
    }
    ```
    Can you please have a look?
    Thanks!

    0 0

    Hi!
    AddHostObject works very slowly for an object of type Microsoft.Office.Interop.Excel.Workbook.
    ```
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Threading.Tasks;
    using Microsoft.Office.Interop.Excel;

    namespace ClearScriptTest
    {
    class Program
    {
    static void Main(string[] args)
    {
    Application ExcelApplication = null;
    try
    {
    ExcelApplication = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
    }
    catch (COMException)
    {
    Type type = Type.GetTypeFromProgID("Excel.Application");
    ExcelApplication = (Application)System.Activator.CreateInstance(type);
    }
    Workbook ExcelDocument = (Workbook)ExcelApplication.Workbooks.Add();
    Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
    engine.AddHostObject("ExcelObject", ExcelApplication);
    engine.AddHostObject("DocumentObject", ExcelDocument); // Too long
    engine.Execute(@"ExcelObject.ScreenUpdating = True
    ExcelObject.Visible = True");
    }
    }
    }
    ```
    Can you please have a look?
    Thanks!
    Comments: Fixed in [Version 5.4.1](https://clearscript.codeplex.com/SourceControl/changeset/c2200cbd6b77300484927906517035caef3ae323).

    0 0

    the base implantation of DynamicMetaObject just returns an empty string array.

    advise using doing something like what dynamic object does


    ```
    public override IEnumerable<string> GetDynamicMemberNames()
    {
    return scriptItem.GetDynamicMemberNames();
    }
    ```


    test
    ```
    var objWithcolor = engine.Evaluate("x={color:'red'};");
    var dynamicProvider = (IDynamicMetaObjectProvider)objWithcolor;
    var metaObject = dynamicProvider.GetMetaObject(Expression.Constant(dynamicProvider));
    var propNames = metaObject.GetDynamicMemberNames();
    Assert.IsTrue(propNames.Any(name => name == "color"));
    ```

    0 0

    the base implantation of DynamicMetaObject just returns an empty string array.

    advise using doing something like what dynamic object does


    ```
    public override IEnumerable<string> GetDynamicMemberNames()
    {
    return scriptItem.GetDynamicMemberNames();
    }
    ```


    test
    ```
    var objWithcolor = engine.Evaluate("x={color:'red'};");
    var dynamicProvider = (IDynamicMetaObjectProvider)objWithcolor;
    var metaObject = dynamicProvider.GetMetaObject(Expression.Constant(dynamicProvider));
    var propNames = metaObject.GetDynamicMemberNames();
    Assert.IsTrue(propNames.Any(name => name == "color"));
    ```
    Comments: Fixed in [Version 5.4.1](https://clearscript.codeplex.com/SourceControl/changeset/c2200cbd6b77300484927906517035caef3ae323).

    0 0

    HI!
    How to properly add ADODB.Recordset? Is it possible?
    ```
    static void Main(string[] args)
    {
    ADODB.Recordset _recordset = new ADODB.Recordset();
    _recordset.Fields.Append("Id", ADODB.DataTypeEnum.adInteger);
    _recordset.Fields.Append("Name", ADODB.DataTypeEnum.adVarChar, 20);
    _recordset.Open(System.Reflection.Missing.Value
    , System.Reflection.Missing.Value
    , ADODB.CursorTypeEnum.adOpenStatic
    , ADODB.LockTypeEnum.adLockOptimistic, 0);
    _recordset.AddNew(Type.Missing, Type.Missing);
    _recordset.Fields["Name"].Value = "Test";
    Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
    engine.AllowReflection = true;
    engine.AddHostObject("RS", _recordset);
    engine.Execute("RS.MoveFirst"); // Ok
    engine.Execute("RS.Fields(\"Name\").Value = \"Ok\""); // Error
    }
    ```
    Thanks!

    0 0

    HI!
    How to properly add ADODB.Recordset? Is it possible?
    ```
    static void Main(string[] args)
    {
    ADODB.Recordset _recordset = new ADODB.Recordset();
    _recordset.Fields.Append("Id", ADODB.DataTypeEnum.adInteger);
    _recordset.Fields.Append("Name", ADODB.DataTypeEnum.adVarChar, 20);
    _recordset.Open(System.Reflection.Missing.Value
    , System.Reflection.Missing.Value
    , ADODB.CursorTypeEnum.adOpenStatic
    , ADODB.LockTypeEnum.adLockOptimistic, 0);
    _recordset.AddNew(Type.Missing, Type.Missing);
    _recordset.Fields["Name"].Value = "Test";
    Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
    engine.AllowReflection = true;
    engine.AddHostObject("RS", _recordset);
    engine.Execute("RS.MoveFirst"); // Ok
    engine.Execute("RS.Fields(\"Name\").Value = \"Ok\""); // Error
    }
    ```
    Thanks!
    Comments: Fixed in [Version 5.4.1](https://clearscript.codeplex.com/SourceControl/changeset/c2200cbd6b77300484927906517035caef3ae323).

    0 0

    Hello,

    I am evaluating which script technology to embedded in a asp.net app and I am testing ClearScript. I build with success but when I am trying to run ClearScriptBenchmarks test 2 (2. SunSpider - V8 (default)). I got application crash with debug showing Unhandled exception at 0x00007FF9235F635C (v8-x64.dll) in ClearScriptBenchmarks.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

    I am using my dev computer running W8.1 with VS13.

    Is it normal?

    Thanks,
    Eric.

    0 0

    Hello,

    I am evaluating which script technology to embedded in a asp.net app and I am testing ClearScript. I build with success but when I am trying to run ClearScriptBenchmarks test 2 (2. SunSpider - V8 (default)). I got application crash with debug showing Unhandled exception at 0x00007FF9235F635C (v8-x64.dll) in ClearScriptBenchmarks.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

    I am using my dev computer running W8.1 with VS13.

    Is it normal?

    Thanks,
    Eric.
    Comments: Fixed in [Version 5.4.1](https://clearscript.codeplex.com/SourceControl/changeset/c2200cbd6b77300484927906517035caef3ae323).

    0 0

    Hi, I am new to the project and I wanted to change over to ClearScript for my SignalR example BoardGame from a different V8 engine host.

    In my existing sample, there was an "immediate window" that allowed people to type arbitrary script and have it executed against the currently running script engine. That script was:

    var tokens = map.GetTokenList();
    for (var i=0; i<tokens.length; i++)
    {
    tokens[i].X=50i; tokens[i].Y=50i;
    }

    map refers to a hosted object. GetTokenList is a public method on that instance that returns (currently) a Token[]. So a .NET array was returned. I guess the previous engine was converting that to a JavaScript array, because as you can see the length of the array is accessed via "length", the JavaScript array method for counting the contents.

    I struggled getting the exact same code to work when I replaced the engine with ClearScript. But then I figured out that, in this context, tokens was really a .NET array and hadn't been converted, so simply changing the lowercase l to an uppercase L worked, as in:

    var tokens = map.GetTokenList();
    for (var i=0; i<tokens.Length; i++)
    {
    tokens[i].X=50i; tokens[i].Y=50i;
    }

    Not that I am saying this code or sample is ideal, but I was curious if there is a way in the engine to instantiate V8 types (JavaScript types). In other words, could my .NET code instantiate a JavaScript array and return it from a .NET method call. I'm guessing the other engine just does that somehow.

    I looked at the FAQ and saw a section on creating arrays from script using the HostFunctions object, but I don't think that is quite what I am going for. I want to be able to return a native JavaScipt array from the host.

    It's also possible there is some disconnect between the project and the NuGet package. I used the following to import ClearScript anf get going: Install-Package ClearScript.V8

    And it installed and reported: "Successfully added 'ClearScript.V8 5.3.10.0' to GameServer."

    Thanks for any insight,
    Chris

    0 0

    Hi Chris,

    First, consider upgrading to the latest version of ClearScript (currently 5.4.1). We recommend that you build it from the source code as outlined in the ReadMe.

    Second, you've determined correctly that ClearScript prefers to make host objects scriptable rather than convert them to script objects. However, it also aims to make it easy to manipulate script objects from the host. Here's a sample that defines an extension method for converting host arrays to script arrays:
    publicstaticclass ScriptHelpers {
        publicstaticobject ToScriptArray<T>(this T[] array) {
            dynamic scriptArray = ScriptEngine.Current.Evaluate("[]");
            foreach (var element in array) {
                scriptArray.push(element);
            }
            return scriptArray;
        }
    }
    Note that ScriptEngine.Current is new in ClearScript 5.4.1. With an older version you'd have to pass the engine instance into the conversion method (or use some other technique).

    Good luck!

    0 0

    Thank you for this detailed answer. I'll see if I can get the current version building.

    0 0

    Hello,
    I was able to get this working with a basic example. Then I tried to tweak it to suit my particular needs but I am not having any luck. Technically, I don't specifically need to have the setTimeout function. Instead, any function will do the trick that provides a delayed callback into the script. Also, I don't need the periodic feature as long as I can repeate the delayed function a few times. In my application, the user will be creating counters and when the counter gets to say 5 or 10, they will stop counting until some other event fires to start the counting again. This can be done either with the periodic function or with a delay where the called back function calls the delay again each time until the target value is reached. I prefer the delay in case the user messes up and does not stop the periodic timer - it just seems a little safer.


    The trick for me is that I want to do this in a JS class that will be instantiated a hundred times. Each class has its own timer that it uses for counting against its instance data. I tried using setTimeout based upon the solution above and passed this.Run as the callback function. It seemed to me that this lost its context because setTimeout was created in global scope. I'm not all that solid with JavaScript classes and context so I'm not really sure why this didn't work. At one point through my attempted tweaks, I called this.Run on one instance and it ran on all instances. My code looks something like this.
    var DVC = function(tag) {
      this.Tag = tag;
      this.timerTarget = 5;
      this.count = 0;
      var _start = false;
      Object.defineProperty(this, 'start', {
        get: function() { return _start; },
        set: function(value) {
                 this._start = value;
                 if (value === true) { setTimeout(this.Run, 1000);}
               }
      });
    
      this.Run = function() {
        if (this.count >= this.timerTarget) {
          //do something ...
        }else{
          this.count++;
          setTimeout(this.Run, 1000);
        }
      };
    };
    
    var x = new DVC("YV-101");
    var y = new DVC("YV-201");
    
    function calledByUser() {
      x.start = true;
    }
    
    function someOtherFunction(){
      y.start = true;
    }
    Any suggestions?

    0 0

    Hello!

    The problem seems to be that you aren't binding your Run function to a DVC instance. Consider defining it as follows:
    var DVC = function(tag) {
      //...this.Run = this.RunMethod.bind(this);
    };
    DVC.prototype.RunMethod = function() {
      //...
    };
    Good luck!

    0 0

    I have the following script:
     string script = @"function1(a) { }  function2(b) { function1(b); }"
    
    and the following C# code:
     engine.Execute(script);
     engine.Script.function1("blah");
    
    I'm getting an exception on the engine.Script "function1 is not defined". What am I doing wrong?

    0 0

    Oops, I had a typo in the script. After fixing the typo it works.

    0 0

    Getting the following exception when running my Azure Mobile Service:
     Exception=System.TypeLoadException: Cannot load V8 interface assembly. Load failure         information for v8-ia32.dll:
     C:\DWASFiles\Sites\mobile$Service\Temporary ASP.NET      Files\root\1aa0fcb8\40098f63\assembly\dl3\c1d3aac4\014f7f98_0b52d001\v8-ia32.dll: The      specified module could not be found
     MobileServicesDotNet\1.0.450\v8-ia32.dll: The specified module could not be found
     MobileServicesDotNet\1.0.450\bin\v8-ia32.dll: The specified module could not be found
    
    However, the dll is in included in the project root with options set to Content and do not copy local as I used the Clearscript Installer NuGet. Is this a case of not having the VC++ redistributables installed on the server? Is there anyway I can include the necessary redistributables so they are on the server when I deploy?

    0 0

    Hello AEONSoft,

    At first glance this doesn't look like a case of missing VC++ libraries; "The specified module could not be found" indicates that v8-ia32.dll itself is missing.

    Can you connect to the Azure instance remotely? If so, you should be able to examine the deployment folder and determine whether v8-ia32.dll is installed, and where. If you can do this, please post your findings.

    Thanks!

    0 0

    That did the trick. I understand the bind method in an abstract sense but without an understanding of how JS handles and changes context its difficult to know when to use it. Your answer prompted me to do a little testing to observe when and how the context changes so I think I understand it better. I assumed that calling a class instance method should have the instance as the current context but in fact it appears to pass the context of the caller by default. I was calling the instance method from the global scope in some cases and from within another object instance in other cases. The bind method fixed those problems.

    I know this is technically not really a ClearScript issue - its a lack of understanding JavaScript on my part so I am doubly thankful for your help. My classes are awesome now.

    Thanks again!

    0 0

    v8-ia32.dll is installed in:

    d:\home\site\wwwroot

older | 1 | .... | 63 | 64 | (Page 65) | 66 | 67 | .... | 115 | newer