private void InitData() { var emptyGuid = new Guid(); _rows = (from att in AryaTools.Instance.InstanceData.Dc.Attributes where att.ProjectID.Equals(AryaTools.Instance.InstanceData.CurrentProject.ID) && att.AttributeType.Equals(_metaAttType.ToString()) let displayRank = (from si in att.SchemaInfos where si.TaxonomyID.Equals(emptyGuid) from sd in si.SchemaDatas where sd.Active select sd.DisplayOrder).FirstOrDefault() orderby displayRank, att.AttributeName select att).ToList(); _columns = (from att in AryaTools.Instance.InstanceData.Dc.Attributes where att.ProjectID.Equals(AryaTools.Instance.InstanceData.CurrentProject.ID) && att.AttributeType.Equals(_metaMetaAttType.ToString()) let displayRank = (from si in att.SchemaInfos where si.TaxonomyID.Equals(emptyGuid) from sd in si.SchemaDatas where sd.Active select sd.DisplayOrder).FirstOrDefault() orderby displayRank, att.AttributeName select att).ToList(); }
public static Attribute GetAttributeFromName(string attributeName, bool createIfNotFound, Framework.Data.AryaDb.AttributeTypeEnum attributeType = Framework.Data.AryaDb.AttributeTypeEnum.NonMeta) { // select cache to use Dictionary <string, Attribute> attributeCache; switch (attributeType) { case Framework.Data.AryaDb.AttributeTypeEnum.SchemaMeta: { attributeCache = SchemaMetaAttributeCache; break; } case Framework.Data.AryaDb.AttributeTypeEnum.SchemaMetaMeta: { attributeCache = SchemaMetaMetaAttributeCache; break; } case Framework.Data.AryaDb.AttributeTypeEnum.TaxonomyMeta: { attributeCache = TaxonomyMetaAttributeCache; break; } case Framework.Data.AryaDb.AttributeTypeEnum.TaxonomyMetaMeta: { attributeCache = TaxonomyMetaMetaAttributeCache; break; } case Framework.Data.AryaDb.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 AryaTools.Instance.InstanceData.Dc.Attributes where attribute.AttributeName.Equals(lowerAttributeName) && attribute.ProjectID == AryaTools.Instance.InstanceData.CurrentProject.ID select attribute; attQuery = attributeType == Framework.Data.AryaDb.AttributeTypeEnum.NonMeta ? attQuery.Where( attr => Framework.Data.AryaDb.Attribute.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 { AttributeName = attributeName, AttributeType = (attributeType == Framework.Data.AryaDb.AttributeTypeEnum.NonMeta ? Framework.Data.AryaDb.AttributeTypeEnum.Sku : attributeType).ToString() }; AryaTools.Instance.InstanceData.CurrentProject.Attributes.Add(newAttribute); } // 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); }