I need to browse files in a directory using velocity syntax, while working with C#. No solution found yet for C# lang env. All relevant answers are regarding Java that requires to create a specific Java class to do that. A Java class can be used in a template with "$loader".
How can I tailor it according to C#?
.vm
json-from-file.vm - It's using $fn.fileFromBundle("foo.json") but:
Single File: $fn.fileFromBundle("foo.json") works for one file, but I need all JSONs (Product.json, Order.json). No Folder Scan: Telosys Velocity lacks a method to list files in a directory (e.g., no $fn.filesFromBundle()). My Snag: I kept trying to find a native Velocity way to browse TelosysTools\templates\json-to-entity—it doesn’t exist.
In fact, I want to create .entity files from .json files. telosys requires "ne EntityName" to create empty .entity file. One command per entity. I have created a .txt file that will create .entity files using json-to-entity.vm for all the json files placed in adirectory. And then gen * *.
telosys-cmd.txt:
m product-model
b json-to-entity
gen * * -y
b csharp-bundle
gen * * -y
exit
Is there any way to achieve this using json-from-file.vm
I need to browse files in a directory using velocity syntax, while working with C#. No solution found yet for C# lang env. All relevant answers are regarding Java that requires to create a specific Java class to do that. A Java class can be used in a template with "$loader".
How can I tailor it according to C#?
https://github/telosys-templates/text-files-usage/blob/master/json-from-file.vm
json-from-file.vm - It's using $fn.fileFromBundle("foo.json") but:
Single File: $fn.fileFromBundle("foo.json") works for one file, but I need all JSONs (Product.json, Order.json). No Folder Scan: Telosys Velocity lacks a method to list files in a directory (e.g., no $fn.filesFromBundle()). My Snag: I kept trying to find a native Velocity way to browse TelosysTools\templates\json-to-entity—it doesn’t exist.
In fact, I want to create .entity files from .json files. telosys requires "ne EntityName" to create empty .entity file. One command per entity. I have created a .txt file that will create .entity files using json-to-entity.vm for all the json files placed in adirectory. And then gen * *.
telosys-cmd.txt:
m product-model
b json-to-entity
gen * * -y
b csharp-bundle
gen * * -y
exit
Is there any way to achieve this using json-from-file.vm
Share Improve this question edited Mar 27 at 13:05 saibin asked Mar 27 at 12:16 saibinsaibin 254 bronze badges1 Answer
Reset to default 0Telosys is written in Java. Therefore, it only supports extensions written in Java and loaded with $loader in a template file.
So, you'll need to create and compile a small Java8 utility class to retrieve the files located in a given directory. It's quite simple; you'll find many examples online.