Saving my own code

Posts   
 
    
eugene
User
Posts: 85
Joined: 05-Oct-2004
# Posted on: 13-Jan-2005 15:25:56   

Hi there at the forum,

I am using the adapter model together with the SubClass template. When I need to regenerate my code I have on the one hand to have changes in the sub classes (reflecting changes in the relationships between the entities) and on the other hand I need to preserve my own code. I am using a merge tool at the moment (winmerge from sourceforge) but this is really a lot of work to do (1000+ entities). Are there any alternative methods to achieve this? Currently I generate in an alternative folder and then compare the generated sub classes with my original ones. I am certain that .NET 2.0 with partial classes will render this problem obselete but I cannot really wait until then.

Thank you very much for your ideas on this.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-Jan-2005 17:12:09   

This is addressed within a month when the codeemitter taskperformer is updated with code which merges code in a predefined region into the generated code being generated at that moment. The other way is include templates, but that can be problematic if you have a lot of custom code per entity which is unique per entity.

You can work around that, by writing code like:

<[If StringValueEquals CurrentEntityName "Order"]> <# OrderEntityInclude #> <[EndIf]>

etc.

in the include template you include in the entity class. This way you can simply re-generate your code and everything is merged in.

Frans Bouma | Lead developer LLBLGen Pro
eugene
User
Posts: 85
Joined: 05-Oct-2004
# Posted on: 13-Jan-2005 17:17:02   

Dear Otis,

it is quite comforting to know that you are planning is (mostly!!!) ahead of the your customers thoughts!!!

Greetings

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-Jan-2005 20:28:31   

eugene wrote:

Dear Otis,

it is quite comforting to know that you are planning is (mostly!!!) ahead of the your customers thoughts!!!

smile . (do not tell anyone, but I read in an article that good code-generators should preserve added usercode, so I found out the code generator lacked a serious feature! simple_smile )

Frans Bouma | Lead developer LLBLGen Pro
eugene
User
Posts: 85
Joined: 05-Oct-2004
# Posted on: 14-Jan-2005 13:39:45   

Dear Otis,

I guess the ability to merge code needs not to be considered as essential. (maybe a great nice-to-have). First it is quite problematic to get things right while merging files. Also, maybe it is not needed after all, should you be able to seperate generated and user code in seperate files (self-servicing is a great example of this!). This should be easier with .NET 2.0.

I am working with the adapter using the subclasses template, and currently it is quite difficult to keep the code up to date (reflecting the changes in the DB and in the .lgp file) while preserving my changes.

I didn't understand the solution you describe in your posting.

 <[If StringValueEquals CurrentEntityName "Order"]>
<# OrderEntityInclude #>
<[EndIf]>

Take for example the entity CustomerEntity with the properties Name and Surname. In MyCustomerEntity I would write a property, FullName that returns a concatanation of Name and Surname while considering some rules.

Now assume the table Customer in the DB is modified by adding a new relationship to table Discounts. This would need to be reflected in the MyCustomerEntity (Prefetch and Members).

Would using the include template you mention save my user code, while appending the generated code?

Thank you in advance for your reply and have a nice weekend!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 14-Jan-2005 14:09:26   

eugene wrote:

I guess the ability to merge code needs not to be considered as essential. (maybe a great nice-to-have). First it is quite problematic to get things right while merging files. Also, maybe it is not needed after all, should you be able to seperate generated and user code in seperate files (self-servicing is a great example of this!). This should be easier with .NET 2.0.

What the plan is is that in the template regions are defined for user code. When emitting the code, an exisiting file is read, the same regions are read and copied over to the text to write, which effectively means the code you write in these regions is preserved between code generation. I think that's the main point, and would release you from the burdon of keeping track of your own code.

I didn't understand the solution you describe in your posting.

 <[If StringValueEquals CurrentEntityName "Order"]>
<# OrderEntityInclude #>
<[EndIf]>

Take for example the entity CustomerEntity with the properties Name and Surname. In MyCustomerEntity I would write a property, FullName that returns a concatanation of Name and Surname while considering some rules.

Now assume the table Customer in the DB is modified by adding a new relationship to table Discounts. This would need to be reflected in the MyCustomerEntity (Prefetch and Members).

Would using the include template you mention save my user code, while appending the generated code?

You write your FullName property in the template customerInclude.template for example. Then you define an include file for the entities (as one template is included in the entity template). This is simply a template with solely <[If StringValueEquals CurrentEntityName "Order"]> <# OrderEntityInclude #> <[EndIf]> statements, so in your case thus also: <[If StringValueEquals CurrentEntityName "Customer"]> <# CustomerEntityInclude #> <[EndIf]>

Now, you have to create a new templateset config based on an existing one where you ADD the template bindings of for example CustomerEntityInclude, and also the binding of Custom_EntityAdapterTemplate, which is the ID of the template to include in each entity class.

Now, Custom_EntityAdapterTemplate you bind to the template with the <[If StringValueEquals... statements. CustomerEntityInclude you bind to a file, for example the mentioned, customerInclude.template, which contains: public string FullName { get { return this.FirstName + " " + this.LastName; } }

When you then generate your code, the code generator will first merge the template customerInclude.template into the template you bound to Custom_EntityAdapterTemplate, at the spot <# CustomerEntityInclude #> (thus still surrounded by the ifstatement). Then, that merge result is merged with the template for adapter entities at the spot where Custom_EntityAdapterTemplate is included (at the bottom). THEN the template is ran. For customer entities only the statement <[If StringValueEquals CurrentEntityName "Customer"]> will be true, so only in customer templates, the contents of customerInclude.template is emitted into the output stream (and thus ending up in your customer entity code file simple_smile ).

This way you can control which code goes in which entity and you don't have to work with a large file. To develop this kind of code, first write the code you want to emit into the generated code, compile it, then go to templatestudio and create a template and copy over the code, in this case the property of Fullname.

Thank you in advance for your reply and have a nice weekend!

You too! simple_smile

Frans Bouma | Lead developer LLBLGen Pro
eugene
User
Posts: 85
Joined: 05-Oct-2004
# Posted on: 28-Jan-2005 12:19:08   

Dear Otis,

you mentioned in a previous posting that an update of the codeemitter taskperformer will be released that uses predefined regions in order to merge user code with generated code. As the number of modified Extended Entities (really a great feature smile ) in use grows I am having trouble keeping track of the all the changes. When do you expect this update to be released?

Best regards and a nice weekend!

N. Brake

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 28-Jan-2005 13:11:53   

eugene wrote:

Dear Otis,

you mentioned in a previous posting that an update of the codeemitter taskperformer will be released that uses predefined regions in order to merge user code with generated code. As the number of modified Extended Entities (really a great feature smile ) in use grows I am having trouble keeping track of the all the changes. When do you expect this update to be released?

Estimated date as about now, new estimated date is end of february, as I lost almost 2 weeks with the typedlist editor which had to be updated and which took way longer than expected, plus I want to move some functionality into this update which was planned for april/may, namely expression editing in the designer.

Frans Bouma | Lead developer LLBLGen Pro
eugene
User
Posts: 85
Joined: 05-Oct-2004
# Posted on: 07-Mar-2005 10:27:42   

Dear Otis,

has this change been built into the March 5th upate of the installer? Where is it possible to obtain a complete list of fixes and changes? Do i need to uninstall my exisitng installtion prior to installing the new installer?

Best regards

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 07-Mar-2005 11:56:08   

eugene wrote:

Dear Otis,

has this change been built into the March 5th upate of the installer? Where is it possible to obtain a complete list of fixes and changes? Do i need to uninstall my exisitng installtion prior to installing the new installer? Best regards

No not yet, it will first go into beta, I estimate: wednesday or thursday, and will be promoted to the final installer end of march.

Frans Bouma | Lead developer LLBLGen Pro