コード例 #1
0
        public ShTermGroup ExportTaxonomyGroupToConfig(ClientContext context, string groupName)
        {
            TermStore termStore = GetTermStore(context);

            var spTermGroup = termStore.Groups.ToList().FirstOrDefault(g => g.Name == groupName);

            if (spTermGroup == null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Couldn't find a taxonomy group with the name " + groupName);
                Console.ResetColor();
                return(null);
            }
            context.Load(spTermGroup, x => x.TermSets);
            context.ExecuteQuery();

            var shTermGroup = new ShTermGroup(spTermGroup.Id, spTermGroup.Name);

            foreach (var spTermSet in spTermGroup.TermSets)
            {
                var shTermSet = new ShTermSet(spTermSet.Id, spTermSet.Name);

                AddTermsToConfig(context, spTermSet, shTermSet);
                shTermGroup.TermSets.Add(shTermSet);
            }
            return(shTermGroup);
        }
コード例 #2
0
        /// <summary>
        /// Checks that no ID's in the configuration file contains duplicate Ids.
        /// Also checks that no terms at the same level have duplicate names.
        /// Both scenarios will lead to problems with 'rogue' terms and term sets
        /// </summary>
        /// <param name="shTermGroup"></param>
        /// <returns></returns>
        public void ValidateConfiguration(ShTermGroup shTermGroup)
        {
            if (shTermGroup == null)
            {
                throw new ArgumentNullException("shTermGroup");
            }

            Log.Debug("Validating taxonomy configuration");
            var termIdsForEnsuringUniqueness = new List <Guid> {
                shTermGroup.Id
            };

            foreach (var termSet in shTermGroup.TermSets)
            {
                if (termIdsForEnsuringUniqueness.Contains(termSet.Id))
                {
                    throw new NotSupportedException("One or more term items has the same Id which is not supported. Termset Id " + termSet.Id);
                }

                termIdsForEnsuringUniqueness.Add(termSet.Id);
                foreach (var term in termSet.Terms)
                {
                    if (termIdsForEnsuringUniqueness.Contains(term.Id))
                    {
                        throw new NotSupportedException("One or more term items has the same Id which is not supported. Term Id " + term.Id);
                    }

                    termIdsForEnsuringUniqueness.Add(term.Id);
                    // Terms at the same level cannot have duplicate names
                    string currentTermTitle = term.Title;
                    if (termSet.Terms.Count(t => t.Title.Equals(currentTermTitle)) != 1)
                    {
                        throw new NotSupportedException("Found duplicate term names at the same level which is not supported. Term name " + term.Title);
                    }
                }
            }
            Log.Info("Taxonomy configuration validated");
        }
コード例 #3
0
 public TaxonomyManager(ShTermGroup termGroup)
 {
     _termGroup = termGroup;
 }