Patterns is a template-based tool (dkt files). This means that xpz files are generated based on the generated instances and the application of certain configuration files and certain templates, and these xpz files will be consolidated in GX to generate more GX objects.
Templates combine C# code with the KMW language used in GX. Therefore, the output text obtained (xml corresponding to xpz) has code directly copied from the template and xml code generated by the C# statements.
When visualizing a template code you see something like the following:
Here you can see that a Case is being generated to be included in the xpz, and two components can be identified:
The code between <% and %> is C# code; e.g.: <%=icAtt.Name%>. In this case this segment is substituted for the variable value at this moment, or the result of processing with the foreach.
What is outside <% and %> signs is GX code. It is copied directly to the xpz.
It is a program that processes an input text (instance, xml format) and produces another text. In the case of patterns this text is an xpz (xml file).
KMW - GeneXus (output)
In this way, based on the KB, the instances generation and the configuration files, and applying the templates, you obtain the definition of those GX objects you want to consolidate in the new KB version.
As we have said so far, to generate an instance associated to an object you must just double click on the object and you will start using the program setup in the DefaultGenerator property to generate the default instance (which uses the GXPatterns.WorkWith.WorkWithGenerator value by default).
Once the instance(s) is (are) ready to be processed, on pressing F5 from Patterns (option Build\Apply and Consolidate) the installation process starts.
The following steps are executed in this process:
- An xml is generated for each existing instance (representing the xpz corresponding to this instance)
- The mentioned xpz contains all the objects to be consolidated in GX associated to the mentioned instance.
- Only one xpz is generated with all the instances xmls.
- Output.xml.xpz is consolidated in the KB, obtaining version 2 of the KB.
The first step (generating the xml of each one of the instances) is performed by the template engine. The second step (generating only one xpz) is performed directly by the tool.
The template engine process is in charge of taking an instance and applying a template to it to generate an xml (xpz) with all the objects.
Some auxiliary dlls are used in addition to the dkts to perform this process.
For each pattern, there is a dkt in charge of executing these actions and the rest are called based on it. ViewGenerator.dkt is used in the case of Work With pattern.
The Build Information\GeneratorFilename property of Pattern.Definition is setup to indicate the dkt to be used.
This template uses several sub-templates. E.g.: the following lines are in ViewGenerator.dkt :
<%@ SubTemplate Name="ViewTemplate" File="ViewTemplate.dkt" %>
<%@ SubTemplate Name="GridTemplate" File="GridTemplate.dkt" %>
<%@ SubTemplate Name="TabularTemplate" File="TabularTemplate.dkt" %>
The sub-template to be used is indicated here.
There are some important templates from which we will mention the following (although their names are quite descriptive and deducting what each of them generates is easy):
It generates all work with, grids and prompts information.
It generates all the views information.
It generates all the information regarding the General component used in the Views
It generates all the transactions information.
Some dlls (assemblies) are also used within the templates. They help in the xml generation.
The following is used in ViewGenerator.dkt:
<%@ Assembly Name="GXKnowledgeBase" %>
<%@ Assembly Name="WorkWith" %>
<%@ Assembly Name="TemplateHelpers" %>
GXKnowledgeBase.dll and TemplateHelpers.dll help to scan the KB and to generate the xml. Particularly, these dlls help in the generation of variables, controls, etc.
These dlls are generis for any pattern.
In Documentation.chm you will find the documentation associated to these programs.
WorkWith.dll is also used within the template, since within this dll there are several routines to generate parts of the objects.
If you visualize WorkWith.dll sources you can see that within GXPatternsSources there is a WorkWith\Helpers directory and within this directory you can find several cs; these are the auxiliary dlls mentioned before.
E.g.: PagingButton.cs is the source generating the code in xpz to generate the paging buttons.
In GridTemplate.dkt you can see a reference to this routine:
private string PagingButtons(ArrayList buttons)
string r = "";
foreach (PagingButton button in buttons)
r += button.ToHtmlImage();
And in PagingButton.cs there is:
public string ToHtmlImage()
return HtmlToKmw.Image(Name, GlobalWorkWithConfig.Config.Theme("Image"), m_Caption, GlobalWorkWithConfig.Config.ImagePath() + Image) + "\r\n";
The code to generate the buttons segment of xpz is returned in this way.
Another interesting routing included within workwith.dll is IsLastInstance.
On pressing F5 you also control whether generating the objects to be consolidated just once (list programs, recent links, etc.) in xpz is required or not.
This routines controls whether generating these objects is necessary or not. As these objects go just once, they are generated in the last instance.
More information about other templates: