|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!
Pulzze Systems was happy to participate in such a premier event and thankful to be receiving the winning investment and global network support from G-Startup Worldwide. It is an exciting time for Pulzze to showcase the effectiveness of innovative technologies and enable them to make the world smarter and better. The reputable contest is held to identify promising startups around the globe that are assured to change the world through their innovative products and disruptive technologies. There w...
Aug. 27, 2016 07:45 AM EDT Reads: 646
DevOps at Cloud Expo, taking place Nov 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 19th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait for long dev...
Aug. 27, 2016 06:15 AM EDT Reads: 2,334
Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more business becomes digital the more stakeholders are interested in this data including how it relates to business. Some of these people have never used a monitoring tool before. They have a question on their mind like “How is my application doing” but no id...
Aug. 27, 2016 03:15 AM EDT Reads: 1,766
Personalization has long been the holy grail of marketing. Simply stated, communicate the most relevant offer to the right person and you will increase sales. To achieve this, you must understand the individual. Consequently, digital marketers developed many ways to gather and leverage customer information to deliver targeted experiences. In his session at @ThingsExpo, Lou Casal, Founder and Principal Consultant at Practicala, discussed how the Internet of Things (IoT) has accelerated our abil...
Aug. 27, 2016 02:30 AM EDT Reads: 2,001
With so much going on in this space you could be forgiven for thinking you were always working with yesterday’s technologies. So much change, so quickly. What do you do if you have to build a solution from the ground up that is expected to live in the field for at least 5-10 years? This is the challenge we faced when we looked to refresh our existing 10-year-old custom hardware stack to measure the fullness of trash cans and compactors.
Aug. 27, 2016 01:45 AM EDT Reads: 1,731
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 wi...
Aug. 27, 2016 01:15 AM EDT Reads: 2,014
Cloud computing is being adopted in one form or another by 94% of enterprises today. Tens of billions of new devices are being connected to The Internet of Things. And Big Data is driving this bus. An exponential increase is expected in the amount of information being processed, managed, analyzed, and acted upon by enterprise IT. This amazing is not part of some distant future - it is happening today. One report shows a 650% increase in enterprise data by 2020. Other estimates are even higher....
Aug. 27, 2016 12:45 AM EDT Reads: 2,936
SYS-CON Events announced today that 910Telecom will exhibit at the 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA. Housed in the classic Denver Gas & Electric Building, 910 15th St., 910Telecom is a carrier-neutral telecom hotel located in the heart of Denver. Adjacent to CenturyLink, AT&T, and Denver Main, 910Telecom offers connectivity to all major carriers, Internet service providers, Internet backbones and ...
Aug. 26, 2016 10:00 PM EDT Reads: 1,859
SYS-CON Events announced today Telecom Reseller 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. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
Aug. 26, 2016 07:00 PM EDT Reads: 684
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, will deep dive into best practices that will ensure a successful smart city journey.
Aug. 26, 2016 04:45 PM EDT Reads: 1,549
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, Digital Transformation, 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 opportuni...
Aug. 26, 2016 04:00 PM EDT Reads: 3,951
There is growing need for data-driven applications and the need for digital platforms to build these apps. In his session at 19th Cloud Expo, Muddu Sudhakar, VP and GM of Security & IoT at Splunk, will cover different PaaS solutions and Big Data platforms that are available to build applications. In addition, AI and machine learning are creating new requirements that developers need in the building of next-gen apps. The next-generation digital platforms have some of the past platform needs a...
Aug. 26, 2016 03:15 PM EDT Reads: 501
Internet of @ThingsExpo, taking place November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 19th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devices - comp...
Aug. 26, 2016 10:15 AM EDT Reads: 3,598
Data is the fuel that drives the machine learning algorithmic engines and ultimately provides the business value. In his session at Cloud Expo, Ed Featherston, a director and senior enterprise architect at Collaborative Consulting, will discuss the key considerations around quality, volume, timeliness, and pedigree that must be dealt with in order to properly fuel that engine.
Aug. 26, 2016 09:45 AM EDT Reads: 1,872
19th Cloud Expo, taking place November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, 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. Meanwhile, 94% of enterpri...
Aug. 26, 2016 05:00 AM EDT Reads: 3,063
I wanted to gather all of my Internet of Things (IOT) blogs into a single blog (that I could later use with my University of San Francisco (USF) Big Data “MBA” course). However as I started to pull these blogs together, I realized that my IOT discussion lacked a vision; it lacked an end point towards which an organization could drive their IOT envisioning, proof of value, app dev, data engineering and data science efforts. And I think that the IOT end point is really quite simple…
Aug. 25, 2016 11:45 PM EDT Reads: 2,323
Identity is in everything and customers are looking to their providers to ensure the security of their identities, transactions and data. With the increased reliance on cloud-based services, service providers must build security and trust into their offerings, adding value to customers and improving the user experience. Making identity, security and privacy easy for customers provides a unique advantage over the competition.
Aug. 25, 2016 09:15 PM EDT Reads: 2,247
Is the ongoing quest for agility in the data center forcing you to evaluate how to be a part of infrastructure automation efforts? As organizations evolve toward bimodal IT operations, they are embracing new service delivery models and leveraging virtualization to increase infrastructure agility. Therefore, the network must evolve in parallel to become equally agile. Read this essential piece of Gartner research for recommendations on achieving greater agility.
Aug. 25, 2016 05:15 PM EDT Reads: 795
SYS-CON Events announced today that Venafi, the Immune System for the Internet™ and the leading provider of Next Generation Trust Protection, will exhibit at @DevOpsSummit at 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA. Venafi is the Immune System for the Internet™ that protects the foundation of all cybersecurity – cryptographic keys and digital certificates – so they can’t be misused by bad guys in attacks...
Aug. 25, 2016 01:00 PM EDT Reads: 2,640
For basic one-to-one voice or video calling solutions, WebRTC has proven to be a very powerful technology. Although WebRTC’s core functionality is to provide secure, real-time p2p media streaming, leveraging native platform features and server-side components brings up new communication capabilities for web and native mobile applications, allowing for advanced multi-user use cases such as video broadcasting, conferencing, and media recording.
Aug. 25, 2016 08:45 AM EDT Reads: 2,166