public ConfigurationDefinition(DefinitionMetadata metadata, ComponentDescription componentDescription, ComponentConfiguration configuration) { Metadata = metadata; ComponentDescription = componentDescription; Configuration = configuration; }
public ConfigurationDefinition ReadDefinition(Stream input) { var yaml = deserializer.Deserialize <YamlTemplate>(new StreamReader(input)); var guid = Guid.Parse(yaml.Metadata.Guid); var descriptionGuid = Guid.Parse(yaml.Template.Guid); var description = componentDescriptionLookup.GetDescription(new TypeDescriptionComponentType(descriptionGuid, ComponentType.Unknown(yaml.Template.Name))); if (description == null) { throw new InvalidOperationException("Base description for template not found."); } var metadata = new DefinitionMetadata { Guid = guid, Description = yaml.Metadata.Description, Name = yaml.Metadata.Name, Version = yaml.Metadata.Version, }; var properties = new Dictionary <PropertyName, PropertyValue>(); foreach (var setter in yaml.Properties) { var componentProperty = description.Properties.FirstOrDefault(x => x.Name == setter.Name); if (componentProperty == null) { throw new InvalidOperationException($"Property '{setter.Name}' does not exist on component type '{description.ComponentName}'"); } PropertyValue value; switch (componentProperty.Type) { case PropertyType.Boolean: { value = new PropertyValue((bool)setter.Value); break; } case PropertyType.Decimal: { value = new PropertyValue((double)setter.Value); break; } case PropertyType.Integer: { value = new PropertyValue((int)setter.Value); break; } case PropertyType.Enum: case PropertyType.String: { value = new PropertyValue((string)setter.Value); break; } default: { throw new NotSupportedException("Unknown property type."); } } properties.Add(componentProperty.SerializedName, value); } var configuration = new ComponentConfiguration(null, yaml.Metadata.Name, properties); return(new ConfigurationDefinition(metadata, description, configuration)); }