コード例 #1
0
        static void Main(string[] args)
        {
            Log("\r\nTermSetImport (Server OM): Starting...\r\n");

            // Uncomment this section to create a sample input file.
#if false
            GenerateExampleXmlFile();
#else
            TermSetGoal termSetGoal = LoadTermSetGoal();

            using (SPSite site = new SPSite(siteUrl))
            {
                TaxonomySession taxonomySession = new TaxonomySession(site, updateCache: true);
                TermStore       termStore       = taxonomySession.DefaultSiteCollectionTermStore;

                Program.lcid = termStore.WorkingLanguage;

                ImportTermSet(termStore, termSetGoal);
            }
#endif

            Log("\r\nThe operation completed successfully.");

            if (Debugger.IsAttached)
            {
                Debugger.Break();
            }
        }
コード例 #2
0
        // Create the goal objects in the specified term store
        static void ImportTermSet(TermStore termStore, TermSetGoal termSetGoal)
        {
            Log("Setting up term set \"" + termSetGoal.Name + "\"");
            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("Deleting existing term set \"" + termSetGoal.Name + "\"");
                termSet.Delete();
                termStore.CommitAll();
            }

            Log("Creating new term set \"" + termSetGoal.Name + "\"");
            termSet = group.CreateTermSet(termSetGoal.Name, termSetGoal.Id);
            termStore.CommitAll();

            ImportTerms(termSet, termSetGoal);

            termStore.CommitAll();
        }
コード例 #3
0
        // This function uses the XmlSerializer to write an example input file
        // illustrating the XML syntax.
        static void GenerateExampleXmlFile()
        {
            TermSetGoal termSet = new TermSetGoal();

            termSet.Name = "TermSet";
            var parentTerm = new TermGoal()
            {
                Name = "Term1"
            };

            termSet.TermGoals.Add(parentTerm);
            parentTerm.TermGoals.Add(new TermGoal()
            {
                Name = "Term2", OtherLabels = new List <string>(new[] { "A", "B", "C" })
            });

            XmlSerializer serializer = new XmlSerializer(typeof(TermSetGoal));

            using (Stream stream = new FileStream("ExampleInput.xml", FileMode.Create))
            {
                serializer.Serialize(stream, termSet);
            }
        }