public static void CheckAttribute(DataServiceRestClient client, EntityDto entity, ushort key, string description, AttributeTypeDto type) { var configuration = client.GetConfiguration().Result; var definition = configuration.GetDefinition(key); if (definition == null) { client.CreateAttributeDefinition(entity, new AttributeDefinitionDto { Key = key, Description = description, Type = type }); } else if (configuration.GetTypeForKey(key) != entity || definition.Description != description || (definition as AttributeDefinitionDto)?.Type != type) { //Don't do this, in case the PiWeb database is already in use. Changing the configuration will cause data-loss!!! client.UpdateAttributeDefinitions(entity, new AbstractAttributeDefinitionDto[] { new AttributeDefinitionDto { Key = key, Description = description, Type = type } }); } }
/// <summary> /// Initializes a new instance of the <see cref="AttributeDefinitionDto"/> class. /// </summary> /// <param name="key">The unique key for this attribute</param> /// <param name="description">The attribute description</param> /// <param name="type">The datatype of this attribute</param> /// <param name="length">The length of a string attribute (only valid if <code>type</code> is <code>AttributeType.AlphaNumeric</code></param> /// <param name="queryEfficient"><code>true</code> if this attribute is efficient for filtering operations</param> public AttributeDefinitionDto(ushort key, string description, AttributeTypeDto type, ushort?length, bool queryEfficient = false) : base(key, description, queryEfficient) { Type = type; Length = Type == AttributeTypeDto.AlphaNumeric ? length : null; }