private IEnumerable <KeyValuePair <Attribute, SchemaData> > GetExportAttributes(TaxonomyInfo taxonomy)
        {
            if (taxonomyAttributesCache.ContainsKey(taxonomy.ID))
            {
                return(taxonomyAttributesCache[taxonomy.ID]);
            }
            var schemaInfos = new List <SchemaInfo>();

            schemaInfos.AddRange(taxonomy.SchemaInfos.Where(si => si.SchemaDatas.Any(sd => sd.Active)).ToList());

            var attributes = (from si in schemaInfos
                              let rank = GetRank(si.SchemaData, SortOrder.OrderbyNavigationDisplay)
                                         where si.SchemaData.InSchema
                                         orderby rank, si.Attribute.AttributeName
                              select new KeyValuePair <Attribute, SchemaData>(si.Attribute, si.SchemaData)).ToList();

            if (AttributeGroupExclusions.Length > 0)
            {
                //exclude Attribute Groups
                attributes =
                    attributes.Where(
                        p => p.Key.Group == null || (!AttributeGroupExclusions.Contains(p.Key.Group.ToLower())))
                    .ToList();
            }

            if (AttributeGroupInclusions.Length > 0)
            {
                //include Attribute Groups
                attributes =
                    attributes.Where(
                        p => p.Key.Group == null || (AttributeGroupInclusions.Contains(p.Key.Group.ToLower()))).ToList();
            }

            if ((AttributeGroupExclusions.Length > 0 && AttributeGroupExclusions.Contains("default")) ||
                (AttributeGroupInclusions.Length > 0 && !AttributeGroupInclusions.Contains("default")))
            {
                attributes = attributes.Where(p => p.Key.Group != null).ToList();
            }

            taxonomyAttributesCache.Add(taxonomy.ID, attributes);

            return(attributes);
        }
示例#2
0
        //Attribute,NavRank,DispRank
        private IEnumerable <Tuple <Attribute, decimal, decimal> > GetExportAttributes(TaxonomyInfo taxonomy)
        {
            if (_taxonomyAttributesCache.ContainsKey(taxonomy.ID))
            {
                return(_taxonomyAttributesCache[taxonomy.ID]);
            }
            var schemaInfos = new List <SchemaInfo>();

            schemaInfos.AddRange(taxonomy.SchemaInfos.Where(si => si.SchemaDatas.Any(sd => sd.Active)).ToList());

            if (ExportSuperSchema)
            {
                foreach (var leaf in taxonomy.AllLeafChildren)
                {
                    schemaInfos.AddRange(leaf.SchemaInfos.Where(si => si.SchemaDatas.Any(sd => sd.Active)).ToList());
                }
            }

            var atts =
                schemaInfos.Where(p => p.SchemaData.InSchema).Select(p => new { p.Attribute, p.SchemaData }).ToList();

            List <Tuple <Attribute, decimal, decimal> > attributes;

            if (Top6OnlyAttributes == false)
            {
                if (ExportSuperSchema)
                {
                    attributes = (from att in atts
                                  group att by att.Attribute
                                  into grp
                                  let minRank = grp.Min(p => GetRank(p.SchemaData, SortOrder.OrderbyDisplayNavigation))
                                                orderby minRank
                                                select new Tuple <Attribute, decimal, decimal>(grp.Key, 0, minRank)).ToList();
                }
                else
                {
                    attributes = (from att in atts
                                  let rank = GetRank(att.SchemaData, OrderAttributesBy)
                                             orderby rank, att.Attribute.AttributeName
                                  select
                                  new Tuple <Attribute, decimal, decimal>(att.Attribute,
                                                                          att.SchemaData == null ? 0 : att.SchemaData.NavigationOrder,
                                                                          att.SchemaData == null ? 0 : att.SchemaData.DisplayOrder)).ToList();
                }
            }
            else
            {
                var attrs = (from att in atts.Where(att => att.SchemaData != null && att.SchemaData.NavigationOrder > 0)
                             let baseAttributeName = GetBaseAttributeName(att.Attribute.AttributeName)
                                                     group att by baseAttributeName
                                                     into grp
                                                     let minNavRank = grp.Min(g => g.SchemaData.NavigationOrder)
                                                                      orderby minNavRank
                                                                      select new { BaseAttributeName = grp.Key, Attributes = grp.Select(p => p.Attribute) }).Take(6)
                            .SelectMany(p => p.Attributes)
                            .Distinct()
                            .ToList();

                attributes = (from attribute1 in attrs
                              let schemaData = taxonomy.SchemaInfos.Single(si => si.AttributeID == attribute1.ID).SchemaData
                                               select
                                               schemaData == null
                            ? new Tuple <Attribute, decimal, decimal>(attribute1, 0, 0)
                            : new Tuple <Attribute, decimal, decimal>(attribute1, schemaData.NavigationOrder,
                                                                      schemaData.DisplayOrder)).ToList();
            }

            if (AttributeGroupExclusions.Length > 0)
            {
                //exclude Attribute Groups
                attributes =
                    attributes.Where(
                        p => p.Item1.Group == null || (!AttributeGroupExclusions.Contains(p.Item1.Group.ToLower())))
                    .ToList();
            }

            if (AttributeGroupInclusions.Length > 0)
            {
                //include Attribute Groups
                attributes =
                    attributes.Where(
                        p => p.Item1.Group == null || (AttributeGroupInclusions.Contains(p.Item1.Group.ToLower())))
                    .ToList();
            }

            if ((AttributeGroupExclusions.Length > 0 && AttributeGroupExclusions.Contains("default")) ||
                (AttributeGroupInclusions.Length > 0 && !AttributeGroupInclusions.Contains("default")))
            {
                attributes = attributes.Where(p => p.Item1.Group != null).ToList();
            }

            _taxonomyAttributesCache.Add(taxonomy.ID, attributes);

            return(attributes);
        }