Access Intent Architect designers and metadata through the IMetadataManager interface
The Designer API provides access to Intent Architect designers and their metadata at template execution time. Use IMetadataManager to query designers and retrieve metadata elements.
using System;using System.Collections.Generic;using System.Linq;using Intent.Metadata.Models;using Intent.Modules.Common;namespace Intent.ModuleBuilder.Api{ public class DesignerModel : IMetadataModel, IHasStereotypes, IHasName, IElementWrapper { public const string SpecializationType = "Designer"; public const string SpecializationTypeId = "7f5fcc9f-c721-4a31-bfe2-7909f4289420"; protected readonly IElement _element; public DesignerModel(IElement element, string requiredType = SpecializationType) { if (!requiredType.Equals(element.SpecializationType, StringComparison.InvariantCultureIgnoreCase)) { throw new Exception( $"Cannot create a '{GetType().Name}' from element with " + $"specialization type '{element.SpecializationType}'. " + $"Must be of type '{SpecializationType}'"); } _element = element; } public string Id => _element.Id; public string Name => _element.Name; public string Comment => _element.Comment; public IEnumerable<IStereotype> Stereotypes => _element.Stereotypes; public IElement InternalElement => _element; public IList<DesignerReferenceModel> DesignerReferences => _element.ChildElements .GetElementsOfType(DesignerReferenceModel.SpecializationTypeId) .Select(x => new DesignerReferenceModel(x)) .ToList(); } public static class DesignerModelExtensions { public static bool IsDesignerModel(this ICanBeReferencedType type) { return type != null && type is IElement element && element.SpecializationTypeId == DesignerModel.SpecializationTypeId; } public static DesignerModel AsDesignerModel(this ICanBeReferencedType type) { return type.IsDesignerModel() ? new DesignerModel((IElement)type) : null; } }}
public class MyTemplate : IntentTemplateBase<ClassModel>{ public MyTemplate(IOutputTarget outputTarget, ClassModel model) : base("Template.Id", outputTarget, model) { } public override string RunTemplate() { // Access the domain designer var domainDesigner = ExecutionContext.MetadataManager .Domain(ExecutionContext.GetApplicationConfig().Id); // Query elements from the designer var classes = domainDesigner.GetDomainModels() .SelectMany(x => x.Classes); // Generate code based on metadata foreach (var @class in classes) { // Process each class element } return TransformText(); }}
var designer = metadataManager.Domain(applicationId);// Get all root elementsvar rootElements = designer.GetElements();// Find element by IDvar specificElement = designer.GetElementById("some-element-id");// Query by specialization typevar classes = designer.GetElements() .GetElementsOfType(ClassModel.SpecializationTypeId);
When creating a module, generate designer extension methods for easy access:
public static class MyDesignerExtensions{ // Designer ID constant public const string MyDesignerId = "12345678-1234-1234-1234-123456789abc"; // Extension method on IMetadataManager public static IDesigner MyDesigner( this IMetadataManager metadataManager, IApplication application) { return metadataManager.GetDesigner(application.Id, MyDesignerId); } // Helper to get strongly-typed models public static IList<MyModel> GetMyModels(this IDesigner designer) { return designer.GetElements() .GetElementsOfType(MyModel.SpecializationTypeId) .Select(x => new MyModel(x)) .ToList(); }}