コード例 #1
0
        // Create the TermSetGoal objects in the specified TermStore object.
        static void SyncTermSet(TermStore termStore, TermSetGoal termSetGoal)
        {
            Group group = termStore.Groups.FirstOrDefault(g => g.Name == termSetGoal.GroupName);

            if (group == null)
            {
                Log("* Creating missing group \"" + termSetGoal.GroupName + "\"");
                group = termStore.CreateGroup(termSetGoal.GroupName);
            }

            TermSet termSet = termStore.GetTermSet(termSetGoal.Id);

            if (termSet == null)
            {
                Log("* Creating missing term set \"" + termSetGoal.Name + "\"");
                termSet = group.CreateTermSet(termSetGoal.Name, termSetGoal.Id, lcid);
            }
            else
            {
                if (termSet.Group.Id != group.Id)
                {
                    Log("* Moving term set to group \"" + group.Name + "\"");
                    termSet.Move(group);
                }

                if (termSet.Name != termSetGoal.Name)
                {
                    termSet.Name = termSetGoal.Name;
                }
            }

            termStore.CommitAll();

            // Load the tree of terms as a flat list.
            Dictionary <Guid, Term> termsById = new Dictionary <Guid, Term>();

            foreach (Term term in termSet.GetAllTerms())
            {
                termsById.Add(term.Id, term);
            }

            Log("Step 1: Adds and Moves");
            ProcessAddsAndMoves(termSet, termSetGoal, termsById);

            Log("Step 2: Deletes");
            // Requery the TermSet object to reflect changes to the topology.
            termSet = termStore.GetTermSet(termSetGoal.Id);
            ProcessDeletes(termSet, termSetGoal); // Step 2

            Log("Step 3: Property Updates");
            termSet = termStore.GetTermSet(termSetGoal.Id);
            ProcessPropertyUpdates(termSet, termSetGoal); // Step 3

            termStore.CommitAll();
        }
コード例 #2
0
 public void Move(TermGroupInstance targetGroup)
 {
     m_termSet.Move(targetGroup.TermGroup);
 }
コード例 #3
0
        // If Term and TermGroup objects do not already exist, this function creates them as
        // specified by the TermSetGoal object that was read from the XML
        // input file.  The code also calls the ClientContext.Load() method to query
        // client object model properties that will be needed later.
        static TermSet CreateTermSetAndGroup(TermStore termStore, TermSetGoal termSetGoal)
        {
            // Load the data
            Program.clientContext.Load(termStore,
                                       termStoreArg => termStoreArg.WorkingLanguage,
                                       termStoreArg => termStoreArg.Groups.Include(
                                           groupArg => groupArg.Id,
                                           groupArg => groupArg.Name
                                           )
                                       );

            TermSet termSet = termStore.GetTermSet(termSetGoal.Id);

            Program.clientContext.Load(termSet,
                                       termSetArg => termSetArg.Id,
                                       termSetArg => termSetArg.Name,
                                       termSetArg => termSetArg.Group.Id);

            Program.ExecuteQuery(); // WCF CALL #1

            // Set up the group and the term set.
            Program.lcid = termStore.WorkingLanguage;

            TermGroup group = termStore.Groups.ToList().FirstOrDefault(g => g.Name == termSetGoal.GroupName);

            if (group == null)
            { // (ServerObjectIsNull is not used here)
                Log("* Creating missing group \"" + termSetGoal.GroupName + "\"");
                group = termStore.CreateGroup(termSetGoal.GroupName, Guid.NewGuid());
            }

            if (termSet.ServerObjectIsNull.Value)
            {
                Log("* Creating missing term set \"" + termSetGoal.Name + "\"");
                termSet = group.CreateTermSet(termSetGoal.Name, termSetGoal.Id, Program.lcid);
                Program.clientContext.Load(termSet,
                                           termSetArg => termSetArg.Id,
                                           termSetArg => termSetArg.Name,
                                           termSetArg => termSetArg.Group.Id);
            }


#if false
            else
            {
                if (termSet.Group.Id != group.Id)
                {
                    Log("* Moving term set to group \"" + group.Name + "\"");
                    termSet.Move(group);
                }
                else
                {
                    Log("Verified term set \"" + termSetGoal.Name + "\"");
                }
                if (termSet.Name != termSetGoal.Name)
                {
                    termSet.Name = termSetGoal.Name;
                }
            }
#endif

            return(termSet);
        }