Example #1
0
        private void Visit(ElementMapping <AttributeGroup> attribute)
        {
            WriteElement(attribute,
                         ag =>
            {
                foreach (var attr in ag.Attributes)
                {
                    _formatter.WriteAttribute(attr);
                }
            },
                         (ag1, ag2) =>
            {
                // TODO: Need to insert the newlines and indentions, perhaps support GetTokenList(IEnumerable<ICustomAttribute>)
                var attributeComparer = new AttributeComparer();
                var ag1Tokens         = ag1.Attributes.OrderBy(c => c, attributeComparer)
                                        .SelectMany(c => _declHelper.GetTokenList(c));
                var ag2Tokens = ag2.Attributes.OrderBy(c => c, attributeComparer)
                                .SelectMany(c => _declHelper.GetTokenList(c));

                foreach (var token in ListMerger.MergeLists(ag1Tokens, ag2Tokens))
                {
                    WriteElement(token, t =>
                    {
                        _syntaxWriter.WriteSyntaxToken(t);
                    },
                                 (t1, t2) =>
                    {
                        using (_syntaxWriter.StartStyle(SyntaxStyle.Removed))
                            _syntaxWriter.WriteSyntaxToken(t1);
                        using (_syntaxWriter.StartStyle(SyntaxStyle.Added))
                            _syntaxWriter.WriteSyntaxToken(t2);
                    }, false);
                }
            }, true);
        }
        public virtual FacetIterator GetIterator()
        {
            IDictionary <string, string> props = m_sel == null ? null : m_sel.SelectionProperties;
            int  depth  = PathFacetHandler.GetDepth(props);
            bool strict = PathFacetHandler.IsStrict(props);
            List <BrowseFacet> finalList;

            string[] paths = m_sel == null ? null : m_sel.Values;
            if (paths == null || paths.Length == 0)
            {
                finalList = new List <BrowseFacet>(GetFacetsForPath(null, depth, strict, int.MinValue, m_count.Length));
                return(new PathFacetIterator(finalList));
            }

            if (paths.Length == 1)
            {
                finalList = new List <BrowseFacet>(GetFacetsForPath(paths[0], depth, strict, int.MinValue, m_count.Length));
                return(new PathFacetIterator(finalList));
            }

            finalList = new List <BrowseFacet>();
            var iterList = new List <IEnumerator <BrowseFacet> >(paths.Length);

            foreach (string path in paths)
            {
                var subList = GetFacetsForPath(path, depth, strict, int.MinValue, m_count.Length);
                if (subList.Count > 0)
                {
                    iterList.Add(subList.GetEnumerator());
                }
            }
            var finalIter = ListMerger.MergeLists(iterList.ToArray(),
                                                  m_comparerFactory == null ? new FacetValueComparerFactory().NewComparer() : m_comparerFactory.NewComparer());

            while (finalIter.MoveNext())
            {
                BrowseFacet f = finalIter.Current;
                finalList.Add(f);
            }
            return(new PathFacetIterator(finalList));
        }
        public virtual IEnumerable <BrowseFacet> GetFacets()
        {
            IDictionary <string, string> props = _sel == null ? null : _sel.SelectionProperties;
            int  depth  = PathFacetHandler.GetDepth(props);
            bool strict = PathFacetHandler.IsStrict(props);

            string[] paths = _sel == null ? null : _sel.Values;
            if (paths == null || paths.Length == 0)
            {
                return(GetFacetsForPath(null, depth, strict, _minHitCount, _maxCount));
            }

            if (paths.Length == 1)
            {
                return(GetFacetsForPath(paths[0], depth, strict, _minHitCount, _maxCount));
            }

            List <BrowseFacet> finalList = new List <BrowseFacet>();
            var iterList = new List <IEnumerator <BrowseFacet> >(paths.Length);

            foreach (string path in paths)
            {
                var subList = GetFacetsForPath(path, depth, strict, _minHitCount, _maxCount);
                if (subList.Count() > 0)
                {
                    iterList.Add(subList.GetEnumerator());
                }
            }

            var finalIter = ListMerger.MergeLists(iterList.ToArray(),
                                                  _comparatorFactory == null ? new FacetValueComparatorFactory().NewComparator() : _comparatorFactory.NewComparator());

            while (finalIter.MoveNext())
            {
                BrowseFacet f = finalIter.Current;
                finalList.Insert(0, f);
            }
            return(finalList);
        }