Plugin coding issue - TypedLists

Posts   
 
    
renesisx
User
Posts: 44
Joined: 07-Aug-2006
# Posted on: 10-Aug-2006 16:36:57   

Hi guys,

So, I got my field renamer plugin working great for Entities yesterday.

This was the inner code - works great:

    For Each objEntity As EntityDefinition In MyBase.Entities
          For Each objField As EntityFieldDefinition In objEntity.Fields
            MyBase.ProgressSubtaskStart("Processing Entity Field: " & objEntity.Name & "." & objField.FieldName)
            objField.FieldName = Left(objField.FieldName, 1).ToLower & Mid(objField.FieldName, 2)
        Next

        MyBase.ProgressSubtaskComplete()
    Next

(the indenting doesn't show up in the Forum sadly...)

I'm trying to do the same job with the TypedLists though, here is the code which dies:

    For Each objTypedList As TypedLists.TypedListDefinition In MyBase.TypedLists
        For Each objEntityAlias As TypedLists.EntityAlias In objTypedList.EntityAliases
            MyBase.ProgressSubtaskStart("Processing TypedList EntityAlias: " & objTypedList.Name & "." & objEntityAlias.Alias)
            objEntityAlias.Alias = Left(objEntityAlias.Alias, 1).ToLower & Mid(objEntityAlias.Alias, 2)
        Next

        MyBase.ProgressSubtaskComplete()
    Next

Exception on the line "For Each objEntityAlias...":

Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'SD.LLBLGen.Pro.ApplicationCore.TypedLists.EntityAlias'.

Where am I going wrong?

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 10-Aug-2006 17:39:53   

Haven't played with TypedListDefinition yet, but from what the exception says, objTypedList.EntityAliases is an hastable, with elements being of type DictionaryEntry.

Each DictionaryEntry holds Key/Value properties, I guess the value will be what you're looking for.

So you may go:



For Each objDictionaryEntry As System.Collections.DictionaryEntry In objTypedList.EntityAliases

dim objEntityAlias As TypedLists.EntityAlias  = objDictionaryEntry.Value

etc... 


Not sure what the key stands for though, but you just have to check...

renesisx
User
Posts: 44
Joined: 07-Aug-2006
# Posted on: 10-Aug-2006 18:01:14   

Sadly, that's not the one..

Object reference not set to an instance of an object.

That's when I try to access "objEntityAlias.Alias"

This was my code (I had to DirectCast as my project is Option Strict On):

        For Each objDictionaryEntry As System.Collections.DictionaryEntry In objTypedList.EntityAliases
            Dim objEntityAlias As TypedLists.EntityAlias = DirectCast(objDictionaryEntry.Value, TypedLists.EntityAlias)

            MyBase.ProgressSubtaskStart("Processing TypedList EntityAlias: " & objTypedList.Name & "." & objEntityAlias.Alias)
            objEntityAlias.Alias = Left(objEntityAlias.Alias, 1).ToLower & Mid(objEntityAlias.Alias, 2)
        Next

It's a shame the plugin model doesn't use generics wink

Any other ideas?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 10-Aug-2006 18:05:33   

Key is alias name (the name you type in in the designer), value is an EntityAlias object.

Frans Bouma | Lead developer LLBLGen Pro
renesisx
User
Posts: 44
Joined: 07-Aug-2006
# Posted on: 10-Aug-2006 18:10:35   

Hey Otis,

The EntityAlias object appears to empty, or the Value property on the DictionaryEntry is..

Can you show me the correction I need to make to my code? I'm just trying to drop the first letter into lowercase...

Thanks

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 10-Aug-2006 18:47:53   

I don't know where precisely you'll find your Entityaliases, but it shouldn't be too hard browsing the objects at runtime.

You should place a break point and add a watch to examine the structure of the properties and find what you need.

Alternatively, loading your project with the project explorer from the template studio might give you some insights to.

Then, for the renaming, I'd suggest using the RenameAlias which probably holds some business logic, rather than doing it manually.

Hope that helps

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 10-Aug-2006 20:42:29   

renesisx wrote:

Hey Otis,

The EntityAlias object appears to empty, or the Value property on the DictionaryEntry is..

Can you show me the correction I need to make to my code? I'm just trying to drop the first letter into lowercase...

Thanks

You're absolutely correct, I didn't check the code, I should have done so.

EntityAliases contains as key the EntityAlias object, as value a null. So you can browse all EntityAlias objects by browsing the keys. It's used to check if an alias is already there.

There's also another hashtable, EntityToEntityAliases, don't know if you need that one, but it contains per entity in the typedlist (key) all EntityAlias objects in an arraylist as value. So pick either one simple_smile

It doesn't use generics because I didn't want to port all designer code over to .NET 2.0 generic constructs just to use generics wink .

A tip: right-click the project node in the project explorer and select the project inspector plugin, it will show you the live Project object graph, which can help you with what is stored where.

Frans Bouma | Lead developer LLBLGen Pro
renesisx
User
Posts: 44
Joined: 07-Aug-2006
# Posted on: 11-Aug-2006 15:05:04   

OK, let me fill you in more on what I'm trying to do and we'll see if we can crack this!

I changed to use the Key property, but now it dies on the MyBase.ProgressSubtaskComplete() line with "Value of '1' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'. Parameter name: Value"

Here is the chunk of my code:


        For Each objTypedList As TypedLists.TypedListDefinition In MyBase.TypedLists
            For Each objDictionaryEntry As System.Collections.DictionaryEntry In objTypedList.EntityAliases
                Dim objEntityAlias As TypedLists.EntityAlias = DirectCast(objDictionaryEntry.Key, TypedLists.EntityAlias)

                MyBase.ProgressSubtaskStart("Processing TypedList EntityAlias: " & objTypedList.Name & "." & objEntityAlias.Alias)
                objEntityAlias.Alias = Left(objEntityAlias.Alias, 1).ToLower & Mid(objEntityAlias.Alias, 2)
            Next

            MyBase.ProgressSubtaskComplete()
        Next

Essentially what I'm trying to do is as follows...

When creating a Typed List in the designer I set up the fields I want in the "Fields Mapped On Entity Fields" tab. There is a column called "Field Alias" and this contains the name of the .NET Properties that will be created. I'm trying to rename those with my plug-in.

I've had no problems renaming the field names on the standard Entities - that code works perfectly - I'm just a bit stuck trying to find the right properties on the TypedList object!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 12-Aug-2006 13:54:06   

renesisx wrote:

OK, let me fill you in more on what I'm trying to do and we'll see if we can crack this!

I changed to use the Key property, but now it dies on the MyBase.ProgressSubtaskComplete() line with "Value of '1' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'. Parameter name: Value"

Here is the chunk of my code:


        For Each objTypedList As TypedLists.TypedListDefinition In MyBase.TypedLists
            For Each objDictionaryEntry As System.Collections.DictionaryEntry In objTypedList.EntityAliases
                Dim objEntityAlias As TypedLists.EntityAlias = DirectCast(objDictionaryEntry.Key, TypedLists.EntityAlias)

                MyBase.ProgressSubtaskStart("Processing TypedList EntityAlias: " & objTypedList.Name & "." & objEntityAlias.Alias)
                objEntityAlias.Alias = Left(objEntityAlias.Alias, 1).ToLower & Mid(objEntityAlias.Alias, 2)
            Next

            MyBase.ProgressSubtaskComplete()
        Next

You start a subtask task on the progressbar in a loop but only close it once. Every ProgressSubtaskStart has to have a ProgressSubtaskComplete() call. It's in general not of great value to enlist which entity is being processed as the task description, as it's in general very fast so before you've read the first characters of the text, it's already updated.

Essentially what I'm trying to do is as follows...

When creating a Typed List in the designer I set up the fields I want in the "Fields Mapped On Entity Fields" tab. There is a column called "Field Alias" and this contains the name of the .NET Properties that will be created. I'm trying to rename those with my plug-in.

I've had no problems renaming the field names on the standard Entities - that code works perfectly - I'm just a bit stuck trying to find the right properties on the TypedList object!

The fields of a typedlist are stored in the collection returned by the Fields property. This property returns a TypedListFieldsCollection which contains TypedListFieldDefinition objects. Simply traverse these and rename these objects' Alias property. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
renesisx
User
Posts: 44
Joined: 07-Aug-2006
# Posted on: 01-Sep-2006 17:02:30   

You were right about me not setting the SubTasks complete. I didn't spot that simple_smile

And thanks - the info on the TypedList fields got me what I needed.

Cheers!