Full list of in-depth articles -
Feedback and questions -
Request demo -
17 September 2004 - Visual Basic Express and SoProMach
1
| Extending Visual Basic Express 2005 Beta 1 with a Somusar generator |
|
|
3
| Preparing an integration workspace in VB Express |
|
4
| Extending VB Express with SoProMach/XML-VB |
|
4.1
| Gaining access to the "External Tools..." button |
|
4.2
| Adding external tool SoProMach/XML-VB |
|
5
| Running SoProMach/XML-VB from within VB Express |
|
5.1
| Building the VB project |
|
5.2
| Generating "Northwind.vb" |
|
5.3
| Extending class Northwind |
|
5.4
| Generating "Southwind.vb" |
|
|
A previous article discussed how
Eclipse 3.0 can be extended
with a Somusar generator to consistently and efficiently produce
a number of interrelated Java classes, JSP and configuration files.
This article describes how to integrate an XML-driven Somusar generator
with another popular integrated development environment (IDE):
Microsoft
Visual Basic Express 2005 Beta 1 (VB Express).
Such an integration shows how to use VB Express comfortable user interface
to directly drive SoProMach's powerful code generation facilities,
significantly improving VB Express users' productivity without limiting
their development experience.
The Somusar generator used for this article produces code
conforming to Kathleen Dollard's article "Generate .NET Code With XSLT" published by Visual Studio Magazine.
Depending on different project requirements and constraints,
different Somusar generators can be integrated with different IDEs
to produce source code, configuration files, and documentation
compliant to those requirements and constraints.
This article assumes that you have a working installation of both
Visual Basic Express 2005 Beta 1 and SoProMach/XML-VB on Windows 2000 or Windows XP.
Instructions on how to install and run the SoProMach/XML-VB
generator are provided in the appendix to this article.
Please refer to the
generator description for information
on how to request the free trial package of the generator.
To test the SoProMach/XML-VB generator we suggest you to set up a
new project (menu "File -> New Project")
called "vb_sopromach" in VB Express. Choose the default
type for new projects ("Windows Application") as shown in the
following picture.
Figure 1 - Creating a new VB Express project
After creating the new project, you need to add three files from
the SoProMach/XML-VB installation folder: "Northwind.vb", "Northwind.xml", and
"Southwind.xml". To do so, open the "Add Existing Item" dialog (menu
"Project -> Add Existing Item") and look in the generator
folder. Select to view files of type "All Files".
You can add the three files at once, as shown in the
next picture. Click on "Add".
Figure 2 - Adding files to the VB project
Your Visual Basic Express 2005 Beta 1 should now look as shown in the next picture: the Solution
Explorer should list the added files.
Figure 3 - VB Express after adding files
Now close the project (menu "File -> Close Project"): click on "Save"
in the two dialog boxes that will pop up one after the other.
Up to now you have created a simple VB.NET project with one class
and two XML files.
Extending VB Express with the generator is not more complex than that,
but you first need to customize VB Express to show you the "External Tools..."
item of menu "Tools", as the generator is configured as an
external tool.
Open the "Customize" dialog (menu "Tools -> Customize"). Select tab
"Commands", then click on "Rearrange Commands" (see below).
Figure 4 - Commands customization in VB Express
Now select menu bar "Tools" in dialog "Rearrange Commands",
then click on "Add", as shown in the following picture.
Figure 5 - Adding VB Express commands
Select category "Tools", then scroll down to, and select,
command "External Tools...". The dialog settings are shown
in the next picture.
Figure 6 - Adding command "External Tools..."
Click on "OK". The "Rearrange Commands" dialog should now look
as in the picture below.
Figure 7 - Command "External Tools..." added
Click on "Close", then close also dialog "Customize".
You can now open the external tools configuration dialog via
menu "Tools -> External Tools...".
Set the input fields as follows (Note:
we chose to install SoProMach/XML-VB under "C:\vb_user\vb_dotnet_2":
in case you chose a different folder, change the settings below
accordingly):
- Title: Sopromach/VB
- Command: C:\vb_user\vb_dotnet_2\pocbin\win\tefigel.exe
- Arguments: C:\vb_user\vb_dotnet_2\ide_bridge.tfg $(ItemPath)
- Initial directory: C:\vb_user\vb_dotnet_2
Set "Use Output Window" to active. The dialog settings are shown
in the next picture. Now click on "OK".
Figure 8 - Adding SoProMach/XML-VB with dialog "External Tools..."
You are now ready to run the generator, but before generating
new code you need to make sure that your project gets built
without errors. To achieve that,
you first need to add references to external resources.
Re-open the project (menu "File -> Recent Projects -> vb_sopromach"),
then open dialog "Add Reference" (menu "Project -> Add Reference").
Scroll down to the list bottom, then select both "System.Data.dll" and
"System.Xml.dll", as shown below. Then click on "OK".
Figure 9 - Adding project references
Build the project (menu "Build -> Build vb_sopromach") and
make sure that your VB Express window looks like the checkpoint picture below, with
message "Build succeeded".
Figure 10 - Checkpoint 1
The input models to SoProMach/XML-VB are XML files, such as "Northwind.xml" and
"Southwind.xml". Double-click on "Northwind.xml" in the Solution Explorer
to open it. Then run SoProMach/XML-VB (menu "Tools -> Sopromach/VB").
Your VB Express should now look like the following picture.
Figure 11 - Applying the generator on "Northwind.xml"
You have now re-generated "Northwind.vb" exactly as it was in the
generator installation, so that nothing special has happened yet.
Edit class Northwind by double-clicking on "Northwind.vb"
in the Solution Explorer, and search repeatedly for "phone" within that class
(menu "Edit -> Quick find"). There are 17 occurrences of "phone".
Now, suppose that your task is to extend class Northwind to also manage
cellphones. This is very similar to managing phones, so you should
duplicate those 17 code fragments, changing "phone" or "Phone" to
"cellphone" or "Cellphone". You can perform this task by means of
copy-paste-edit cycles, or you can achieve the
same result more quickly and safely using SoProMach/XML-VB.
Click on tab "Northwind.xml" to edit it, then duplicate the row
describing DataColumn "Phone". Change the copy to "Cellphone" as shown
in the next picture.
Figure 12 - Adding Cellphone to "Northwind.xml"
Save file "Northwind.xml", then run again SoProMach/XML-VB
(menu "Tools -> Sopromach/VB"). VB Express will pop up the question
shown below: click on "Yes".
Figure 13 - Reloading "Northwind.vb"
Now click on tab "Northwind.vb" and search for "cellphone": you will thus
get a feeling of the effectiveness of extending Visual Basic Express 2005 Beta 1 with
SoProMach/XML-VB.
You can now instruct your code-generator-enabled VB Express to produce similar code
for a different class of the same type. Instead of the Northwind
code, you will generate equivalent code for a hypothetical Southwind database.
Add an empty class Southwind (menu "Project -> Add Class") as shown in the
following picture.
Figure 14 - Adding an empty Southwind
Check that the project gets built correctly (menu "Project -> Build")
as shown below.
Figure 15 - Checkpoint 2
Double-click on "Southwind.xml" to open it in the editing area of
VB Express. Note that this is roughly the same as "Northwind.xml": all occurrences
of "North" have been changed to "South". But you can add new attributes
and extend this XML model as you prefer.
To complete this exercise, run again SoProMach/XML-VB, but this time on
"Southwind.xml". Confirm that VB Express
should reload the modified "Southwind.vb", then view it and rebuild
the project. Your VB Express should now look like the picture below.
Figure 16 - Generation completed
Somusar proof-of-concept (POC) generators
are delivered in tar/gzip format. POC packages contain
a SoProMach and the textual input and scripts that re-generate
the POC target code. Compressed POC packages are well below 1 MByte in size,
and can be uncompressed with all most common unzip and uncompress utilities.
To install SoProMach/XML-VB proceed as follows. Unpack the POC package to
a new folder of your choice (suggestion: C:\vb_user\vb_dotnet_2).
After unpacking the new folder should look as shown below.
Figure 17 - Unpacking the generator trial package
Double-clicking on BAT file "w1_prepare" should result in the
command window of next picture. This step removes file "Northwind.vb"
which will be produced by the generator.
Figure 18 - Setting up the generator
Press Return once to set up the generator, then once again to
close the command window. Now double-click on BAT file "w2_generate":
SoProMach/XML-VB will generate "Northwind.vb" from "Northwind.xml" as shown in the
following picture.
Figure 19 - Running the generator
Press Return to close the window. The next step
is optional: double-clicking on BAT file "w3_results"
will list the file produced by the generator ("Northwind.vb").
Figure 20 - Result listing
The installation folder window should now look as in the following
screenshot: "Northwind.vb" has now been re-generated.
Figure 21 - Re-generated "Northwind.vb"
Full list of in-depth articles -
Feedback and questions -
Request demo -
|