Ejemplo n.º 1
0
        public SPOTermSet(TermSet termSet)
            : base(termSet)
        {
            _termSet = termSet;

            if (_termSet.IsPropertyAvailable("Description"))
                SetProp("Description", _termSet.Description, false);
            if (_termSet.IsPropertyAvailable("Contact"))
                SetProp("Contact", _termSet.Contact, false);
            if (_termSet.IsPropertyAvailable("IsOpenForTermCreation"))
                SetProp("IsOpenForTermCreation", _termSet.IsOpenForTermCreation, false);
        }
        public SPOTermSet(TermSet termSet) : base(termSet)
        {
            _termSet = termSet;

            if (_termSet.IsPropertyAvailable("Description"))
            {
                SetProp("Description", _termSet.Description, false);
            }
            if (_termSet.IsPropertyAvailable("Contact"))
            {
                SetProp("Contact", _termSet.Contact, false);
            }
            if (_termSet.IsPropertyAvailable("IsOpenForTermCreation"))
            {
                SetProp("IsOpenForTermCreation", _termSet.IsOpenForTermCreation, false);
            }
        }
        public override void Refresh()
        {
            _termSet.RefreshLoad();
            _termSet.Context.ExecuteQuery();
            base.Refresh();

            if (_termSet.IsPropertyAvailable("Description"))
            {
                SetProp("Description", _termSet.Description, false);
            }
            if (_termSet.IsPropertyAvailable("Contact"))
            {
                SetProp("Contact", _termSet.Contact, false);
            }
            if (_termSet.IsPropertyAvailable("IsOpenForTermCreation"))
            {
                SetProp("IsOpenForTermCreation", _termSet.IsOpenForTermCreation, false);
            }
        }
Ejemplo n.º 4
0
        public static void WireUpTaxonomyField(this Web web, Field field, TermSet termSet, bool allowMultipleValues = false)
        {
            var clientContext = termSet.Context as ClientContext;

            if (!termSet.IsPropertyAvailable("TermStore"))
            {
                clientContext.Load(termSet.TermStore);
                clientContext.ExecuteQuery();
            }
            // set the SSP ID and Term Set ID on the taxonomy field
            var taxField = web.Context.CastTo <TaxonomyField>(field);

            taxField.AllowMultipleValues = allowMultipleValues;
            taxField.SspId     = termSet.TermStore.Id;
            taxField.TermSetId = termSet.Id;
            taxField.Update();
            web.Context.ExecuteQuery();
        }
        private static string TokenizeTaxonomyField(ClientContext ctx, Field field, string schemaXml)
        {
            var fieldType = schemaXml.GetXmlAttribute("Type");

            if (!fieldType.StartsWith("TaxonomyField"))
            {
                return(schemaXml);
            }

            schemaXml = schemaXml.RemoveXmlAttribute("List");
            schemaXml = schemaXml.RemoveXmlAttribute("WebId");
            schemaXml = schemaXml.RemoveXmlAttribute("SourceID");
            schemaXml = schemaXml.RemoveXmlAttribute("Version");
            //Default Value

            var taxonomyField = ctx.CastTo <TaxonomyField>(field);

            ctx.Load(taxonomyField);
            ctx.ExecuteQueryRetry();

            var defaultValue = taxonomyField.DefaultValue;

            if (!string.IsNullOrEmpty(defaultValue))
            {
                schemaXml = schemaXml.Replace(defaultValue, "");
            }

            var sspId = taxonomyField.SspId.ToString();

            schemaXml = schemaXml.Replace(sspId, "{@SspId}");

            if (taxonomyField.TermSetId != default(Guid) ||
                taxonomyField.AnchorId != default(Guid))
            {
                var     taxonomySession = TaxonomySession.GetTaxonomySession(ctx);
                var     termStore       = TermStoreUtility.GetTermStore(ctx, taxonomySession);
                TermSet termSet         = null;
                Term    anchorTerm      = null;

                if (taxonomyField.TermSetId != default(Guid))
                {
                    termSet = termStore.GetTermSet(taxonomyField.TermSetId);
                    ctx.Load(termSet, ts => ts.Name);
                }
                if (taxonomyField.AnchorId != default(Guid))
                {
                    anchorTerm = termStore.GetTerm(taxonomyField.AnchorId);
                    ctx.Load(anchorTerm, t => t.Name);
                }
                try
                {
                    ctx.ExecuteQueryRetry();
                }
                catch
                {
                    //ignore
                }

                if (termSet != null && termSet.IsPropertyAvailable("Name"))
                {
                    schemaXml = schemaXml.Replace(taxonomyField.TermSetId.ToString(), $"{{@TermSet:{termSet.Name}}}");
                }
                else
                {
                    schemaXml = schemaXml.Replace(taxonomyField.TermSetId.ToString(), $"00000000-0000-0000-0000-000000000000");
                }
                if (anchorTerm != null && anchorTerm.IsPropertyAvailable("Name"))
                {
                    schemaXml = schemaXml.Replace(taxonomyField.AnchorId.ToString(), $"{{@AnchorTermId:{anchorTerm.Name}}}");
                }
                else
                {
                    schemaXml = schemaXml.Replace(taxonomyField.AnchorId.ToString(), $"00000000-0000-0000-0000-000000000000");
                }
            }

            return(schemaXml);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Wires up MMS field to the specified term set.
        /// </summary>
        /// <param name="list">List to be processed</param>
        /// <param name="field">Field to be wired up</param>
        /// <param name="mmsGroupName">Taxonomy group</param>
        /// <param name="mmsTermSetName">Term set name</param>
        public static void WireUpTaxonomyField(this List list, Field field, TermSet termSet, bool allowMultipleValues = false)
        {
            var clientContext = list.Context as ClientContext;

            if (!termSet.IsPropertyAvailable("TermStore"))
            {
                clientContext.Load(termSet.TermStore);
                clientContext.ExecuteQuery();
            }

            // set the SSP ID and Term Set ID on the taxonomy field
            var taxField = clientContext.CastTo<TaxonomyField>(field);
            taxField.SspId = termSet.TermStore.Id;
            taxField.TermSetId = termSet.Id;
            taxField.AllowMultipleValues = allowMultipleValues;
            taxField.Update();
            clientContext.ExecuteQuery();
        }