-
Notifications
You must be signed in to change notification settings - Fork 6
plugin sdk entity mappings
The EntityMappings property is a List<EntityMapping> collection on the Role entity that allows plugins to store custom configuration data or metadata associated with specific entities. This is a plugin-specific feature for maintaining private data relationships between your plugin role and other entities in Security Center.
Think of EntityMappings as private custom fields that belong to your role. While Security Center's custom fields are system-wide and visible to all applications, EntityMappings allow your role to maintain its own private data associated with any entity. This data is only accessible through your role and won't interfere with other applications or system-wide configurations.
The EntityMapping class contains three key properties:
public class EntityMapping
{
public Guid LocalEntityId { get; set; }
public Guid RoleId { get; set; }
public string XmlInfo { get; set; }
}-
LocalEntityId: The GUID of the entity being mapped (for example, Door, AccessPoint, Cardholder). -
RoleId: The GUID of the role that owns this mapping. -
XmlInfo: A string field for storing custom configuration data, typically XML but can contain any string data.
Use entity mappings when your role needs private, role-scoped data associated with Security Center entities.
EntityMappings is typically used with plugin roles to store custom configuration data specific to individual entities. This is the most common and recommended use case.
Unlike custom fields that are visible in Config Tool and Security Desk, EntityMappings provides role-private storage. Your plugin can associate custom data with any entity (doors, cardholders, cameras, etc.) without affecting other applications or appearing in Security Center's user interfaces.
Store entity-specific configuration data within any role type. This allows roles to maintain custom settings or metadata for each entity they manage.
EntityMappings can store any custom configuration data that needs to be associated with a specific entity within a role's context.
EntityMappings is commonly used to map Security Center entities to external third-party systems. This enables integration plugins to maintain correlations between entities and external data sources:
- Map cardholders to employee IDs in HR systems
- Connect entities to external database records
| Feature | EntityMappings | Custom fields |
|---|---|---|
| Scope | Role-private | System-wide |
| Visibility | Only accessible through your role | Visible in Config Tool and other applications |
| Purpose | Internal plugin data and integration mappings | User-configurable entity properties |
| UI integration | No automatic UI representation | Appears in Security Center interfaces |
| Use case | Plugin-specific configuration and external system mappings | Business properties users can modify |
EntityMappings is ideal when you need to store configuration data that should remain private to your application and not appear in the standard Security Center user interfaces.
The role.EntityMappings property returns a copy of the mapping collection, not a live collection reference. This means:
// This will NOT work as expected
role.EntityMappings.Add(newMapping); // Adding to a copy, not the original
// This is the correct approach
var mappings = role.EntityMappings;
mappings.Add(newMapping);
role.EntityMappings = mappings; // Assign the modified list backThe Role class provides convenience methods for working with EntityMappings:
public void AddMapping(Guid localEntity, string info);This method creates and adds a new EntityMapping to the role's EntityMappings collection.
public void RemoveMapping(EntityMapping mapping);This method removes the specified EntityMapping from the role's collection.
When working with large numbers of mappings, direct list assignment is significantly faster than using the individual helper methods:
// Inefficient for many mappings
foreach (var mapping in manyMappings)
{
role.AddMapping(mapping.LocalEntityId, mapping.XmlInfo);
}// Efficient for bulk operations
var mappings = role.EntityMappings;
mappings.AddRange(manyMappings);
role.EntityMappings = mappings;Use the helper methods (AddMapping, RemoveMapping) for single operations, but prefer direct list manipulation for bulk operations.
Use these patterns to add, update, and retrieve mapping data consistently.
To add or update an EntityMapping:
void SaveMapping(Role role, Guid entityId, string data)
{
var mappings = role.EntityMappings;
var existing = mappings.FirstOrDefault(m => m.LocalEntityId == entityId);
if (existing != null)
existing.XmlInfo = data;
else
mappings.Add(new EntityMapping { LocalEntityId = entityId, RoleId = role.Guid, XmlInfo = data });
role.EntityMappings = mappings;
}To retrieve configuration data from an EntityMapping:
bool TryGetMapping(Role role, Guid entityId, out string data)
{
EntityMapping mapping = role.EntityMappings
.FirstOrDefault(m => m.LocalEntityId == entityId);
if (mapping != null)
{
data = mapping.XmlInfo;
return true;
}
data = default;
return false;
}To remove an EntityMapping from a role:
role.RemoveMapping(mapping);When EntityMappings are modified, the system raises the following events:
-
EntityInvalidated: Raised on the Engine instance for the specific role entity. -
EntitiesInvalidated: Raised on the Engine instance for the collection of roles affected. -
FieldsChanged: Raised on the role instance to indicate that a field has been updated.
These events allow applications to respond to changes in EntityMappings and update their own cached data or user interfaces accordingly.
Changes to EntityMappings are automatically persisted to the Security Center database when you set the EntityMappings property or call AddMapping() or RemoveMapping().
For bulk operations, prefer using the EntityMappings property setter as shown in the performance considerations section above. This is a single operation regardless of how many mappings are in the list.
If you must use AddMapping() or RemoveMapping() in a loop, wrap the operations in a transaction to batch them:
engine.TransactionManager.ExecuteTransaction(() =>
{
foreach (var mapping in mappingsToAdd)
{
role.AddMapping(mapping.LocalEntityId, mapping.XmlInfo);
}
});- Plugin SDK overview: Plugin architecture, lifecycle, and components.
- Plugin SDK configuration: Role-level configuration storage and update flow.
- Plugin SDK entity ownership: Plugin-owned entities and their running-state contract.
-
About entities: Entity model and
IPartitionSupport. - About transactions: Batching multiple entity operations into one request.
- Overview
- Connecting to Security Center
- SDK certificates
- Referencing SDK assemblies
- SDK compatibility
- Entities
- Entity cache
- Transactions
- Events
- Actions
- Security Desk
- Custom events
- ReportManager
- ReportManager query reference
- DownloadAllRelatedData and StrictResults
- Privileges
- Partitions
- Mobile credentials
- Logging
- Overview
- Certificates
- Lifecycle
- Threading
- State management
- Configuration
- Restricted configuration
- Events
- Queries
- Request manager
- Database
- Entity ownership
- Entity mappings
- Server management
- Custom privileges
- Custom entity types
- Resolving non-SDK assemblies
- Deploying plugins
- .NET 8 support
- Overview
- Certificates
- Creating modules
- Tasks
- Pages
- Components
- Tile extensions
- Services
- Contextual actions
- Options extensions
- Configuration pages
- Monitors
- Shared components
- Commands
- Extending events
- Map extensions
- Timeline providers
- Image extractors
- Credential encoders
- Credential readers
- Cardholder fields extractors
- Badge printers
- Content builders
- Dashboard widgets
- Incidents
- Logon providers
- Pinnable content builders
- Custom report pages
- Overview
- Getting started
- MediaPlayer
- VideoSourceFilter
- MediaExporter
- MediaFile
- G64 converters
- FileCryptingManager
- PlaybackSequenceQuerier
- PlaybackStreamReader
- OverlayFactory
- PtzCoordinatesManager
- AudioTransmitter
- AudioRecorder
- AnalogMonitorController
- Camera blocking
- Overview
- Getting started
- Referencing entities
- Entity operations
- About access control in the Web SDK
- About video in the Web SDK
- Users and user groups
- Partitions
- Custom fields
- Custom card formats
- Actions
- Events and alarms
- Incidents
- Reports
- Tasks
- Macros
- Custom entity types
- System endpoints
- Performance guide
- Reference
- Under the hood
- Troubleshooting