Search code examples
sdkgenexus

GeneXus Extension: List properties of all Generators in a KB - (PropertyName, PropertyValue)


I need to iterate through all the properties of all the generators of a KB in a GeneXus Extension.

I would like to understand how the KB / Version / Environment / Models / Generator are modeled in Gx16 and Gx17.

Does anyone have an example in C# of how to list the properties of a generator?

To list the properties of the KB, I am using the code:

foreach (Property kbp in UIServices.KB.CurrentKB.Properties.Properties)
   {
    string kbpvalue = "";
    if (kbp.Value != null)
         kbpvalue = kbp.Value.ToString();
    writer.AddTableData(new string[] { "KB", kbp.Name, kbpvalue, kbp.IsDefault.ToString()}) ; 
   }

I need the equivalent to Generator properties.


Solution

  • All properties are handled through the PropertiesObject class itself, or eventually subclasses of it.

    Accessing KB properties is pretty straightforward, given a KnowledgeBase instance, the KB properties are under the Properties property. e.g.

    PropertiesObject kbProps = UIServices.KB.CurrentKB.Properties;
    

    Version and Environment properties are modeled in the KBModel class which is a subclass of PropertiesObject. The difference between a Version and a Environment is that the former has the Type set to Design, while the later is Prototype. For a UI package, the most convenient way to access the active Version, and the active Environment is:

    KBModel design = UIServices.KB.CurrentModel;
    KBModel target = design.Environment.TargetModel;
    

    Here design is a KBModel whose Type property is Design, and it represent the version properties, and target is also a KBModel but it's Type property is Prototype. In the SDK you may find that the name target referring to a prototype KBModel is used interchangeably with working.

    DataStore and Generator properties are another thing. Both concepts are represented by KBObjects, so there is a DataStoreCategory object and a GeneratorCategory object. The peculiarity with these objects, is that they don't have too many properties. The most commonly used properties in DataStores and Generators are properties dependent on the target Environment. In order to access those Environment dependent properties, you can use GxDataStore and GxGenerator classes, that can be requested to the corresponding model part. e.g.

    KBModel design = UIServices.KB.CurrentModel;
    KBModel target = design.Environment.TargetModel;
    
    foreach (GxGenerator gen in target.Parts.Get<GeneratorsPart>().Generators)
    {
        gen.Properties....
    }
    
    foreach (GxDataStore ds in target.Parts.Get<DataStoresPart>().DataStores)
    {
        ds.Properties....
    }
    

    The properties in GxDataStore and GxGenerator are loaded dynamically based on the type of data store or generator. That's the reason for the properties to be under a Properties property, and not having GxDataStore and GxGenerator inherit from PropertiesObject themselves.

    The last thing to mention, all these names are valid in GX 17. For generators particularly, there was a big rename in APIs from GX 16 to 17, due to the names used in the previous version not aligned properly with the conceptual model. The details of everything that was renamed from GX 16 to 17 is summarized here.