|By Yakov Werde||
|March 16, 2012 12:45 PM EDT||
This two-part series examines and contrasts PowerBuilder .NET 12.5.1's new dynamic assembly feature with corresponding dynamic library functionality in PowerBuilder Classic. The discourse is presented in the context of a simplified yet practical use case. Part 1 presented the use case, reviewed pertinent PowerBuilder Classic dynamic APIs and presented a Classic PBD implementation. Part 2 introduces PowerBuilder .NET 12.5.1's Dynamic Assembly feature, reveals relevant PowerBuilder .NET generated assembly internals, and presents a PowerBuilder .NET use case implementation. Along the way it explores PowerBuilder assembly internals.
My initial attack plan when exploring version 12.5.1's dynamic assembly function capabilities was to envision a use case where library functions are used to reflect on an assembly to discover its contents and then extract and instantiate class definitions. I am so used to writing dynamic Classic PowerScript code using Library functions to get lists of objects in a PBD and dynamically creating them that I naively assumed that the .NET Library methods were equivalent to their Classic counterparts. Wrong! As you'll soon see, my journey took me spelunking deep into the cavities of PowerBuilder .NET assemblies. Lucky for me I got the treasure at the bottom of the cave and was able find my way back out. Read on!
PowerScript Dynamic Assembly API
In the .NET world, a PBLX is the file-based equivalent of a PBL that you access under the control of the PowerBuilder library API. Just like the PBL, a PBLX has a library directory with managed access to the directory's contents. Pertinent to our discussion, the functions CreateLibrary, DeleteLibrary, LibraryDirectory, LibraryDirectoryEx, LibraryImport and LibraryExport all work as advertised in their Classic form when called in .NET. The sole difference is that they operate on a PBLX or its contents.
Remember that in Classic, a PBD is basically a PBL sans source code. In addition to their important role as runtime libraries, you can add PBDs to an application library list, and create or inherit from their code objects as if they were inside PBLs. The nice thing about runtime libraries in Classic is that with proper forethought you can turn any library on your library list into a standalone PBD that you can use within any application.
Things are a bit different in the .NET world where the PBD has gone the way of the wooly mammoth. There is no such thing as PBD generation nor are PBDs reference-able on a .NET application. The replacement technology is the PowerBuilder .NET Assembly.
To generate a standalone PB .NET Assembly use the IDE to create a PB Assembly Target to which you add the libraries containing code objects you want in your Assembly. Use the Project painter to generate the target's contents as a freestanding DLL. However, since the libraries are generated as DLLs you cannot add them to your library list. You must add them as referenced assemblies on your PowerBuilder application. Once reference-able, you can create or inherit from their code objects just as if they were inside your PBLs.
As mentioned, a PBLX is the file-based equivalent of a PBL; both are accessed by the IDE under the control of the PowerBuilder library API. However, since a PowerBuilder .NET Assembly has no structural relationship to a PBD, the Classic PBL/PBD-centric library functions AddToLibraryList, SetLibraryList and GetLibrary are obsolete in .NET. Sadly for those migrating a Classic application containing these functions, there are no migration or PBCS compiler warning messages; the functions just do nothing at runtime. Worse yet was that there was no functional replacement in the PowerBuilder .NET world; that is until the release of version 12.5.1. This version brings relief to those whose applications rely on adding classes at runtime. Three PowerBuilder Assembly oriented replacement functions were added: AddAssemblyReference, SetAssemblyReference and GetAssemblyReference. These functions are operationally equivalent to their Classic counterparts with the exception that they operate on PowerBuilder assemblies instead of PowerBuilder dynamic libraries. Once a PowerBuilder Assembly is added to the assembly reference list, its contents are fully available to the runtime. Any global function, PowerObject type class or DataWindow object can be created or referenced in code. Of course, since the code objects are not present at build time, you will need to create them using one of the dynamic open or Create methods I illustrated in the first article in this series.
The Missing Link
Table 1 shows differences and similarities between Classic and Dot Net Library Functions.
Table 1: Library function comparison chart
.NET Function & Variations
Adds files to the library search path of the application
Gets the files in the library search path of the application
Create a library and add comments to it
Creates a PBL folder*
Delete a library
Deletes the PBL folder *
Returns a list containing all the objects of a specified type in BOTH PBL & PBD
Only works for PBLX
Doesn't work on Assy!!
PBL & PBD
Returns a list containing all the objects in a library in BOTH PBL & PBD
Only works for PBLX
Doesn't work on Assy!!
Exports an object -from- a specified PBL to a string
Works for PBLX
Imports an object -into- a specified PBL from a string
Works for PBLX
Changes the files in the library search path of the application
Note that there is just one omission: LibraryDirectory and LibraryDirectoryEx are not implemented to return the contents of a referenced PowerBuilder assembly. Similar to AddToLibraryList a call to LibraryDirectoryEx does not generate a compiler warning and does not return a runtime response. Unfortunately for us, runtime Assembly directory functionality is a crucial aspect of our snap-in loader architecture. What to do?
Into the Cave: PowerBuilder Assembly Internals
At this point, I realized that I would have to write my own PowerBuilder Assembly directory functionality. Lucky for us PowerBuilder .NET is a CLR compliant language; I had a full arsenal of .NET 4.0 Framework classes and the strength of the great .NET disassembly tool, Red Gate Software's .NET Reflector. What I needed to do was generate a PowerBuilder Assembly with all kinds of things inside it, use Reflector to learn where things were put and how they were structured, and then use .NET Reflection API calls to get a directory of them at runtime. Once I had the directory of names, I'd let PowerBuilder .NET do its standard magic to dynamically create them at runtime.
I created a PowerBuilder .NET Assembly with everything in it but the kitchen sink (Figure 1 shows my all-time favorite ice cream sundae: Jahn's Kitchen Sink. It could satisfy six hungry kids!). Figure 2 shows the Solution Explorer view of my assembly. It has a function, structure, DataWindow object, menu, CVUO, SCUO, Window and a .NET enumeration. I also added an image file with a Build Action of ‘Embedded Resource.' My plan was to plunge into the assembly's bowels, locate my classes and write code to dynamically build a directory listing of their names that I could present in my UI.
Figure 1: Kitchen Sink Ice Cream Sundae
Figure 2: Shared Assembly
I built a PowerBuilder assembly from my target and used Reflector to examine the assembly structure. Figure 3 show the contents of the disassembled assembly's default namespace. For the screenshot I aligned its generated .NET classes next to their PowerScript Explorer view counterparts. Notice that for each PowerScript Class there is a correspondingly named .NET class prefixed by C__. These C__ classes are the .NET implementation classes. There is also a class named PBGlobalDefinitions_sharedobjects (the target name prefixed by PBGlobalDefinitions_). A look inside this class as shown in Figure 4 reveals that it is a wrapper for the PowerScript class identifiers declared to be of their corresponding C__ class types. This class lists some of the members of our PowerBuilder runtime assembly, but where are the DataWindow Objects?
Figure 3: External vs. internal assembly view
Figure 4: External vs internal Global Type view
A little more poking around with Reflector revealed their location. Figure 5 shows that the engineers tucked DataWindow Object syntax in a local folder named Resources, together with WPF XAML and embedded assembly resources.
Figure 5: DataWindow location
Building the Plumbing
Armed with the knowledge I gained using Reflector about where the global type names were stored, I was able to use methods from the.NET Reflection API to write code to extract global type names from the PowerBuilder assembly. Listing 1 shows the code I wrote to populate a drop down selection list
Listing 1: Extracting Class Names
Assembly myAssembly //some declarations
System.@Type types [ ], atype
FieldInfo pbfields, pbfield
myAssembly = Assembly.LoadFrom(lpath) //lpath holds the folder/file name of
integer i_upper, x, i_innerctr, y
types = myAssembly.GetExportedTypes() // Get an array of the types in the assembly
for x = 1 to types.Length //iterate the array looking for ‘our man'
atype = Types[x]
if Left (atype.FullName,20) = 'PBGlobalDefinitions_' then //if are you're "PBGlobalDefinitions_" let's look inside you
for y=1 to pbfields.Length
pbfield=pbfields[y] //add the global ref name to the DDLB
if not pbfield.IsStatic then ddlb_visuals.AddItem(pbfield.Name)
Writing code to extract the DataWindow object names was an interesting challenge. It turns out that sharedobjects.g.resources stored in the Resources folder is a collection object. Using some code examples I found on the web as my guide I was able to write the code shown in Listing 2 to populate a dropdown listbox with the DataWindow object names.
Listing 2: Extracting DataWindow names
_rreader = Create System.Resources.ResourceReader (myassembly.GetManifestResourceStream("sharedobjects.g.resources"))
_enum = _rreader.GetEnumerator()
do while _enum.MoveNext ( )
sResource = _enum.Key.ToString()
if Right(sResource,4)='.srd' then //we got a dwo name!
sResource=Left(sResource, Len(sResource) - 4)
catch (System.Exception e)
The sum total of these two code listings is roughly equivalent to the Classic LibraryDirectory( ) function. Although we are now much richer for the experience, I can't help but think, "Gee whiz wouldn't it have been good if the product engineers would have provided AssemblyDirectory( )functionality?"
An Example: Putting It Together
For my .NET snap-in API I took a decidedly .NET approach. Rather than providing common ancestors and implementing an inheritance-based approach, I decided to provide a common interface that each snap-in class would implement as a kind of marker that indicated the developer had done due diligence in conforming to the interface. In this simple example I only gave the interface one function; in a production application the interface would define many more functions all of which would need to be implemented to fulfill the snap-in contract. Using an interface-based approach allows a snap-in developer to choose class ancestry from among a range of choices. I put my interface in a separate PowerBuilder assembly target that I built and added as a reference to both the snap-in and dynamic loader targets. Figure 6 shows my SnapCommon assembly.
Figure 6: SnapCommon assembly
Listing 3: Testing the interface
lpo = create using ddlb_visuals.Text //create the object non-visually
cdo = po.ClassDefinition
try //check if the object implements the snappable interface
rc = lpo.dynamic init_snap( 5 ) //all snap-ins must implement this method
catch (RuntimeError r ) //if the method ain't there, it ain't a legal snap-in
MessageBox('Interface Error', 'Snap-In does not implement the i_snappable interface')
rc = -1
if rc=-1 then return
To determine if the selected snap-in is value, we create the object non-visually and try to call the method define in the interface. If the method isn't there, we'll catch the runtime exception, show a message and quit. If the method is there (we have a valid snap-in), we'll use PowerBuilder reflection to determine its type and then create it using its type correct open function; Listing 3 shows that code. Please note that PowerBuilder reflection was not enhanced to report on .NET types, therefore we cannot use the ClassDefinition object to determine if an interface is implemented by a class. It is possible to use .NET reflection as shown in Figure 7 to determine if an interface is implemented. To do so we'd have to get the implementation class and then reflect inside of it using the PowerBuilder mangled names. However, because it is less code and a ‘pure' PowerScript approach, we chose to take a dynamic approach. Listing 4 shows the Choose Case decision block for opening a class based on its type.
Listing 4: Choose Case decision block
mytype = cdo.DataTypeOf
choose case mytype
rc = parent.openuserobject( uo, ddlb_visuals.Text, 10, 10)
if rc = -1 then
parent.Title='Open User Object Failed'
parent.Title='Open User Object Succeeded ' + string(rc)
if IsNull(rc) then parent.Title='Open User Object Returned NULL ' + ddlb_visuals.Text
Open( w, ddlb_visuals.Text)
lds = create using ddlb_visuals.Text
lds.dynamic of_load( sqlca )
Incidentally, creating DataWindows required the most trivial coding. Listing 5 shows the three lines of code.
Listing 5: Displaying a DataWindow
dw_dwos.dataobject = ddlb_dwos.Text
dw_dwos.SetTransObject( sqlca )
Figure 7: .NET Interface location
Suggestions for Improvement: Most Needed & Nice to Have PowerScript Features
First, the ability to declare namespaces and put PowerScript classes into them is one of the useful .NET CLR language features added to PowerBuilder. Open( ) functions support namespaces when they are statically hardcoded. For example Open(elearnIT.w_testwindow) compiles and operates properly. However, my experiments revealed that the language does not support using namespaces in dynamic Open functions and Create Using statements. For example both Open(lWindow, "elearnIT.w_testwindow") and Open(lWindow, "elearnIT_w_testwindow") fail. This lack of support could be a major impediment for enterprise vendors who would likely instruct their independent software vendors to put their third-party assemblies into a customer-specific namespace in order to guarantee name uniqueness in a multi-vendor application snap-in environment.
Second, even though I wrote code to show how one might get directory listings of an assembly's contents, having native functions such as AssemblyDirectory and AssemblyDirectoryEx would be helpful.
Third, it would be useful to extend the PowerBuilder reflection API to report on .NET types present in a PowerBuilder class.
Fourth, it would be useful to be able to statically reflect on a PowerBuilder Class without having to create it first as a PowerObject.
With a good understanding of PowerScript and .NET reflection, coupled with knowledge of polymorphic coding techniques, a developer can design and implement dynamic and creative solutions to expand the usefulness of their enterprise applications.
Long Live PowerBuilder!
WebRTC is bringing significant change to the communications landscape that will bridge the worlds of web and telephony, making the Internet the new standard for communications. Cloud9 took the road less traveled and used WebRTC to create a downloadable enterprise-grade communications platform that is changing the communication dynamic in the financial sector. In his session at @ThingsExpo, Leo Papadopoulos, CTO of Cloud9, discussed the importance of WebRTC and how it enables companies to focus o...
Jan. 19, 2017 07:30 PM EST Reads: 4,228
A critical component of any IoT project is what to do with all the data being generated. This data needs to be captured, processed, structured, and stored in a way to facilitate different kinds of queries. Traditional data warehouse and analytical systems are mature technologies that can be used to handle certain kinds of queries, but they are not always well suited to many problems, particularly when there is a need for real-time insights.
Jan. 19, 2017 06:30 PM EST Reads: 6,314
Providing secure, mobile access to sensitive data sets is a critical element in realizing the full potential of cloud computing. However, large data caches remain inaccessible to edge devices for reasons of security, size, format or limited viewing capabilities. Medical imaging, computer aided design and seismic interpretation are just a few examples of industries facing this challenge. Rather than fighting for incremental gains by pulling these datasets to edge devices, we need to embrace the i...
Jan. 19, 2017 05:30 PM EST Reads: 3,626
Web Real-Time Communication APIs have quickly revolutionized what browsers are capable of. In addition to video and audio streams, we can now bi-directionally send arbitrary data over WebRTC's PeerConnection Data Channels. With the advent of Progressive Web Apps and new hardware APIs such as WebBluetooh and WebUSB, we can finally enable users to stitch together the Internet of Things directly from their browsers while communicating privately and securely in a decentralized way.
Jan. 19, 2017 05:15 PM EST Reads: 3,100
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo 2016 in New York. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place June 6-8, 2017, at the Javits Center in New York City, New York, is co-located with 20th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry p...
Jan. 19, 2017 04:45 PM EST Reads: 3,755
In his General Session at 17th Cloud Expo, Bruce Swann, Senior Product Marketing Manager for Adobe Campaign, explored the key ingredients of cross-channel marketing in a digital world. Learn how the Adobe Marketing Cloud can help marketers embrace opportunities for personalized, relevant and real-time customer engagement across offline (direct mail, point of sale, call center) and digital (email, website, SMS, mobile apps, social networks, connected objects).
Jan. 19, 2017 04:00 PM EST Reads: 5,427
SYS-CON Events announced today that Catchpoint, a leading digital experience intelligence company, has been named “Silver Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Catchpoint Systems is a leading Digital Performance Analytics company that provides unparalleled insight into your customer-critical services to help you consistently deliver an amazing customer experience. Designed for digital business, C...
Jan. 19, 2017 03:45 PM EST Reads: 1,793
@ThingsExpo has been named the ‘Top WebRTC Influencer' by iTrend. iTrend processes millions of conversations, tweets, interactions, news articles, press releases, blog posts - and extract meaning form them and analyzes mobile and desktop software platforms used to communicate, various metadata (such as geo location), and automation tools. In overall placement, @ThingsExpo ranked as the number one ‘WebRTC Influencer' followed by @DevOpsSummit at 55th.
Jan. 19, 2017 02:00 PM EST Reads: 4,783
"There's a growing demand from users for things to be faster. When you think about all the transactions or interactions users will have with your product and everything that is between those transactions and interactions - what drives us at Catchpoint Systems is the idea to measure that and to analyze it," explained Leo Vasiliou, Director of Web Performance Engineering at Catchpoint Systems, in this SYS-CON.tv interview at 18th Cloud Expo, held June 7-9, 2016, at the Javits Center in New York Ci...
Jan. 19, 2017 01:15 PM EST Reads: 5,675
The 20th International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held June 6-8, 2017, at the Javits Center in New York City, brings together Cloud Computing, Big Data, Internet of Things, DevOps, Containers, Microservices and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal ...
Jan. 19, 2017 01:15 PM EST Reads: 5,165
SYS-CON Events announced today that Linux Academy, the foremost online Linux and cloud training platform and community, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Linux Academy was founded on the belief that providing high-quality, in-depth training should be available at an affordable price. Industry leaders in quality training, provided services, and student certification passes, its goal is to c...
Jan. 19, 2017 12:15 PM EST Reads: 2,017
20th Cloud Expo, taking place June 6-8, 2017, at the Javits Center in New York City, NY, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy.
Jan. 19, 2017 12:15 PM EST Reads: 4,310
In the next five to ten years, millions, if not billions of things will become smarter. This smartness goes beyond connected things in our homes like the fridge, thermostat and fancy lighting, and into heavily regulated industries including aerospace, pharmaceutical/medical devices and energy. “Smartness” will embed itself within individual products that are part of our daily lives. We will engage with smart products - learning from them, informing them, and communicating with them. Smart produc...
Jan. 19, 2017 11:45 AM EST Reads: 1,721
"What is the next step in the evolution of IoT systems? The answer is data, information, which is a radical shift from assets, from things to input for decision making," stated Michael Minkevich, VP of Technology Services at Luxoft, in this SYS-CON.tv interview at @ThingsExpo, held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA.
Jan. 19, 2017 10:00 AM EST Reads: 5,568
The emerging Internet of Everything creates tremendous new opportunities for customer engagement and business model innovation. However, enterprises must overcome a number of critical challenges to bring these new solutions to market. In his session at @ThingsExpo, Michael Martin, CTO/CIO at nfrastructure, outlined these key challenges and recommended approaches for overcoming them to achieve speed and agility in the design, development and implementation of Internet of Everything solutions with...
Jan. 19, 2017 10:00 AM EST Reads: 5,583
WebRTC sits at the intersection between VoIP and the Web. As such, it poses some interesting challenges for those developing services on top of it, but also for those who need to test and monitor these services. In his session at WebRTC Summit, Tsahi Levent-Levi, co-founder of testRTC, reviewed the various challenges posed by WebRTC when it comes to testing and monitoring and on ways to overcome them.
Jan. 19, 2017 09:30 AM EST Reads: 6,040
Internet of @ThingsExpo, taking place June 6-8, 2017 at the Javits Center in New York City, New York, is co-located with the 20th International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. @ThingsExpo New York Call for Papers is now open.
Jan. 19, 2017 07:30 AM EST Reads: 3,661
Smart Cities are here to stay, but for their promise to be delivered, the data they produce must not be put in new siloes. In his session at @ThingsExpo, Mathias Herberts, Co-founder and CTO of Cityzen Data, discussed the best practices that will ensure a successful smart city journey.
Jan. 19, 2017 07:00 AM EST Reads: 2,034
Every successful software product evolves from an idea to an enterprise system. Notably, the same way is passed by the product owner's company. In his session at 20th Cloud Expo, Oleg Lola, CEO of MobiDev, will provide a generalized overview of the evolution of a software product, the product owner, the needs that arise at various stages of this process, and the value brought by a software development partner to the product owner as a response to these needs.
Jan. 19, 2017 07:00 AM EST Reads: 1,231
In 2014, Amazon announced a new form of compute called Lambda. We didn't know it at the time, but this represented a fundamental shift in what we expect from cloud computing. Now, all of the major cloud computing vendors want to take part in this disruptive technology. In his session at 20th Cloud Expo, John Jelinek IV, a web developer at Linux Academy, will discuss why major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform are all trying to sidestep VMs and containers...
Jan. 19, 2017 06:00 AM EST Reads: 874