public IEnumerable <Attribute> GetMetaAttributes(AttributeTypeEnum type) { var atts = from att in this.Attributes where type.ToString() == att.AttributeType let displayOrder = (from si in att.SchemaInfos from sd in si.SchemaDatas where sd.Active select sd.DisplayOrder) .FirstOrDefault() orderby displayOrder, att.AttributeName select att; return(atts.ToList()); }
public static dynamic GetTSObject(AttributeTypeEnum dynEnum) { var tsType = TSActivator.CreateInstance("Tekla.Structures.Model.Collaboration.ReferenceModelObjectAttribute.AttributeTypeEnum").GetType(); switch (dynEnum) { case AttributeTypeEnum.ATTRIBUTETYPE_INVALID: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_INVALID")); case AttributeTypeEnum.ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_CSHAPEPROFILE: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_CSHAPEPROFILE")); case AttributeTypeEnum.ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_CIRCLEHOLLOWPROFILE: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_CIRCLEHOLLOWPROFILE")); case AttributeTypeEnum.ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_CIRCLEPROFILE: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_CIRCLEPROFILE")); case AttributeTypeEnum.ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_ELLIPSEPROFILE: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_ELLIPSEPROFILE")); case AttributeTypeEnum.ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_ISHAPEPROFILE: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_ISHAPEPROFILE")); case AttributeTypeEnum.ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_LSHAPEPROFILE: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_LSHAPEPROFILE")); case AttributeTypeEnum.ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_RECTANGLEHOLLOWPROFILE: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_RECTANGLEHOLLOWPROFILE")); case AttributeTypeEnum.ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_RECTANGLEPROFILE: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_RECTANGLEPROFILE")); case AttributeTypeEnum.ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_TSHAPEPROFILE: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_TSHAPEPROFILE")); case AttributeTypeEnum.ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_USHAPEPROFILE: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_USHAPEPROFILE")); case AttributeTypeEnum.ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_ZSHAPEPROFILE: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_IFC2X3_PARAMETRICOBJECT_ZSHAPEPROFILE")); case AttributeTypeEnum.ATTRIBUTETYPE_PARAMETRICOBJECT_CUSTOMPROFILE: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_PARAMETRICOBJECT_CUSTOMPROFILE")); case AttributeTypeEnum.ATTRIBUTETYPE_PARAMETRICOBJECT_OBB: return(System.Enum.Parse(tsType, "ATTRIBUTETYPE_PARAMETRICOBJECT_OBB")); default: throw new DynamicAPIException(dynEnum.ToString() + "- enum value is not implemented"); } }
/// <summary> /// Get Attribute for specified Typ /// </summary> /// <returns><see cref="Attribute{ValueType}"/></returns> public static IAttribute CreateTypedAttribute(string name, AttributeTypeEnum type, List <IValue> values = null) { var typeName = type.ToString(); var result = ((Func <IAttribute>)(() => { switch (type) { case AttributeTypeEnum.Boolean: return(new Attribute <bool?>(name, typeName)); case AttributeTypeEnum.DateTime: return(new Attribute <DateTime?>(name, typeName)); case AttributeTypeEnum.Number: return(new Attribute <decimal?>(name, typeName)); case AttributeTypeEnum.Entity: return(new Attribute <EntityRelationship>(name, typeName) { Values = new List <IValue> { Value.NullRelationship } }); // ReSharper disable RedundantCaseLabel case AttributeTypeEnum.String: case AttributeTypeEnum.Hyperlink: case AttributeTypeEnum.Custom: case AttributeTypeEnum.Undefined: case AttributeTypeEnum.Empty: // ReSharper restore RedundantCaseLabel default: return(new Attribute <string>(name, typeName)); } }))(); if (values != null) { result.Values = values; } return(result); }
/// <summary> /// Get an Import-Attribute /// </summary> private ImportAttribute(string staticName, string name, AttributeTypeEnum type, string notes, bool? visibleInEditUi, object defaultValue) { StaticName = staticName; Type = type.ToString(); AttributeMetaData = new List<ImportEntity> { GetAttributeMetaData(name, notes, visibleInEditUi, HelpersToRefactor.SerializeValue(defaultValue)) }; }
//public static Attribute GetAttributeFromName(AryaDbDataContext db, string attributeName, // bool createIfNotFound, AttributeTypeEnum attributeType = AttributeTypeEnum.NonMeta) public static Attribute GetAttributeFromName(AryaDbDataContext db, string attributeName, bool createIfNotFound, AttributeTypeEnum attributeType = AttributeTypeEnum.NonMeta, bool useChache = true) { // select cache to use //TODO: Very important please ask vivek for making this change. if (!useChache) { NonMetaAttributeCache.Clear(); SchemaMetaAttributeCache.Clear(); SchemaMetaMetaAttributeCache.Clear(); TaxonomyMetaAttributeCache.Clear(); TaxonomyMetaMetaAttributeCache.Clear(); } Dictionary <string, Attribute> attributeCache; switch (attributeType) { case AttributeTypeEnum.SchemaMeta: { attributeCache = SchemaMetaAttributeCache; break; } case AttributeTypeEnum.SchemaMetaMeta: { attributeCache = SchemaMetaMetaAttributeCache; break; } case AttributeTypeEnum.TaxonomyMeta: { attributeCache = TaxonomyMetaAttributeCache; break; } case AttributeTypeEnum.TaxonomyMetaMeta: { attributeCache = TaxonomyMetaMetaAttributeCache; break; } case AttributeTypeEnum.Workflow: { attributeCache = WorkflowAttributeCache; break; } default: //Sku, Global, Derived, Flag { attributeCache = NonMetaAttributeCache; break; } } // format attribute name attributeName = attributeName.Trim(); var lowerAttributeName = attributeName.ToLower(); // try to find attribute in cache and make sure it is correct if (attributeCache.ContainsKey(lowerAttributeName)) { var attribute = attributeCache[lowerAttributeName]; if (attribute != null && !attribute.AttributeName.ToLower().Equals(lowerAttributeName)) { attributeCache.Remove(lowerAttributeName); } else { return(attribute); } } // if attribute is not cached, try to find it in the whole attribute file Attribute newAttribute = null; var attQuery = from attribute in db.Attributes where attribute.AttributeName.ToLower().Equals(lowerAttributeName) && attribute.ProjectID == db.CurrentProject.ID select attribute; attQuery = attributeType == AttributeTypeEnum.NonMeta ? attQuery.Where(attr => NonMetaAttributeTypes.Contains(attr.AttributeType)) : attQuery.Where(attr => attr.AttributeType == attributeType.ToString()); var att = attQuery.FirstOrDefault(); // if found, return it if (att != null) { newAttribute = att; } // if not found and creation is requested, create it else if (createIfNotFound) { newAttribute = new Attribute(db) { AttributeName = attributeName, AttributeType = (attributeType == AttributeTypeEnum.NonMeta ? AttributeTypeEnum.Sku : attributeType).ToString() }; db.CurrentProject.Attributes.Add(newAttribute); // db.SubmitChanges(); } // if attribute exists, try to add it to the appropriate cache if (newAttribute != null) { if (!attributeCache.Keys.Contains(lowerAttributeName)) { attributeCache.Add(lowerAttributeName, newAttribute); } } return(newAttribute); }