When creating an activity, it could be possible that a new entity for the properties, or result variable is needed.
It's possible to add an extra element to the Plugin datasources within the component.
Let's say we want to provide an extra option in our activity to provide an entity with the filename and play mode as attributes.
We need to take the following steps
1. Define guid(s) for entities to add
2. Add "Codolex.Activity.YourActivityName.DefinedEntity.pas".
3. Add entities to generate action to the '...Component.Pas'.
4. Call entities to add in the '...Puggable.pas'.
5. Extra info
Go to the 'Component.Interfaces.pas' file, and add a const section to the interfaces. Use Ctrl+Shift+G to generate a guid for every entity
interface
uses ...;
const PlaySoundConfigGuid = '{55FC2C2E-AB35-4BD2-ABC4-F6950FE10A0D}'; |
Add a new unit, and use the following code in the unit (Replace playsound with your activity name)
unit Codolex.Activity.PlaySound.DefinedEntities;
interface
uses DataModel.Entity.Interfaces, Codolex.Spring.Collections;
type TCreateDataEntityFunc = reference to function(const Name: string): IDataEntity;
TPlaySoundDefinedEntities = class private class function CreatePlaySoundConfig(const CreateEntity: TCreateDataEntityFunc): IDataEntity;
public class procedure Get(const Entities: IDictionary<string, IDataEntity>; const CreateEntity: TCreateDataEntityFunc); end;
implementation
uses DataModel.DataTypes.Defines;
{ TPlaySoundDefinedEntities }
class procedure TPlaySoundDefinedEntities.Get(const Entities: IDictionary<string, IDataEntity>; const CreateEntity: TCreateDataEntityFunc); begin var PlaySoundConfig := CreatePlaySoundConfig(CreateEntity); Entities.Add(PlaySoundConfig.Name, PlaySoundConfig);
//repeat this for as many entities as you need end;
class function TPlaySoundDefinedEntities.CreatePlaySoundConfig(const CreateEntity: TCreateDataEntityFunc): IDataEntity; begin Result := CreateEntity('PlaySoundConfig'); Result.Guid := PlaySoundConfigGuid;
Result.AddStringField('FileName', '{4061BAB6-EE7E-4D62-B78D-33A07166C4B6}'); Result.AddStringField('PlayMode', '{1DBACDBA-5A4B-4072-A80-2FE703194F01}'); end;
end. |
In the Component.pas add the following files to the interface uses:
- DataModel.Entity.Interfaces,
- Codolex.Spring.Collections,
Add the
Add the following class procedure to the protected functions
class procedure DefineEntities(const Entities: IDictionary<string, IDataEntity>); override; |
Add the created unit 'Codolex.Activity.PlaySound.DefinedEntities;' to the implementation uses section.
This makes it possible to call the class function Get From the unit.
class procedure DefineEntities(const Entities: IDictionary<string, IDataEntity>); override; begin inherited; TPlaySoundDefinedEntities.Get(Entities, CreateDataEntity); end; |
In the Pluggable.pas add the following files to the interface uses:
- DataModel.Entity.Interfaces,
- Codolex.Spring.Collections,
Add the interface IFlowComponentWithDataEntities to the list of used interfaces for the plugin object.
Add the following class procedure to the public functions
function GetDataEntities: IReadOnlyCollection<IDataEntity>; |
Implement the function by calling the GetDefinedEntities function from the component
function TPlaySoundPluggableComponent.GetDataEntities: IReadOnlyCollection<IDataEntity>; begin Result := TFlowActivityPlaySound.GetDefinedEntities.Values; end; |
This ensures the entities are created when the plugin is loaded into codolex.
It's possible to add multiple entities this way, and it's also possible to add associations between those entities.
To add an association, use the following code:
... var Association := ParentEntity.AddAssociationAsParent(ChildEntity);
Association.Guid := //Generate a guid; Association.AssociationType := TAssociationType.OneToMany; //one to one is also possible Association.ChildName := 'ChildNameAssociation'; Association.Name := 'AssiciationName'; ... |