1. Aron Cox
  2. PowerBuilder
  3. Tuesday, 21 January 2020 11:44 AM UTC

Sorry I am sure this has been asked before but for some reason I can't find anything useful.

Does PowerBuilder 2019 come with some new and wonderful way of calling C# code, non-visual I think, without having to use COM wrappers, or Web APIs, or any of that annoying stuff. 

I feel like I've read somewhere it does but I can't seem to find anything that actually states that clearly (again maybe my searching skills are just letting me down).

If it does, can anyone point me to any "Getting Started" material?

Thank you!

 

Accepted Answer
René Ullrich Accepted Answer Pending Moderation
  1. Tuesday, 21 January 2020 12:13 PM UTC
  2. PowerBuilder
  3. # Permalink
Comment
  1. Aron Cox
  2. Tuesday, 21 January 2020 13:08 PM UTC
Thanks, looks like a place to start :)
  1. Helpful
  1. Armeen Mazda @Appeon
  2. Tuesday, 21 January 2020 18:07 PM UTC
Please note you need to upgrade to R2 version of PowerBuilder 2019 to get this. The original release from 2019 didn't have this. You can download from https://account.appeon.com/download
  1. Helpful
There are no comments made yet.
Aron Cox Accepted Answer Pending Moderation
  1. Tuesday, 21 January 2020 16:07 PM UTC
  2. PowerBuilder
  3. # 1

Thanks Michael. Ah, so not officially out yet, I guess I'll have to wait a bit then :(

I have written a lot of C# code in a COM wrapped assembly, and it would be nice to get rid of all the COM bits that seem to go wrong every few months and cause me all kinds of problems, and it looks like this could be a solution for that.

I do have a licence so i suppose I could get hold of the beta, but my company hasn;t scheduled any time for me to look at it right now, so I'll hold off for a bit.

 

One question for you as you've been having a play :) Can I return an object with things like strings and ints and arrays in it, or can i only return very simple types?

Comment
  1. Chris Pollach @Appeon
  2. Tuesday, 21 January 2020 16:19 PM UTC
Hi Aron ... Only "simple" PB data types and/or structures with the same simple data elements, in either direction.
  1. Helpful
  1. Michael Kramer
  2. Tuesday, 21 January 2020 16:31 PM UTC
Most simple data types (incl. BLOB!) are fine as pass-by-value/readonly parameters; fewer are fine as return type and pass-by-ref parameters. Arrays of simple types are also fine.

Complex (or structured) types are not supported (I guess similar to COM wrapper). Two options to consider:

1) (my preference) Pass data structure back and forth as JSON strings. Fine support in both PowerScript and C#.

2) Do-it-yourself binary structure and pass it back and fort as PowerScript BLOB = C# byte[ ].

8-10 years ago I did complex data exchange PB <=> C# via COM. We serialized as XML. Now I prefer JSON.
  1. Helpful
  1. Aron Cox
  2. Wednesday, 22 January 2020 05:09 AM UTC
So my current COM wrapped .NET assembly returns things like this:



public class SubSiteCreateResult

{

public SubSiteInfo SubSiteInfo;



public OperationResult OperationResult;



public SubSiteCreateResult()

{

OperationResult = new OperationResult();



SubSiteInfo = new SubSiteInfo();

}

}



Where each class in that class something like this:



public class SubSiteInfo

{

public String ID = "";

public DateTime Created = DateTime.MinValue;

public String MasterUrl = "";

public String ServerRelativeUrl = "";

public String CustomMasterUrl = "";

public String Title = "";

public String Description = "";

public String Url = "";

}



Does that seem possible? (Thanks very much for your insights, very useful).



As you say I could convert it to JSON / XML and then reconvert it on the PowerBuilder side, something I did a while back when making SOAP calls, but since it works fine with COM I wonder if it would with the new way???
  1. Helpful
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Tuesday, 21 January 2020 14:19 PM UTC
  2. PowerBuilder
  3. # 2

Aron, remember new C# interop is part of R2 release so currently in "customer beta" aka. "public beta" though only for customers with valid PB license.

It's pretty cool. There is also a C# Class Importer (Tools > C# Class Importer) in PB IDE that auto-generates a CSharpObject descendant with functions and properties generated.

// C#
public class Gentleman {
    public Gentleman( ) { ... }
    public Gentleman(string firstName, string lastName, string nickName) {...}
    public string Greetings(string name, int attemptCount) { ... }
    public byte[] ConvertToGUID(string guidText) { ... }
}

// Generated in PowerBuilder
// NOTE: byte-array converted to "any". You can assign value directly to a BLOB variable!
nvo_gentleman inherits from nonvisualobject
    string function of_greetings(string as_name, long al_attemptCount)
    any function of_converttoguid(string as_guidtext)

// Using generated proxy.
string ls_text
nvo_gentleman lnv_person
lnv_person = create nvo_gentleman
ls_text = lnv_person.of_greetings("Harald Bluetooth", 3)

Couple of notes:

  • First call auto-loads assembly; creates .NET object from the assembly using param-less constructor.
  • You can customize with a few more code lines, like load assembly using specific .NET Core version (CSharpAssembly.LoadWithNetCore)
  • You can explicitly create new instances using parameterized constructors (CSharpAssembly.CreateInstance)
  • You can catch exceptions from .NET in PowerScript via TRY-CATCH.

I'm tinkering with C# interop as I write this. Trying out where the limits are.

HTH /Michael

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.