0

I know there is an example of code generation for asp.net mvc

Q1: I want to know how to map standard variables (which seem to be java specific) to .net folders in a solution.

# -------------------------------------------
# STANDARD VARIABLES 
# -------------------------------------------
# --- Folders 
SRC      = src/main/java
RES      = src/main/resources
WEB      = src/main/webapp
TEST_SRC = src/test/java
TEST_RES = src/test/resources
DOC      = doc
TMP      = tmp
# --- Packages
ROOT_PKG = org.foo.bar

Q2: For multiple project solution like below in an abp.io based solution, do I need to create multiple telosys projects with a set of template bundles for each? How do I handle various paths for different projects in Telosys config files I would probably like to build a Visual Studio extension that would extract project folders and namespaces and modify programmatically telosys config files to match.

Here is an example of an open source asp.net core framework abp.io can have front end (in a project each): Angular, MVC Razor pages, Blazor,

It supports multiple DBs: Entity Framework, Dapper

Its solution structure is like this:

Solution structure

The content of the solution file is like this (pointing to individual project files which are in separate folders)

Solution file

** Q3: How to have a metadata annotation to exclude an attribute in a list form or exclude it from editing**

jazb
  • 5,498
  • 6
  • 37
  • 44
Rad
  • 933
  • 1
  • 15
  • 32

2 Answers2

1

Q1 answer :

Regarding the "standard variables" they are not specific for Java (only the example is for Java). You can use them as you want for any kind of target language. These variables are usually used in the "templates.cfg" file to define the folders where generated files will be located (their use is not mandatory).

By convention :

  • SRC : folder where to generate "sources" files
  • RES : folder where to generate "resources" files (configuration files, etc)
  • WEB : folder for any web files (HTML, CSS, etc )
  • TEST_SRC : folder for unit tests sources
  • TEST_RES : folder for unit tests resources (config files, etc)
  • DOC : for documentation files
  • TMP : for temporary files (generation tests, etc)

You can organize your project structure as you want

Example in a "templates.cfg" for C# ( only $SRC is used ) :

#--- Models
Entity class                ; ${BEANNAME}.cs                    ; ${SRC}/Models/${BEANNAME}     ; Models/Xxx_cs.vm                  ; *
Entity CreateViewModel      ; Create${BEANNAME}ViewModel.cs     ; ${SRC}/Models/${BEANNAME}     ; Models/CreateXxxViewModel_cs.vm   ; *
Entity UpdateViewModel      ; Update${BEANNAME}ViewModel.cs     ; ${SRC}/Models/${BEANNAME}     ; Models/UpdateXxxViewModel_cs.vm   ; *

#-- Controllers
Entity controller           ; ${BEANNAME}sController.cs         ; ${SRC}/Controllers            ; Controllers/Xxxcontroller_cs.vm       ; *

#-- Views
Index View                  ; Index.cshtml                      ; ${SRC}/Views/Home             ; Views/Home/Index_cshtml.vm            ; 1
List View                   ; List${BEANNAME}View.cshtml        ; ${SRC}/Views/${BEANNAME}s     ; Views/ListXxxView_cshtml.vm       ; *
Create View                 ; Create${BEANNAME}View.cshtml      ; ${SRC}/Views/${BEANNAME}s     ; Views/CreateXxxView_cshtml.vm     ; *
Update View                 ; Update${BEANNAME}View.cshtml      ; ${SRC}/Views/${BEANNAME}s     ; Views/UpdateXxxView_cshtml.vm     ; *
Application Layout          ; _Layout.cshtml                    ; ${SRC}/Views/Shared           ; Views/Shared/_Layout_cshtml.vm        ; 1

Q2 answer :

The simplest way is probably to have one Telosys project for each target project (to keep each project as small as possible).

But you can also create your own "global variables" and use them in a "big project" with a complex structure.

Example of specific variables definition (in "telosys-tools.cfg") :

ProjectVariable.MODULE_APPLICATION    = my-app
ProjectVariable.MODULE_DOMAIN         = my-domaine
ProjectVariable.MODULE_INFRASTRUCTURE = my-infrastructure

Example of usage in a "templates.cfg" file :

${MODULE_INFRASTRUCTURE}/${RES}/db
${MODULE_DOMAIN}/${SRC}/repository
${MODULE_APPLICATION}/${SRC}/handler 
lgu
  • 2,342
  • 21
  • 29
0

Q3 answer :

When you need a specific information for an attribute the simplest solution is to use a "tag".

You create any tag as you want (it's just a string starting with "#").

For example use "#exclude" tag for an attribute in the model :

 comment : string { #exclude } ;

and use it in the template file :

#if ( ! $attribute.hasTag("exclude") )
use attribute here
#end

See : https://doc.telosys.org/dsl-model/tags

lgu
  • 2,342
  • 21
  • 29
  • Thank you Laurent. Merci. Vous êtes un grand esprit. – Rad Oct 15 '21 at 08:37
  • I need to push this idea of generating code based on the Telosys model in a abp.io solution with many modules (each will have a solution structure like above) further. I would like to create an extension in Visual Studio that will help in configuring telosys-tools.cfg file. When you have a DDD based module with many features and each feature requires multiple entities, does that mean I need to have Telosys project per module and multiple Telosys models (one model per feature which will have multiple entities). So this complicates generation and I want to introduce vertical feature modeling – Rad Oct 15 '21 at 08:47
  • I see you working on telosys-editor-notepadplusplus UDL. I guess you will add keywords for .cfg files. I have a problem launching vscode from telosys CLI. This config doesn't work: EditorCommand = "E:/Program Files/Microsoft VS Code/Code.exe" $FILE. Notepad++ works as expected – Rad Oct 15 '21 at 09:13
  • I would like to explore 2 things: 1. to add ability to run c# code with $loader when I need more complex metadata transformation in VLT templates. I will check if there is a way to provide input argumets to a c# script which is compiled and executed using Roslyn compiler withing dotnet-script global tool https://dejanstojanovic.net/aspnet/2021/june/c-scripting-with-net-core-global-tool/ it would be cool to provide java to c# (global cli tool) bridge to execute some script and user stin/stio to send and receive output and inject it in VLT template. – Rad Oct 15 '21 at 09:34
  • Second thing is to allow to merge newly generated code (e.g. entity class) with previously generated entity class where you added some code. This could be done by creating #region somename.... #end region and that all code present outside these regions would be preserved. See: https://efg.loresoft.com/en/latest/regeneration/ So I would like to know if there would be a way to temporarily generate files in a TMPGEN folder and allow some "merge program to run" that will mege new code with previously generated code (with some code added by the developer) previously determine if merge is needed. – Rad Oct 15 '21 at 09:42
  • This is the code from EntityFrameworkCore.Generator tool that merges existing regions https://github.com/loresoft/EntityFrameworkCore.Generator/blob/2a0a52214853c343c73c08bafd36c27071c6e0bc/src/EntityFrameworkCore.Generator.Core/Templates/CodeTempl ateBase.cs#L45 – Rad Oct 15 '21 at 09:54
  • This is the code from EntityFrameworkCore.Generator tool that merges existing regions https://github.com/loresoft/EntityFrameworkCore.Generator/blob/2a0a52214853c343c73c08bafd36c27071c6e0bc/src/EntityFrameworkCore.Generator.Core/Templates/CodeTempl ateBase.cs#L45 protected virtual void MergeOutput(string fullPath, string outputContent) show that fullPath is an existing file and outputContent is the result of parsing the template (new content). RegionParser uses these namespaces: Microsoft.CodeAnalysis.CSharp; and Microsoft.CodeAnalysis.CSharp.Syntax; – Rad Oct 15 '21 at 10:11
  • This article: https://segmentfault.com/a/1190000040432188/en shows how you can run c# script using dotnet-script CLI tool. This is how to run a script and provide input arguments: dotnet script main.csx -- arg1 arg2 arg3 , you can pass arg1,arg2,arg3 as parameters to the script. Inside main.csx you can extraat args like this foreach(var args in Args) {Console.WriteLine(arg)}. I can probably work around missing interceptor for code merge by generating vlt .vm templates into a TMPGEN folder with the same structure as target folders and compare old (existing files) with newly generated content. – Rad Oct 15 '21 at 10:19