private static double parseDoubleValue(Xbim.CobieLiteUk.Attribute attribute)
        {
            if (attribute != null)
            {
                double parsedValue = Double.NaN;
                Double.TryParse(attribute.Value.GetStringValue(), out parsedValue);
                return(parsedValue);
            }

            return(Double.NaN);
        }
        private static DurationUnit parseDurationUnitValue(Xbim.CobieLiteUk.Attribute attribute)
        {
            DurationUnit result = DurationUnit.asrequired;

            string asString = parseStringValue(attribute);

            if (asString != null && !asString.Equals(string.Empty))
            {
                result = (DurationUnit)Enum.Parse(typeof(DurationUnit), asString, true);
            }

            return(result);
        }
        private static DateTime parseDateValue(Xbim.CobieLiteUk.Attribute attribute)
        {
            if (attribute != null && attribute.Value != null)
            {
                DateTime dt;
                DateTime.TryParseExact(attribute.Value.GetStringValue(),
                                       "MM.dd",
                                       System.Globalization.CultureInfo.InvariantCulture,
                                       System.Globalization.DateTimeStyles.None,
                                       out dt);
                return(dt);
            }

            return(DateTime.MinValue);
        }
        private static List <ContactKey> parseSupplierValue(Xbim.CobieLiteUk.Attribute attribute)
        {
            List <ContactKey> contactKeys = new List <ContactKey>();

            if (attribute != null && attribute.Value != null)
            {
                string[] emailList = attribute.Value.GetStringValue().Split(new[] { ':', ';', '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string email in emailList)
                {
                    contactKeys.Add(createContactKey(email));
                }
            }

            return(contactKeys);
        }
        private static bool resolveAttribute(Xbim.CobieLiteUk.Attribute attribute, string key, Dictionary <string, List <PsetPropertyPair> > map)
        {
            List <PsetPropertyPair> values;

            map.TryGetValue(key, out values);
            if (values != null && values.Count() > 0 && attribute != null && attribute.Value != null)
            {
                PsetPropertyPair psetPropertyPair = values.Find(v => attribute.Name.ToUpper().Equals(v.propertyName.ToUpper()) && attribute.PropertySetName.ToUpper().Equals(v.psetName.ToUpper()));
                if (psetPropertyPair != null)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Converts an IfcProperty to a COBie Attribute
        /// </summary>
        /// <param name="ifcProperty"></param>
        /// <returns></returns>
        public static Attribute ConvertToAttributeType(IIfcProperty ifcProperty)
        {
            var attributeType = new Attribute
            {
                Description = ifcProperty.Description,
                Name        = ifcProperty.Name,
                Categories  = new List <Category>
                {
                    new Category {
                        Classification = "DPoW Status", Code = "Submitted"
                    }
                }
                //srl we need to define categories, the schema proposes "As Built|Submitted|Approved|Exact Requirement|Maximum Requirement|Minimum Requirement|Requirement", should DPoW set requirements?
            };

            var ifcPropertySingleValue     = ifcProperty as IIfcPropertySingleValue;
            var ifcPropertyEnumeratedValue = ifcProperty as IIfcPropertyEnumeratedValue;
            var ifcPropertyBoundedValue    = ifcProperty as IIfcPropertyBoundedValue;
            var ifcPropertyTableValue      = ifcProperty as IIfcPropertyTableValue;
            var ifcPropertyReferenceValue  = ifcProperty as IIfcPropertyReferenceValue;
            var ifcPropertyListValue       = ifcProperty as IIfcPropertyListValue;

            if (ifcPropertySingleValue != null)
            {
                attributeType.Value = GetAttributeValueType(ifcPropertySingleValue);
            }
            else if (ifcPropertyEnumeratedValue != null)
            {
                var valueItem = new StringAttributeValue();
                attributeType.Value = valueItem;

                if (ifcPropertyEnumeratedValue.EnumerationReference != null && ifcPropertyEnumeratedValue.EnumerationReference.Unit != null)
                {
                    valueItem.Unit = ((IIfcUnit)ifcPropertyEnumeratedValue.EnumerationReference).FullName;
                }
                if (ifcPropertyEnumeratedValue.EnumerationValues.Count() == 1)
                {
                    // ReSharper disable once PossibleNullReferenceException
                    valueItem.Value = ifcPropertyEnumeratedValue.EnumerationValues.FirstOrDefault().ToString();
                }
                else
                {
                    valueItem.Value = "";
                    foreach (var enumValue in ifcPropertyEnumeratedValue.EnumerationValues)
                    {
                        valueItem.Value += enumValue + ";";
                    }
                    valueItem.Value = valueItem.Value.TrimEnd(';', ' ');
                }
                //add in the allowed values
                if (ifcPropertyEnumeratedValue.EnumerationReference != null && ifcPropertyEnumeratedValue.EnumerationReference.EnumerationValues.Any())
                {
                    // todo: value never used.
                    var allowedValues = new List <string>();
                    foreach (var enumValue in ifcPropertyEnumeratedValue.EnumerationReference.EnumerationValues)
                    {
                        allowedValues.Add(enumValue.ToString());
                    }
                }
            }
            else if (ifcPropertyBoundedValue != null)
            {
                attributeType.Value = GetAttributeValue(ifcPropertyBoundedValue);
            }
            else if (ifcPropertyTableValue != null)
            {
                //Logger.WarnFormat("Table values are not supported in COBie");
            }
            else if (ifcPropertyReferenceValue != null)
            {
                //Logger.WarnFormat("Reference property values are not supported in COBie");
            }
            else if (ifcPropertyListValue != null)
            {
                //Logger.WarnFormat("Multiple List values are not supported in COBie");
            }
            return(attributeType);
        }
 private static string parseStringValue(Xbim.CobieLiteUk.Attribute attribute)
 {
     return(attribute != null && attribute.Value != null
         ? attribute.Value.GetStringValue()
         : string.Empty);
 }
Ejemplo n.º 8
0
        public static IEnumerable <CAttribute> GetCOBieAttributes(this DPoWAttributableObject obj, DateTime?createdOn, string createdBy)
        {
            IEnumerable <Xbim.DPoW.Attribute> sAttributes = obj.Attributes;
            var sAttrs = sAttributes as DAttribute[] ?? sAttributes.ToArray();

            if (sAttributes == null || !sAttrs.Any())
            {
                yield break;
            }

            foreach (var sAttr in sAttrs)
            {
                //create attribute in target
                var tAttr = new CAttribute
                {
                    Name            = sAttr.Name,
                    Description     = sAttr.Definition,
                    PropertySetName = "DPoW Attributes",
                    CreatedOn       = createdOn,
                    CreatedBy       = new ContactKey {
                        Email = createdBy
                    },
                    Categories = new List <Category>(new [] { new Category {
                                                                  Code = "Submitted"
                                                              } })
                };
                switch (sAttr.ValueType)
                {
                case ValueTypeEnum.NotDefined:
                    tAttr.Value = new StringAttributeValue {
                        Value = sAttr.Value
                    };
                    break;

                case ValueTypeEnum.Boolean:
                    bool bVal;
                    if (bool.TryParse(sAttr.Value, out bVal))
                    {
                        tAttr.Value = new BooleanAttributeValue {
                            Value = bVal
                        }
                    }
                    ;
                    break;

                case ValueTypeEnum.DateTime:
                    DateTime dtVal;
                    if (DateTime.TryParse(sAttr.Value, out dtVal))
                    {
                        tAttr.Value = new DateTimeAttributeValue {
                            Value = dtVal
                        }
                    }
                    ;
                    break;

                case ValueTypeEnum.Decimal:
                    float fVal;
                    if (float.TryParse(sAttr.Value, out fVal))
                    {
                        tAttr.Value = new DecimalAttributeValue {
                            Value = fVal
                        }
                    }
                    ;
                    break;

                case ValueTypeEnum.Integer:
                    int iVal;
                    if (int.TryParse(sAttr.Value, out iVal))
                    {
                        tAttr.Value = new IntegerAttributeValue {
                            Value = iVal
                        }
                    }
                    ;
                    break;

                case ValueTypeEnum.String:
                    tAttr.Value = new StringAttributeValue {
                        Value = sAttr.Value
                    };
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                //default action is to create string
                if (tAttr.Value == null)
                {
                    tAttr.Value = new StringAttributeValue {
                        Value = sAttr.Value
                    }
                }
                ;
                yield return(tAttr);
            }
        }
    }