Custom Framework

Posts   
 
    
idas
User
Posts: 9
Joined: 16-Aug-2016
# Posted on: 12-Jan-2017 14:17:13   

At this time our application models are in an old tool and we would like to migrate them to LLBLGEN.

To generate the appropriate code I think we would need to develop a custom "Target Framework" with Custom templates to generate code for our business-layer, UI-layer and SQL. This way we can continue to use our framework.

I can create a new Framework (copy an exsting) in the Frameworks folder and rename it but there's (much) more to it than just that I suppose.

I'm new to LLBLGEN and don't know where to start so I'm looking for some pointers in the right direction.

Furthermore we would like to be able to add properties to Entity, Field, Relation types wich we would like to use when generating code. For instance, we would like to be able to add to the DotNetTypes so we can use our own DomainObject types, like Mailaddress, Url, Phonenumber, SmartDate etc.

thanks

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 12-Jan-2017 18:27:03   

Good to hear you are migrating to LLBLGen Pro. But to help you further, I need to know why are you migrating, because from your words you want to use your own framework?

Why not using one of the supported frameworks?

idas
User
Posts: 9
Joined: 16-Aug-2016
# Posted on: 12-Jan-2017 18:54:57   

We have already developed many applications using this framework in the past 6 years so we cannot switch to another framework.

We do however need a new tool to make our models in and generate code from. That's what we would like to use LLBLGEN for...

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 13-Jan-2017 09:56:07   

Ok, you need to use templates, templateBindings, Tasks, TaskGroups and Presets. Ref: SDk Documentation

Templates First let's start with the Templates as the name implies is what you need to write to generate every piece of code. (a template for each type of classes). Templates can be Edited in the Designer

Then you create a templatebindings file to assign unique IDs for the templates you are using in your project..
You can also do that in the designer by opening the templatebindings editor

Keep in mind that the designer can only see your templates if you store them in a folder which is defined as the AdditionalTemplates folder in the project settings. When you have refreshed the code generation meta data in the designer after saving your templatebindings file you should see it in the templatebindings viewer. If not, please check whether the file is indeed stored in a folder reachable from the AdditionalTemplates Folder in the project settings.

Tasks Most probably you won't need to define new tasks, as you can find code emitting, folder creation and VS project file creation tasks already shipped.

Presets But you need to define your Preset Which defines which tasks/group of tasks to execute when you Run/Executes the Code Generation process using this preset, and the value of their parameters, like which template to use for this task.

You can examine any of the shipped Presets, like the "Adapter...." ones, by going to the Presets Viewer in the Tools menu of the Designer. There you can create a New Preset, Edit it to define the tasks that you need to execute when generating the code. Save your preset in a folder which is reachable from the 'Additional Tasks' folder in the project settings.

That's it, please let us if it has worked out with you.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 13-Jan-2017 16:31:21   

Additionally to the files mentioned by Walaa, to support a new framework, you also need a .framework file and a .frameworksettings file. See: http://www.llblgen.com/Documentation/5.1/SDK/implement3rdpartyorm.htm. Optionally you can add a validator if you want.

It's perhaps a good idea to look at the Entity Framework core files as a starting point as these are rather small. The sourcecode archive available for v5.x on the website under 'My Account -> downloads' contains the validator sourcecode for all supported orms, so you can look into these how to create a validator if you want to generate errors for e.g. features supported by the designer but not by your framework.

In the designer's Frameworks folder you have to place the .framework and .frameworksettings file. The latter is used for the settings in the project settings for the framework and which are also available in templates.

If you run into problems, don't hesitate to ask. The system might be a bit complex at first but once you see a bit how things work together it's straightforward.

Frans Bouma | Lead developer LLBLGen Pro
idas
User
Posts: 9
Joined: 16-Aug-2016
# Posted on: 18-Feb-2017 11:43:24   

Hi Otis,

I dit have a look at the .framework and .frameworksettings file and created a custom version.

But before starting with validation or code generation I'm wondering how I can add custom-properties to the LLBLGEN model.

For instance, on an Entity-Field, I would need to be able to store a DatabaseType (D_BOOLEAN, D_PHONENUMBER, D_STREET, etc..) and BusinessObjectType (string, int32, PhoneNumber, Amount, ...) and a (.NET) type (string, int32, decimal)

BusinessObjectType would be the type of the property in our Csla businessObject, our Database layer will then convert the value of the field back-and-forth to a standaard SQLdatabase-type when handling database actions.

Example:

Field Status in the Order Entity will have DatabaseType D_ENUM and BusinessObjectType OrderStatus (= enumeration) and will be stored in the (SQL or Firebird) database as an Int32 (of even as as varchar)

To generate code for our framework we need this type of extra information at field-, Entity- and relationship level. Is this possible with LLBLGEN ? Can you tell me

If my explanation isn't clear to you I'd be more than happy to explain further, maybe in a chat or via phone/skype

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 21-Feb-2017 08:30:18   

Would these be set manually in the designer for each field? or would they be automatically generated and set in code?

idas
User
Posts: 9
Joined: 16-Aug-2016
# Posted on: 21-Feb-2017 09:43:53   

These would be set in the designer for each field, some for each entity and some for each relation.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 21-Feb-2017 17:10:59   

Ok, how is this information retrieved or stored in code? Through attributes perhaps? As it sounds like you can also use a central readonly storage (e.g. a singleton object which is readonly) which gives you the information you need based on relationship/entity/field input. You can then simply generate code which builds up the data used by that singleton with 1 template from the mappings/entitymodel ?

Frans Bouma | Lead developer LLBLGen Pro
idas
User
Posts: 9
Joined: 16-Aug-2016
# Posted on: 21-Feb-2017 22:01:34   

Do you mean to seperately store this extra information somewhere else, 'outside' or 'away' of the LLBLGEN model not visible at design-time ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 22-Feb-2017 17:36:55   

Yes, in a separate code file you generate with a separate template. That's also why I asked how you would like to use the data at runtime: through attributes (and thus reflection) or otherwise. As I don't have a clear picture how the resulting code will look like, so I can't advise you what to do to get that resulting code generated wink

Frans Bouma | Lead developer LLBLGen Pro
idas
User
Posts: 9
Joined: 16-Aug-2016
# Posted on: 23-Feb-2017 10:21:22   

Otis,

Now you've lost me... Is it possible to have a short conversation over the phone?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 23-Feb-2017 16:28:19   

idas wrote:

Otis,

Now you've lost me... Is it possible to have a short conversation over the phone?

No, as discussing code over the phone is not really productive simple_smile

What I meant was this: the extra information you're trying to generate how does the code look like which contains that information? How do you plan to use it in your code? So how does this look like in code:

DatabaseType (D_BOOLEAN, D_PHONENUMBER, D_STREET, etc..) and BusinessObjectType (string, int32, PhoneNumber, Amount, ...) and a (.NET) type (string, int32, decimal)

Do you want to use attributes on the field properties / entity classes which contain "D_BOOLEAN" etc., or do you want to generate extra methods / properties which return these data elements, or do you want to define a string or something in code which returns DatabaseType(D_BOOLEAN...) ?

Please write that out for us so we have an idea what that looks like. It might very well be (e.g. if you go the attribute route) that you don't need to generate code as it's already built-in, hence my question simple_smile

Frans Bouma | Lead developer LLBLGen Pro
idas
User
Posts: 9
Joined: 16-Aug-2016
# Posted on: 23-Feb-2017 22:23:18   

Hi Otis,

There seems to be some sort of problem getting my message across, that's why I suggested we call, we can speak dutch and not discuss code but my additional needs in the designer...

I'm not trying to generate this extra information, I'm not yet trying to generate any code.

This extra information is information (properties) which I need to be able to enter and store in de designer, let's say for instance that I'm adding a Field to an Entity, I enter the name, order, type, Is PK, Optional, ReadOnly etc... in addition I want/need to be able to store DatabaseType, BusinessObjectType, .NETtype.

For example: Let's say I want to add a the field Status to Invoice, I'd need to be able to enter the following information.

Name "Status" Order
Type System.Int32 IsPk false Optional false ReadOnly false Max Length N/A Precision N/A Scale N/A Description N/A IsFK N/A *DatabaseType D_ENUM *BusinessObjectType Interfaces.Enums.EInvoiceStatus *NETType System

the first 11 are avaible in the designer, but I'm wondering how we could store the other 3 properties for each field as we absolutely need those for our code-gen.

A similar case can be made for Entity and Relation in wich we also need to be able to store additional information.

I hope I've made it a bit more clear this way, if not please let me know.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 24-Feb-2017 10:46:10   

idas wrote:

Hi Otis,

There seems to be some sort of problem getting my message across, that's why I suggested we call, we can speak dutch and not discuss code but my additional needs in the designer...

I'm not doing phone calls in general and definitely not if there's even a small chance some code has to be discussed or I have to point you to a URL. But I think I have a proper picture. My previous assumption was that you wanted to extend the code generated by the designer for the 4 frameworks, but you want to effectively add another framework.

I'm not trying to generate this extra information, I'm not yet trying to generate any code.

This extra information is information (properties) which I need to be able to enter and store in de designer, let's say for instance that I'm adding a Field to an Entity, I enter the name, order, type, Is PK, Optional, ReadOnly etc... in addition I want/need to be able to store DatabaseType, BusinessObjectType, .NETtype.

For example: Let's say I want to add a the field Status to Invoice, I'd need to be able to enter the following information.

Name "Status" Order
Type System.Int32 IsPk false Optional false ReadOnly false Max Length N/A Precision N/A Scale N/A Description N/A IsFK N/A *DatabaseType D_ENUM *BusinessObjectType Interfaces.Enums.EInvoiceStatus *NETType System

the first 11 are avaible in the designer, but I'm wondering how we could store the other 3 properties for each field as we absolutely need those for our code-gen.

A similar case can be made for Entity and Relation in wich we also need to be able to store additional information.

There are two ways to extend the data in the entity model: through custom properties, which are simple name-value strings, and settings. Settings are name-value pairs where the value can be typed and e.g. be selected from a list, you can use defaults etc.

The 'custom properties' can be applied to the project (entity model), entities and the like and fields. Settings can be applied to project, entities (and typedlists,typedviews etc.) , fields, navigators etc. This is all described in the SDK: http://www.llblgen.com/Documentation/5.1/SDK/Frameworksandsettings.htm

This has already been discussed above, so I don't know if you have looked at it yet. It describes what files you have to create for another framework. You can use that to further understand how the existing files work.

It's really straight forward, but the files discussed in the SDK are the minimum amount of files you have to create. It's also not done in an afternoon: you have to define the framework itself, the frameworksettings file, the validator dll (which can be simple btw), the templatebindings for the templates and the templates itself, and a preset file which dictates which tasks to run which which templateids. All files are pre-filtered on the framework name, so if the entity model uses your framework, the files used, like templatebindings, presets, the validator etc. are all filtered, so they have to contain the name of your framework as the supported framework.

The settings in a .frameworksettings file show up as a setting on the element(s) they're defined for and you can alter their values in the designer.

Now to the part where I kept asking how the generated code would look like: you already know that, as the code in your existing framework is the code you need to generate. This thus means you want to add support for your existing framework to the designer: as an entitymodel target framework (similar to EF, LLBLGen Pro etc.). To write the templates, it's crucial you know how the code looks like that these templates have to generate.

It also means that if the code you're generating are e.g. poco classes with attributes on class / property etc., you can also choose to define attributes in the attribute system of the designer, and not through settings.

Frans Bouma | Lead developer LLBLGen Pro
idas
User
Posts: 9
Joined: 16-Aug-2016
# Posted on: 28-Mar-2017 08:22:26   

Hi Otis,

Thanks for your last post it was very helpful. I can now add custom properties to fields and entities however I cannot yet see how I can add custom properties to a relation as it seems there's no targettype for it. Am I correct ?

http://www.llblgen.com/Documentation/5.1/SDK/definingcustomsettings.htm

Best regards, Jurjen

idas
User
Posts: 9
Joined: 16-Aug-2016
# Posted on: 28-Mar-2017 08:34:27   

Hi Otis,

Is it possible within a customsetting for Entity to make a selection from a field-list, the fields from that entity ?

We have for instance a customSetting DisplayMember for wich the value is one of the fields from the entity, it would be nice if we could select the value from a dropdownlist instead of having to type in the fieldname by hand.

Best regards, Jurjen

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 28-Mar-2017 16:56:07   

idas wrote:

Thanks for your last post it was very helpful. I can now add custom properties to fields and entities however I cannot yet see how I can add custom properties to a relation as it seems there's no targettype for it. Am I correct ?

http://www.llblgen.com/Documentation/5.1/SDK/definingcustomsettings.htm

Correct, you should add them to navigators (the fields mapped onto the relationships), as those are the ones used in the output anyway. E.g. the relationship Customer.Orders 1n Order.Customer has 2 navigators, so you can add the info to both.

idas wrote:

Is it possible within a customsetting for Entity to make a selection from a field-list, the fields from that entity ?

We have for instance a customSetting DisplayMember for wich the value is one of the fields from the entity, it would be nice if we could select the value from a dropdownlist instead of having to type in the fieldname by hand.

That's sadly not possible, the settings are statically defined, not dynamically populated...

Frans Bouma | Lead developer LLBLGen Pro