|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!
The 19th International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, 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 y...
May. 24, 2016 05:00 PM EDT Reads: 1,826
In his session at 18th Cloud Expo, Bruce Swann, Senior Product Marketing Manager at Adobe, will discuss 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). Bruce Swann has more than 15 years of experience working with digital marketing disciplines like web analytics, social med...
May. 24, 2016 04:45 PM EDT Reads: 977
The essence of data analysis involves setting up data pipelines that consist of several operations that are chained together – starting from data collection, data quality checks, data integration, data analysis and data visualization (including the setting up of interaction paths in that visualization). In our opinion, the challenges stem from the technology diversity at each stage of the data pipeline as well as the lack of process around the analysis.
May. 24, 2016 04:30 PM EDT Reads: 871
There are several IoTs: the Industrial Internet, Consumer Wearables, Wearables and Healthcare, Supply Chains, and the movement toward Smart Grids, Cities, Regions, and Nations. There are competing communications standards every step of the way, a bewildering array of sensors and devices, and an entire world of competing data analytics platforms. To some this appears to be chaos. In this power panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists will discuss the vast to...
May. 24, 2016 04:00 PM EDT Reads: 2,340
Internet of @ThingsExpo, taking place November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with the 19th International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world and ThingsExpo New York Call for Papers is now open.
May. 24, 2016 04:00 PM EDT Reads: 1,671
Designing IoT applications is complex, but deploying them in a scalable fashion is even more complex. A scalable, API first IaaS cloud is a good start, but in order to understand the various components specific to deploying IoT applications, one needs to understand the architecture of these applications and figure out how to scale these components independently. In his session at @ThingsExpo, Nara Rajagopalan is CEO of Accelerite, will discuss the fundamental architecture of IoT applications, ...
May. 24, 2016 03:45 PM EDT Reads: 566
As cloud and storage projections continue to rise, the number of organizations moving to the cloud is escalating and it is clear cloud storage is here to stay. However, is it secure? Data is the lifeblood for government entities, countries, cloud service providers and enterprises alike and losing or exposing that data can have disastrous results. There are new concepts for data storage on the horizon that will deliver secure solutions for storing and moving sensitive data around the world. ...
May. 24, 2016 03:30 PM EDT Reads: 899
SYS-CON Events announced today that Enzu, a leading provider of cloud hosting solutions, will exhibit at SYS-CON's 18th International Cloud Expo®, which will take place on June 7-9, 2016, at the Javits Center in New York City, NY. Enzu’s mission is to be the leading provider of enterprise cloud solutions worldwide. Enzu enables online businesses to use its IT infrastructure to their competitive advantage. By offering a suite of proven hosting and management services, Enzu wants companies to foc...
May. 24, 2016 02:15 PM EDT Reads: 2,064
SYS-CON Events announced today the How to Create Angular 2 Clients for the Cloud Workshop, being held June 7, 2016, in conjunction with 18th Cloud Expo | @ThingsExpo, at the Javits Center in New York, NY. Angular 2 is a complete re-write of the popular framework AngularJS. Programming in Angular 2 is greatly simplified. Now it’s a component-based well-performing framework. The immersive one-day workshop led by Yakov Fain, a Java Champion and a co-founder of the IT consultancy Farata Systems and...
May. 24, 2016 02:00 PM EDT Reads: 3,830
IoT generates lots of temporal data. But how do you unlock its value? How do you coordinate the diverse moving parts that must come together when developing your IoT product? What are the key challenges addressed by Data as a Service? How does cloud computing underlie and connect the notions of Digital and DevOps What is the impact of the API economy? What is the business imperative for Cognitive Computing? Get all these questions and hundreds more like them answered at the 18th Cloud Expo...
May. 24, 2016 01:45 PM EDT Reads: 2,041
Customer experience has become a competitive differentiator for companies, and it’s imperative that brands seamlessly connect the customer journey across all platforms. With the continued explosion of IoT, join us for a look at how to build a winning digital foundation in the connected era – today and in the future. In his session at @ThingsExpo, Chris Nguyen, Group Product Marketing Manager at Adobe, will discuss how to successfully leverage mobile, rapidly deploy content, capture real-time d...
May. 24, 2016 01:45 PM EDT Reads: 1,350
In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, will provide an overview of the evolution of the Internet and the Database and the future of their combination – the Blockchain. Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life ...
May. 24, 2016 01:30 PM EDT Reads: 1,729
What a difference a year makes. Organizations aren’t just talking about IoT possibilities, it is now baked into their core business strategy. With IoT, billions of devices generating data from different companies on different networks around the globe need to interact. From efficiency to better customer insights to completely new business models, IoT will turn traditional business models upside down. In the new customer-centric age, the key to success is delivering critical services and apps wit...
May. 24, 2016 01:15 PM EDT Reads: 686
SYS-CON Events announced today that ContentMX, the marketing technology and services company with a singular mission to increase engagement and drive more conversations for enterprise, channel and SMB technology marketers, has been named “Sponsor & Exhibitor Lounge Sponsor” of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2016, at the Javits Center in New York City, New York. “CloudExpo is a great opportunity to start a conversation with new prospects, but what happens after the...
May. 24, 2016 10:30 AM EDT Reads: 706
SYS-CON Events announced today that 24Notion has been named “Bronze Sponsor” of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2016, at the Javits Center in New York, New York. 24Notion is full-service global creative digital marketing, technology and lifestyle agency that combines strategic ideas with customized tactical execution. With a broad understand of the art of traditional marketing, new media, communications and social influence, 24Notion uniquely understands how to con...
May. 24, 2016 09:30 AM EDT Reads: 1,673
The demand for organizations to expand their infrastructure to multiple IT environments like the cloud, on-premise, mobile, bring your own device (BYOD) and the Internet of Things (IoT) continues to grow. As this hybrid infrastructure increases, the challenge to monitor the security of these systems increases in volume and complexity. In his session at 18th Cloud Expo, Stephen Coty, Chief Security Evangelist at Alert Logic, will show how properly configured and managed security architecture can...
May. 24, 2016 09:00 AM EDT Reads: 1,952
When it comes to IoT in the enterprise, namely the commercial building and hospitality markets, a benefit not getting the attention it deserves is energy efficiency, and IoT's direct impact on a cleaner, greener environment when installed in smart buildings. Until now clean technology was offered piecemeal and led with point solutions that require significant systems integration to orchestrate and deploy. There didn't exist a 'top down' approach that can manage and monitor the way a Smart Buildi...
May. 24, 2016 08:30 AM EDT Reads: 2,038
SYS-CON Events announced today BZ Media LLC has been named “Media Sponsor” of SYS-CON's 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA. BZ Media LLC is a high-tech media company that produces technical conferences and expositions, and publishes a magazine, newsletters and websites in the software development, SharePoint, mobile development and Commercial Drone markets.
May. 24, 2016 06:00 AM EDT Reads: 3,378
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, will discuss the importance of WebRTC and how it enables companies to fo...
May. 24, 2016 04:30 AM EDT Reads: 2,394
SYS-CON Events announced today TechTarget has been named “Media Sponsor” of SYS-CON's 18th International Cloud Expo, which will take place on June 7–9, 2016, at the Javits Center in New York City, NY, and the 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA. TechTarget is the Web’s leading destination for serious technology buyers researching and making enterprise technology decisions. Its extensive global networ...
May. 24, 2016 04:00 AM EDT Reads: 3,006