private bool ValidateAttributes(AssetTypeInfoType typeRequirements, AssetTypeInfoType type, AssetInfoType asset) { //get requirements var requirements = typeRequirements.AssetTypeAttributes.Where( a => a.propertySetName != null && a.propertySetName.StartsWith("[required]")); //merge instance and type attributes var attrs = asset.AssetAttributes; attrs.AddRange(type.AssetTypeAttributes); //clear and fill in only required ones asset.AssetAttributes = new AttributeCollectionType(); var allValid = true; foreach (var requirement in requirements) { //create new instance var attr = new AttributeType { AttributeName = requirement.AttributeName, AttributeCategory = "Check", AttributeDescription = requirement.AttributeDescription, propertySetName = requirement.propertySetName, propertySetExternalIdentifier = requirement.propertySetExternalIdentifier }; //add value if defined //prefix [F] if no value is defined or [T] if it is defined //this will be used to report validation result var valAttr = attrs.FirstOrDefault(a => a.AttributeName == requirement.AttributeName); if (valAttr != null && valAttr.AttributeValue != null && valAttr.AttributeValue.Item != null) { var prefix = "[T]"; var valType = valAttr.AttributeValue.Item as ValueBaseType; if (valType != null && !valType.HasValue()) { allValid = false; prefix = "[F]"; } attr.AttributeValue = valAttr.AttributeValue; attr.AttributeName = prefix + attr.AttributeName; } else { allValid = false; attr.AttributeName = "[F]" + attr.AttributeName; } asset.AssetAttributes.Add(attr); } asset.AssetName = (allValid ? "[T]" : "[F]") + asset.AssetName; return allValid; }
public static IEnumerable<AttributeType> GetCOBieAttributes(this DPoWAttributableObject obj) { IEnumerable<Xbim.DPoW.Attribute> sAttributes = obj.Attributes; var sAttrs = sAttributes as Attribute[] ?? sAttributes.ToArray(); if (sAttributes == null || !sAttrs.Any()) yield break; foreach (var sAttr in sAttrs) { //create attribute in target var tAttr = new AttributeType { AttributeName = sAttr.Name, AttributeDescription = sAttr.Definition, AttributeValue = new AttributeValueType() }; switch (sAttr.ValueType) { case ValueTypeEnum.NotDefined: tAttr.AttributeValue.Item = new AttributeStringValueType { StringValue = sAttr.Value }; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeStringValue; break; case ValueTypeEnum.Boolean: bool bVal; if (bool.TryParse(sAttr.Value, out bVal)) { tAttr.AttributeValue.Item = new BooleanValueType { BooleanValue = bVal, BooleanValueSpecified = true }; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeBooleanValue; } break; case ValueTypeEnum.DateTime: DateTime dtVal; if (DateTime.TryParse(sAttr.Value, out dtVal)) { tAttr.AttributeValue.Item = dtVal; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeDateTimeValue; } break; case ValueTypeEnum.Decimal: float fVal; if (float.TryParse(sAttr.Value, out fVal)) { tAttr.AttributeValue.Item = new AttributeDecimalValueType { DecimalValue = fVal, DecimalValueSpecified = true }; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeDecimalValue; } break; case ValueTypeEnum.Integer: int iVal; if (int.TryParse(sAttr.Value, out iVal)) { tAttr.AttributeValue.Item = new AttributeIntegerValueType { IntegerValue = iVal }; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeIntegerValue; } break; case ValueTypeEnum.String: tAttr.AttributeValue.Item = new AttributeStringValueType { StringValue = sAttr.Value }; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeStringValue; break; default: throw new ArgumentOutOfRangeException(); } //default action is to create string if (tAttr.AttributeValue.Item == null) { tAttr.AttributeValue.Item = new AttributeStringValueType { StringValue = sAttr.Value }; tAttr.AttributeValue.ItemElementName = ItemChoiceType.AttributeStringValue; } yield return tAttr; } }