Page 1 of 1

CSE objects

PostPosted: August 6th, 2015, 12:50 am
by Ajay Askoolum
Consider this example:
Code: Select all
     ⎕cse 'LoadAssembly' 'C:\Ajay\C#\VS2012\GEOSPATIAL\GEOSPATIAL\bin\Debug\EntityFramework.dll'
Name=EntityFramework, Version=6.0.0.0, Culture=, PublicKey token=B7-7A-5C-56-19-34-E0-89
     ⎕cse 'ExecStmt' 'using System.Data.Entity;using System.Data.Entity.Spatial;'
0
     ⎕cse 'ExecStmt' 'System.Data.Entity.Spatial.DbGeography thisPoint = System.Data.Entity.Spatial.DbGeography.PointFromText(string.Format("POINT({0} {1})", -121.527200, 45.712113), 4326);'
0
      ⎕cse 'GetValue' 'thisPoint.CoordinateSystemId'
4326
When I query thisPoint, the result appears to be an object:
Code: Select all
      x←⎕cse 'GetValue' 'thisPoint'
      x
43122220
When I use that object to query it properties:
Code: Select all
      ⎕cse 'GetValue' '{0}.CoordinateSystemId' x
CSE ERROR: (1,10): error CS1061: 'int' does not contain a definition for 'CoordinateSystemId' and no extension method 'CoordinateSystemId' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)
      ⎕cse 'GetValue' '{0}.CoordinateSystemId' x
      ^
      ⎕cse 'GetValue' '{0}.CoordinateSystemId' (⎕cse 'GetValue' 'thisPoint')
CSE ERROR: (1,10): error CS1061: 'int' does not contain a definition for 'CoordinateSystemId' and no extension method 'CoordinateSystemId' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)
      ⎕cse 'GetValue' '{0}.CoordinateSystemId' (⎕cse 'GetValue' 'thisPoint')
      ^
Obviously, I can simply execute:
Code: Select all
      ⎕cse 'GetValue' 'thisPoint.CoordinateSystemId'
4326
However, there are objects that have long list of properties and it would be desirable to query them as required.
Is there a way of exposing the properties of a variable/object defined in the CSE context?

Re: CSE objects

PostPosted: August 6th, 2015, 1:24 am
by Davin Church
Just as a wild guess, I'm thinking that this behavior is as designed and is similar in some ways to the long-standing use of objects in []WI. For instance, in your example you say that "x" appears to be a pointer. Well, I think perhaps the terminology is misleading here. What "x" appears to be is an Integer, which contains the value that a pointer to an object would have, but it is not itself an object (or a pointer to one). I think your CoordinateSystemId property must require the object itself in order to work, and not an integer representation of a pointer to that object, and that's why you're seeing the error message complaining about an "int".

To compare this to []WI, if you look at the properties of an ActiveX object you may find that the 'interface' property returns an integer representation of a pointer value but the 'obj' property returns a "pointer" representation of the same value. You must use the type of data that is required by the operation you are trying to perform, and that isn't usually a plain integer.

Re: CSE objects

PostPosted: August 7th, 2015, 12:45 am
by Ajay Askoolum
The CSE example (thisPoint) I used as the basis for my original post has several properties. CSE does not support re-direction (for obvious reasons). Consider a []WI example:
Code: Select all
      ⎕wself←'xl' ⎕wi 'Create' 'Excel.Application'
      ⎕wi 'XWorkbooks.Add' ⍝ watch the integer flow out
67908908
      ⎕wi 'XWorkbooks.Add>xl.wb' ⍝ First option
      'xl.wb' ⎕wi 'Sheets.Count'
1
      'xl.wb' ⎕wi 'Create' (⎕wi 'XWorkbooks.Add') ⍝ Second Option
xl.wb
      'xl.wb' ⎕wi 'Sheets.Count'
1
      ⍝ The integer was an object

Here, when a method or property yields an object, it is possible to use it to query that object's behaviours. My question was: could it be possible for CSE to expose similar facilities via the creation of another object? It is possible to do so with GetValue: but you need to be aware of what properties and methods are available, in advance.
(I know that there are critical differences in the way []wi (in-process) and []cse (out-process) work etc.).

Re: CSE objects and their object model

PostPosted: August 7th, 2015, 4:56 am
by joe_blaze
Ajay: Is there a way of exposing the properties of a variable/object defined in the CSE context?
There are specific CSE methods you may find useful to disclose the object model of a .Net object created in an instance of the CSE.
They are GetEvents, GetMethods and GetProperties.
These are fully documented in the current CSE documentation manual available here: viewtopic.php?f=27&t=1042

For example:

⎕cself←'C'⎕cse 'Init' 'System'

⎕cse 'ExecStmt' 'using System;'
0
⎕cse 'ExecStmt' 'DateTime dt = DateTime.Now;'
0
⍴⎕←⊃⎕cse 'GetMethods' 'dt'
System.DateTime Add(System.TimeSpan value)
System.DateTime AddDays(Double value)
System.DateTime AddHours(Double value)
System.DateTime AddMilliseconds(Double value)
System.DateTime AddMinutes(Double value)
System.DateTime AddMonths(Int32 months)
System.DateTime AddSeconds(Double value)
System.DateTime AddTicks(Int64 value)
System.DateTime AddYears(Int32 value)
System.Int32 CompareTo(System.DateTime value)
System.Int32 CompareTo(System.Object value)
System.Boolean Equals(System.Object value)
System.Boolean Equals(System.DateTime value)
System.String[] GetDateTimeFormats(Char format,System.IFormatProvider provider)
System.String[] GetDateTimeFormats(Char format)
System.String[] GetDateTimeFormats(System.IFormatProvider provider)
System.String[] GetDateTimeFormats()
System.Int32 GetHashCode()
System.Type GetType()
System.TypeCode GetTypeCode()
System.Boolean IsDaylightSavingTime()
System.TimeSpan Subtract(System.DateTime value)
System.DateTime Subtract(System.TimeSpan value)
System.Int64 ToBinary()
System.Int64 ToFileTime()
System.Int64 ToFileTimeUtc()
System.DateTime ToLocalTime()
System.String ToLongDateString()
System.String ToLongTimeString()
System.Double ToOADate()
System.String ToShortDateString()
System.String ToShortTimeString()
System.String ToString()
System.String ToString(System.String format)
System.String ToString(System.IFormatProvider provider)
System.String ToString(System.String format,System.IFormatProvider provider)
System.DateTime ToUniversalTime()
37 79

Re: CSE objects

PostPosted: August 7th, 2015, 5:37 am
by Ajay Askoolum
Brilliant! This will save many round trips into Visual Studio to pick up the same information from its intellisense.

[Apologies for failing to pick this up from the documentation]