Quantcast
Channel: ClearScript
Viewing all 2297 articles
Browse latest View live

Commented Unassigned: Exporting array of Number from V8. [53]

$
0
0
Hi again, guys.

There is some way to export a array of Number ([1,2]) from JS evaluation to C# array of integer?

The JS code is:
```
(function (data){ return new RuleExecutionResult(data.BodyFat > 2 && data.Weight > 85, new CLRArray(1,2)) })(data)
```

RuleExecutionResult constructor is:

```
public WorkoutTemplateAssociatedData(bool isValid, int[] associatedObjectiveIds)
```

But ClearScript can't find it because "associatedObjectiveIds" is being binded to a dynamic (as you can see in the attached file), while isValid is correcly binded as true.



Comments: Hello! This behavior is by design. ClearScript doesn't convert arrays (or most other types) automatically. In general it favors full host and script object access over data conversion. Because host and script objects (even simple collections such as arrays) behave very differently, automatic conversion can be ambiguous and problematic. Full access allows hosts to provide their own conversions that fit their needs. Here's an example of a host-provided array conversion function: ``` C# // C# engine.Script.toIntArray = new Func<dynamic, int[]>(scriptArray => { var length = scriptArray.length; var intArray = new int[length]; for (var i = 0; i < length; i++) intArray[i] = scriptArray[i]; return intArray; }); ``` And here's how you might use it from script code: ``` JavaScript // JavaScript someHostObject.ProcessData(toIntArray([9,8,7,6,5])); ``` Please send any further questions or concerns. Good luck!

Edited Unassigned: Exporting array of Number from V8. [53]

$
0
0
Hi again, guys.

There is some way to export a array of Number ([1,2]) from JS evaluation to C# array of integer?

The JS code is:
```
(function (data){ return new RuleExecutionResult(data.BodyFat > 2 && data.Weight > 85, [1,2]) })(data)
```

RuleExecutionResult constructor is:

```
public WorkoutTemplateAssociatedData(bool isValid, int[] associatedObjectiveIds)
```

But ClearScript can't find it because "associatedObjectiveIds" is being binded to a dynamic (as you can see in the attached file), while isValid is correcly binded as true.



New Post: How to call service method within same class

$
0
0
Hi
I can successfully run a script, however I want to call another service via a hostfunction.
the hostfunction works within C# since it instantiates a proxy dll and reads config from web.config... but I suspect one cannot do this via clearscript?

New Post: How to call service method within same class

$
0
0
Hello!

We're a bit unclear about what you mean by "hostfunction".

There are exceptions, but if you can do it in C#, you should be able to do it in script code as long as you've exposed the relevant .NET types and/or objects to the script engine. Can you provide a sample that does in C# what you'd like to do in script code?

Thanks!

New Post: How to call service method within same class

$
0
0
Hi

Ok this is the script code ...
            using (var engine = new  JScriptEngine())
            {
                engine.AddHostObject("host", new RFManagerService());

                StringBuilder script = new StringBuilder();
                script.Append("function DoWork() {return host.GetCustomerInternal('ContractNo', '15405844');}");
                
                engine.Execute(script.ToString());
                result = engine.Script.DoWork();
            }
now this script is called in a function in a class that also contains the following method ... this method works from other C# code in the same class, but not from script?
        public Customer GetCustomerInternal(string searchBy, string searchVal)
        {
            string validationMsg = string.Empty;
            //return null;
            return GetCustomer(searchBy, searchVal, out validationMsg);
        }

        public Customer GetCustomer(string searchBy, string searchValue, out string validationMsg)
        {
            RFWellnessEngineProxy wellnessEngineProxy = null;

            Customer customer = null;
            validationMsg = string.Empty;

            try
            {
                wellnessEngineProxy = new RFWellnessEngineProxy();
                if (searchBy.Equals("ContractNo") || searchBy.Equals("Contract_No"))
                {
                    customer = wellnessEngineProxy.GetCustomerByContractNo(int.Parse(searchValue), out validationMsg);
                }

                return customer;
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            finally
            {
                //Close proxy(ies)
                CloseProxy(wellnessEngineProxy);
            }
            return customer;
        }

New Post: How to call service method within same class

$
0
0
Hi again,

Thanks for posting the code.

There doesn't appear to be anything wrong here. Your script calls a public method of an exposed object. What are you seeing? Does the script engine throw an exception?

Thanks!

New Post: How to call service method within same class

New Post: How to call service method within same class

$
0
0
here is a link to prove that the method does work when called directly ...
this i did just before the script attempt, and it does return a customer object. script generates socket timeouts but i do not know why

http://1drv.ms/1sCeG3t

New Post: How to call service method within same class

$
0
0
Hi iwcoetzer,

At first glance socket timeouts would appear to be completely unrelated to script execution. On the other hand, you're using JScript, which is a COM component, so it may share infrastructure with WCF or one of its dependencies.

Can you post a stack trace for the innermost (first-chance) exception you're seeing?

Also, what does your setup look like? Is the service running on the same machine? What protocols or bindings are you using?

Thanks!

New Post: How to call service method within same class

$
0
0
Hi. services are currently all hosted on my dev box. will post innerexception when I am back behind my laptop thanks. would be nice if I can get this to work. I want the script to call that method for input parameters so that on can change the script in future to call other functions as need may arise.

Commented Feature: Throw specific script exception by host [43]

$
0
0
Hi,

Would it be possible to add a custom exception, so that when it is thrown by host it throws a script exception of the specified type and message.

For example, in host code:

```
throw new CustomScriptException("RangeError", "custom message");
```

will cause script to execute:

```
throw new RangeError('custom message');
```

Specifically, for the example above I need the exception to be instanceof RangeError.

Thanks again in advance,
Ron


Comments: I have tried this method, however I can only seem to get generic ScriptEngineExceptions with the message set to "Exception has been thrown by the target of an invocation". Any ideas how I could get the original exception from the tryCatch exception handler?

Commented Feature: Throw specific script exception by host [43]

$
0
0
Hi,

Would it be possible to add a custom exception, so that when it is thrown by host it throws a script exception of the specified type and message.

For example, in host code:

```
throw new CustomScriptException("RangeError", "custom message");
```

will cause script to execute:

```
throw new RangeError('custom message');
```

Specifically, for the example above I need the exception to be instanceof RangeError.

Thanks again in advance,
Ron


Comments: Hello! ClearScript uses exception chaining to preserve as much error information as possible. You should be able to use [`InnerException`](http://msdn.microsoft.com/en-us/library/system.exception.innerexception(v=vs.110).aspx) and/or [`GetBaseException()`](http://msdn.microsoft.com/en-us/library/system.exception.innerexception(v=vs.110).aspx) to traverse the exception chain. Good luck!

Created Unassigned: Are multiline strings possible? [54]

$
0
0
I would like to use ClearScript to compile handlebarsjs templates. Handlebars templates can be full html documents that as far as I know there's no good way to build up in js alone ( they have to be passed in via an API or grabbed via an ajax download or `elment.innerHTML`).

Is there a way in ClearScript where I can inject a multiline string containing a document into a variable or am I barking up the wrong tree?

New Post: Are multiline strings possible?

$
0
0
Togakangaroo wrote:

I would like to use ClearScript to compile handlebarsjs templates. Handlebars templates can be full html documents that as far as I know there's no good way to build up in js alone ( they have to be passed in via an API or grabbed via an ajax download or elment.innerHTML).

Is there a way in ClearScript where I can inject a multiline string containing a document into a variable or am I barking up the wrong tree?

Sure, the host can pass any string to a script function:
// C#string document = GetOrCreateDocument();
engine.Script.processDocument(document);
... or store the string as a property in a script object (the global object in this case):
// C#
engine.Script.document = document;
There are no restrictions on string size or contents.

Good luck!

Closed Unassigned: Are multiline strings possible? [54]

$
0
0
I would like to use ClearScript to compile handlebarsjs templates. Handlebars templates can be full html documents that as far as I know there's no good way to build up in js alone ( they have to be passed in via an API or grabbed via an ajax download or `elment.innerHTML`).

Is there a way in ClearScript where I can inject a multiline string containing a document into a variable or am I barking up the wrong tree?
Comments: Moved to a [discussion topic](https://clearscript.codeplex.com/discussions/568385). Please use the [Discussions](https://clearscript.codeplex.com/discussions) area for questions. Thanks!

Edited Unassigned: Are multiline strings possible? [54]

$
0
0
I would like to use ClearScript to compile handlebarsjs templates. Handlebars templates can be full html documents that as far as I know there's no good way to build up in js alone ( they have to be passed in via an API or grabbed via an ajax download or `elment.innerHTML`).

Is there a way in ClearScript where I can inject a multiline string containing a document into a variable or am I barking up the wrong tree?

Edited Issue: Exporting array of Number from V8. [53]

$
0
0
Hi again, guys.

There is some way to export a array of Number ([1,2]) from JS evaluation to C# array of integer?

The JS code is:
```
(function (data){ return new RuleExecutionResult(data.BodyFat > 2 && data.Weight > 85, [1,2]) })(data)
```

RuleExecutionResult constructor is:

```
public WorkoutTemplateAssociatedData(bool isValid, int[] associatedObjectiveIds)
```

But ClearScript can't find it because "associatedObjectiveIds" is being binded to a dynamic (as you can see in the attached file), while isValid is correcly binded as true.



Commented Issue: Exporting array of Number from V8. [53]

$
0
0
Hi again, guys.

There is some way to export a array of Number ([1,2]) from JS evaluation to C# array of integer?

The JS code is:
```
(function (data){ return new RuleExecutionResult(data.BodyFat > 2 && data.Weight > 85, [1,2]) })(data)
```

RuleExecutionResult constructor is:

```
public WorkoutTemplateAssociatedData(bool isValid, int[] associatedObjectiveIds)
```

But ClearScript can't find it because "associatedObjectiveIds" is being binded to a dynamic (as you can see in the attached file), while isValid is correcly binded as true.



Comments: The behavior is by design, and marcusnaweb hasn't commented in 10 days. Marking as resolved.

New Post: Are multiline strings possible?

$
0
0
oooh man. That's awesome.

Another question, does Clearscript not provide the JSON object to stringify?

New Post: Does ClearScript have memory leak?

$
0
0
I wrote a simple application, which exposed a custom type (i.e. Foo) to outside. So the user could invoke it's method like this:
var val1 = new Foo();
Console.WriteLine(val1.Method());
From the memory detecting tool, I found the memory increased a lot after each time I ran this simple script. It seems a lot of Microsoft.ClearScript.HostItem objects exists in memory, and never gone away.

So I am quite worried about this, if a lot of users would create instance of Foo, it would consume very a lot of memories, which seems terrible.

Any thoughts over this problem?
Viewing all 2297 articles
Browse latest View live




Latest Images