Recipes with AjGenesis

Past weeks, I was giving speechs about my open source code generation project, AjGenesis, at two cities of my country: Tandil and Corrientes, thanks to the organization of the Microsoft User Group of Argentina. Usually, I show examples of my project in action; following the “dog fooding” principle, I used it every week. The current version under development is

AjGenesis 0.5

More about the capabilites of the project at:

Application Generation using AjGenesis
Code Generation with AjGenesis: A Hello World application

I’m experimenting adding the capability of invoking one or more entry windows, from a task, to take parameters from the user during the code generation process.

Now, all is produced from model or models, free designed by users, serialized on XML files. But it could be convenient, depending of the code to generate, to take new parameters from the user, in the middle of the code generation. Examples of parameters: target directory and file names, connection strings, namespaces and packages names, etc…

Following this idea, there is a new experimental project in the solution, named AjGenesis.Recipes,  that use the new project AjGenesis.UI. This UI project has a window form dedicated to accept data from the user.

An screenshot:

At the beginning, there is no information in the tree at left. Go to File | Open… and select an example file with recipe definitions: Recipes.xml (it is in the source code directory of the project).

This file contents:


<?xml version="1.0" encoding="utf-8" ?> <Recipes Name="Recipes"> <Node Name="Hello World"> <Recipe Name="Hello World VB.NET Module" Task="Tasks/HelloWorldTask.ajg" Documentation="Tasks/HelloWorldTask.html"/> </Node> <Node Name="VB.NET"> <Recipe Name="Entities" Task="Tasks/Task1.ajg" Documentation="Tasks/Task1.html"/> <Recipe Name="Services"/> </Node> <Node Name="CSharp"> <Recipe Name="Entities"/> <Recipe Name="Services"/> </Node> </Recipes>

Each  node can contains nodes and recipes. A recipe has a name, that is displayed in the tree, a task, AjBasic code to execute, and a file that documents the recipe in HTML.

If you double click over the Hello World VB.NET Module recipe, a window appears. You can enter the file to use as a model, and the name of the .vb file to generate:

The new feature is implemented in the task file, that uses the project AjGenesis.UI and its window form. Let see Tasks\HelloWorldTask.ajg:

form = UIManager.CreateInputForm() form.Text = "Class Generator Wizard" form.AddFileField("Model","Model to use","") form.AddFileField("FileName","File to Generate","") n = form.ShowDialog() if n = 1 then ModelFile = form.GetField("Model") FileName = form.GetField("FileName") ModelManager.LoadModel(ModelFile,Environment) TransformerManager.Transform("Templates/HelloWorldVb.tpl",FileName,Environment) end if

UIManager is a new manager object in this AjGenesis version. Note how a window and its field can be defined and processed. The field values can then retrieved, to use in the generation process.

This is work in progress, but it looks enough interesting to me to write this post.

The model is still used. Any recipe needs one or more model to use as a base to produce the code or text to generate. With AjGenesis Recipes the model could be given in a interactive way. The time will show if these feature is useful to the users, instead of the use of NAnt tasks.

A recipe could be written, without using a model: the paremeters could be enough  to feed the process.

Using a more elaborate interface, we could define our own files of tasks, recipes and templates, invoked from thise program. We can write a recipe to generate all the DAOs in a systems. Or a recipe that generates a set of entities..

Next steps:

  • Estabilization of code (I must fix some directory and file name treatment, their relative position)
  • Improve exception management
  • Capture the output of tasks, and show it in one window during the process 
  • Complete AjGenesis.UI to manage a more complete set of controls (now, it only has a text field, and a directory or file chooser) and a list of windows, like a real wizard
  • Allow the use of user defined controls and windows
  • After writing some recipes, explore if it is useful or interesting or feasible, to integrate this stuff into Visual Studio (or Eclipse, why not), as GAT, or like a  Visual Studio Integration Package.

Suggestions, comments, ideas, welcome!

Angel “Java” Lopez

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s