UserCodeRegion in LogicCSharp templates

Posts   
 
    
Posts: 12
Joined: 22-Nov-2005
# Posted on: 13-Mar-2006 23:13:36   

Is it possible to include user code regions to LogicCSharp templates? Or is this only possible with TDL templates?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39776
Joined: 17-Aug-2003
# Posted on: 14-Mar-2006 10:45:05   

You can do that, please consult the SDK documentation on this:

Template sets -> Lpt templates engine (.lpt templates)

User code regions To emit user code regions into the output, use the following method: DotNetTemplateEngine.GetUserCodeRegion(string name, string commentToken);

Example: <%=DotNetTemplateEngine.GetUserCodeRegion("Testregion", "//")%>

Frans Bouma | Lead developer LLBLGen Pro
Posts: 12
Joined: 22-Nov-2005
# Posted on: 16-Mar-2006 02:03:45   

Is this supposed to maintain code manually added to these sections between code generation runs? Everytime I rerun the code generation the code added to this section always gets removed. Is there an additional setting that I am missing?

In the template I have

        #region User functions
        
<%=DotNetTemplateEngine.GetUserCodeRegion("UserFunctionsRegion", "//")%>

        #endregion

On the task performer I am using these sections


            <task name="EntityManagerBaseGenerator" assemblyFilename="SD.LLBLGen.Pro.LptParser.dll" taskPerformerClass="SD.LLBLGen.Pro.LptParser.DotNetTemplateEngine">
                <parameter name="destinationFolder" value="Managers\Base"/>
                <parameter name="failWhenExistent" value="false"/>
                <parameter name="filenameFormat" value="[elementName]ManagerBase.[extension]"/>
                <parameter name="templateAssemblySourceFileFormat" value="templateClassesSource.[extension]"/>
                <parameter name="templateID" value="EntityManagerBaseTemplate"/>
                <parameter name="emitType" value="allEntities"/>
            </task>
Posts: 12
Joined: 22-Nov-2005
# Posted on: 16-Mar-2006 02:31:07   

Sorry ignore that comment. It seems that when you edit the .cs files with Textpad and save it the default encoding it is using might be getting ignored by LLBLGen.

When I edit one of the code files in VS.NET 2003 LLBLGen does not over write the code changes.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39776
Joined: 17-Aug-2003
# Posted on: 16-Mar-2006 08:26:35   

nikolaiblackie wrote:

Sorry ignore that comment. It seems that when you edit the .cs files with Textpad and save it the default encoding it is using might be getting ignored by LLBLGen.

When I edit one of the code files in VS.NET 2003 LLBLGen does not over write the code changes.

That's strange. Do you by any chance have a different endmarker set in textpad? (so no CRLF but just a LF like on unix?)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 12
Joined: 22-Nov-2005
# Posted on: 19-Mar-2006 23:31:04   

Well I have checked the editor settings and I can't see anything related to endmarkers. I assume that Textpad would leave the endmarker as CRLF.

The only setting I can see is that it saves files in ANSI encoding, and the files appear to be generated as UTF-8.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39776
Joined: 17-Aug-2003
# Posted on: 20-Mar-2006 09:01:55   

Hmm. Well, the parser just loads the original file, scans it for the begin/end markers of the user code regions, and stores each user code region contents with the name of the region in a hashtable. When the code is then re-generated and a user code region with name X is to be inserted, it looks up the name in the hashtable and inserts hte contents if it's present in the hashtable. I don't see where encoding can be a problem, unless you give your user code regions names with characters which aren't part of the standard 127char ascii table.

Frans Bouma | Lead developer LLBLGen Pro
mille562
User
Posts: 1
Joined: 24-Jul-2007
# Posted on: 24-Jul-2007 19:20:23   

There is a problem with encodings. If you set your project's EncodingToUse = ASCII, the UserCodeRegions in a LPT template can wiped out.

Reason: This is because the original file is ALWAYS read in as Unicode. DotNetTemplateEngine.TestFileCanBeOverwritten reads the original file using the DotNetTemplateEngine._encodingToUse variable, which is set to Encoding.Unicode and never changed.

When the template output is written, it uses a local _encodingToUse variable that is set to the encoding of the project.

So if the project is set to ASCII, the file is written in ASCII. When the file is regenerated, the original file is read in Unicode which does not allow regex to always properly match the usercode regions so they can be wiped out.

Solution: Quick: Set your projects encoding to 'UTF8' or 'UNICODE'

Longer: Modify the DotNetTemplateEngine._encodingToUse variable to return the encoding of the project.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39776
Joined: 17-Aug-2003
# Posted on: 25-Jul-2007 12:24:27   

mille562 wrote:

There is a problem with encodings. If you set your project's EncodingToUse = ASCII, the UserCodeRegions in a LPT template can wiped out.

Reason: This is because the original file is ALWAYS read in as Unicode. DotNetTemplateEngine.TestFileCanBeOverwritten reads the original file using the DotNetTemplateEngine._encodingToUse variable, which is set to Encoding.Unicode and never changed.

When the template output is written, it uses a local _encodingToUse variable that is set to the encoding of the project.

So if the project is set to ASCII, the file is written in ASCII. When the file is regenerated, the original file is read in Unicode which does not allow regex to always properly match the usercode regions so they can be wiped out.

Solution: Quick: Set your projects encoding to 'UTF8' or 'UNICODE'

Longer: Modify the DotNetTemplateEngine._encodingToUse variable to return the encoding of the project.

That's a nasty bug, thanks for reporting. The encodingToUse shouldn't be declared locally of course, hence the '' in front of it, only member variables have that. So removing the 'Encoding' declaration in front of it at line 447 should fix this.

Frans Bouma | Lead developer LLBLGen Pro