コード例 #1
0
        public AweCsomeTag Search(TaxonomyTypes taxonomyType, string termSetName, string groupName, string query)
        {
            GetTermSet(taxonomyType, termSetName, groupName, false, out TermStore termStore, out TermSet termSet);
            TermCollection allTerms = termSet.Terms;

            _clientContext.Load(termSet, q => q.Name);
            _clientContext.Load(allTerms);
            _clientContext.ExecuteQuery();
            var rootTag = new AweCsomeTag
            {
                Children      = new List <AweCsomeTag>(),
                Name          = termSet.Name,
                Id            = termSet.Id,
                TermStoreName = termStore.Name
            };

            foreach (var term in allTerms)
            {
                rootTag.Children.Add(GetTermChildren(term, rootTag));
            }
            if (query != null)
            {
                SearchInsideTaxonomy(rootTag, query);
            }

            return(rootTag);
        }
コード例 #2
0
 private bool SearchInsideTaxonomy(AweCsomeTag tag, string query)
 {
     for (int i = tag.Children.Count - 1; i >= 0; i--)
     {
         if (!SearchInsideTaxonomy(tag.Children[i], query))
         {
             tag.Children.RemoveAt(i);
         }
     }
     if (tag.Children.Count > 0)
     {
         return(true);
     }
     return(tag.Name != null && tag.Name.IndexOf(query, StringComparison.InvariantCultureIgnoreCase) >= 0);
 }
コード例 #3
0
        private AweCsomeTag GetTermChildren(Term term, AweCsomeTag parent)
        {
            var currentTag = new AweCsomeTag
            {
                Name     = term.Name,
                Id       = term.Id,
                ParentId = parent.Id,
                Children = new List <AweCsomeTag>()
            };

            if (term.TermsCount > 0)
            {
                _clientContext.Load(term.Terms);
                _clientContext.ExecuteQuery();
                foreach (var child in term.Terms)
                {
                    currentTag.Children.Add(GetTermChildren(child, currentTag));
                }
            }
            return(currentTag);
        }