In the previous post in this series, I added a lot of stuff to manage the generation of .NET projects and solutions. That files are complicated. In contrast, to generate something alike for Java, I only need to generate the folder structure for package, and maybe add Ant or Maven files. But in .NET, I was to struggle with the structure of solution and project files. The code for this part can be downloaded from AppExampleStep06.zip. You need the compiled binaries AjGenesisTrunkBinaries.zip. The complete AjGenesis project, including the examples for this post series, can be downloaded from http://ajgenesis.codeplex.com.
One of the complicated part was to add all .cs and .vb files inside the project file. I wrote:
for each Entity in Project.Model.Entities TransformerManager.Transform("Templates/CSharp/EntityClass.tpl", "${Project.BuildDirectory}/${Project.Name}.Entities/${Entity.Name}.cs", Environment) PrjEntities.Includes.Add(CreateFileCs("${Entity.Name}")) end forThe Includes list in PrjEntities object keeps the information of the files to add in the project file generation. Instead of adding the files in that way, now I add ALL .cs files in the C# project, and all .vb files in the VB.Net project. So, you can add your own custom files, and the project files still will reference them after regeneration of the solution. The key code is inside the Utilities/DotNetUtilities.ajg:
Sub AddVbFilesToProject(project) di = new System.IO.DirectoryInfo(project.Directory) prefix = "" AddVbFiles(project, name, di) End Sub Sub AddVbFiles(project, prefix, di) for each fi in di.GetFiles("*.vb") name = fi.Name.Substring(0, fi.Name.Length - 3) project.Includes.Add(CreateFileVb(prefix & name)) end for sdirs = di.GetDirectories() for each sdir in sdirs AddVbFiles(project, prefix & sdir.Name & "\", sdir) end for End Sub Sub AddCsFilesToProject(project) di = new System.IO.DirectoryInfo(project.Directory) prefix = "" AddCsFiles(project, name, di) End Sub Sub AddCsFiles(project, prefix, di) for each fi in di.GetFiles("*.cs") name = fi.Name.Substring(0, fi.Name.Length - 3) project.Includes.Add(CreateFileCs(prefix & name)) end for sdirs = di.GetDirectories() for each sdir in sdirs AddCsFiles(project, prefix & sdir.Name & "\", sdir) end for End SubAnother feature I added in this step: in the previous post, each time the generation was launched, it created all the files again. Now, it use a new routine, included in Utilities/TransformUtilities.ajg:
Sub TransformFile(tpl, target, tm, env) if System.IO.File.Exists(target) then target2 = target & ".tmp" tm.Transform(tpl, target2, env) content1 = System.IO.File.ReadAllText(target) content2 = System.IO.File.ReadAllText(target2) if content1 <> content2 then System.IO.File.Copy(target2, target, true) end if System.IO.File.Delete(target2) else tm.Transform(tpl, target, env) end if End SubNow, instead of invoking the predefined object TransformerManager:
TransformerManager.Transform("Templates/CSharp/EntityClass.tpl", "${Project.BuildDirectory}/${Project.Name}.Entities/${Entity.Name}.cs", Environment)the task invoke the new routine, that compares the new file with the old one, and replace it only if they are different:
TransformFile("Templates/CSharp/EntityClass.tpl", "${Project.BuildDirectory}/${Project.Name}.Entities/${Entity.Name}.cs", TransformerManager, Environment)Next steps, for future posts: include identity to entities in model, generate database creation DLLs, DAOs, and some Java code.
Keep tuned!
Angel “Java” Lopez
http://www.ajlopez.com
thanks for admin wonderfull information…
Comment by aşk büyüsü — October 6, 2010 @ 1:25 pm
[...] Then, I downloaded the AjGenesis compiled binaries (from source trunk). And some examples, like AppExampleStep06.zip (described in Building an Application using AjGenesis (Part 6)). [...]
Pingback by Running AjGenesis using Mono and Ubuntu « Angel “Java” Lopez on Blog — October 9, 2010 @ 8:53 am
[...] (compilados desde el trunk). Y bajé algunos ejemplos, comoe AppExampleStep06.zip (descripto en Building an Application using AjGenesis (Part 6)) (Armando una Aplicación usando AjGenesis (Part [...]
Pingback by Ejecutando AjGenesis usando Mono y Ubuntu - Angel "Java" Lopez — October 15, 2010 @ 10:01 am
[...] Building an Application with AjGenesis Code Generation with AjGenesis in a Real Project Models for Code Generation in AjGenesis AjBasic: [...]
Pingback by AjGenesis: Basis of its Implementation « Angel “Java” Lopez on Blog — November 18, 2011 @ 12:07 pm
[...] Building an Application with AjGenesis Code Generation with AjGenesis in a Real Project Models for Code Generation in AjGenesis AjBasic: [...]
Pingback by AjGenesis: Bases de su implementación - Angel "Java" Lopez — November 19, 2011 @ 5:32 pm