Exemplo n.º 1
0
        protected override void ExecuteCmdlet()
        {
            var taxonomySession = TaxonomySession.GetTaxonomySession(ClientContext);
            // Get Term Store
            TermStore termStore = null;

            if (TermStore == null)
            {
                termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
            }
            else
            {
                termStore = TermStore.GetTermStore(taxonomySession);
            }
            termStore.EnsureProperty(ts => ts.DefaultLanguage);

            TermGroup termGroup = TermGroup.GetGroup(termStore);

            TermSet termSet = TermSet.GetTermSet(termGroup);

            if (Id == Guid.Empty)
            {
                Id = Guid.NewGuid();
            }
            var termName = TaxonomyExtensions.NormalizeName(Name);

            if (!ParameterSpecified(nameof(Lcid)))
            {
                Lcid = termStore.EnsureProperty(ts => ts.DefaultLanguage);
            }

            var term = termSet.CreateTerm(termName, Lcid, Id);

            ClientContext.Load(term);
            ClientContext.ExecuteQueryRetry();
            term.SetDescription(Description, Lcid);

            var customProperties = CustomProperties ?? new Hashtable();

            foreach (var key in customProperties.Keys)
            {
                term.SetCustomProperty(key as string, customProperties[key] as string);
            }

            var localCustomProperties = LocalCustomProperties ?? new Hashtable();

            foreach (var key in localCustomProperties.Keys)
            {
                term.SetLocalCustomProperty(key as string, localCustomProperties[key] as string);
            }
            termStore.CommitAll();
            ClientContext.Load(term);
            ClientContext.ExecuteQueryRetry();
            WriteObject(term);
        }
Exemplo n.º 2
0
        protected override void ExecuteCmdlet()
        {
            var taxonomySession = TaxonomySession.GetTaxonomySession(ClientContext);

            TermStore termStore = null;

            if (TermStore == null)
            {
                termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
            }
            else
            {
                termStore = TermStore.GetTermStore(taxonomySession);
            }

            termStore.EnsureProperty(ts => ts.Languages);

            Term term = null;

            if (ParameterSetName == ParameterSet_BYID)
            {
                term = Term.GetTerm(ClientContext, termStore, null, false, null);
            }
            else
            {
                TermGroup termGroup = TermGroup.GetGroup(termStore);

                TermSet termSet = TermSet.GetTermSet(termGroup);

                term = Term.GetTerm(ClientContext, termStore, termSet, false, null);
            }
            if (term != null)
            {
                if (ParameterSpecified(nameof(Lcid)))
                {
                    var languageLabels = term.GetAllLabels(Lcid);
                    ClientContext.Load(languageLabels);
                    ClientContext.ExecuteQueryRetry();
                    WriteObject(languageLabels);
                }
                else
                {
                    List <Label> labels = new List <Label>();
                    foreach (var language in termStore.Languages)
                    {
                        var languageLabels = term.GetAllLabels(language);
                        ClientContext.Load(languageLabels);
                        ClientContext.ExecuteQueryRetry();
                        labels.AddRange(languageLabels);
                    }
                    WriteObject(labels, true);
                }
            }
        }
Exemplo n.º 3
0
        protected override void ExecuteCmdlet()
        {
            var taxonomySession = TaxonomySession.GetTaxonomySession(ClientContext);

            TermStore termStore = null;

            if (TermStore == null)
            {
                termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
            }
            else
            {
                termStore = TermStore.GetTermStore(taxonomySession);
            }


            termStore.EnsureProperty(ts => ts.Languages);

            Term term = null;

            if (ParameterSetName == ParameterSet_BYID)
            {
                term = Term.GetTerm(ClientContext, termStore, null, false, null);
            }
            else
            {
                var termGroup = TermGroup.GetGroup(termStore);
                var termSet   = TermSet.GetTermSet(termGroup);

                term = Term.GetTerm(ClientContext, termStore, termSet, false, null);
            }
            if (term != null)
            {
                term.EnsureProperties(t => t.Name, t => t.Id);
                if (ShouldProcess($"Delete label {Label} for language {Lcid} from Term {term.Name} with id {term.Id}"))
                {
                    var labels = term.GetAllLabels(Lcid);
                    ClientContext.Load(labels);
                    ClientContext.ExecuteQueryRetry();
                    var label = labels.FirstOrDefault(l => l.Value == Label);
                    if (label != null)
                    {
                        label.DeleteObject();
                        termStore.CommitAll();
                        ClientContext.ExecuteQueryRetry();
                    }
                    else
                    {
                        throw new PSArgumentException($"Label {Label} not found for language {Lcid}");
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected override void ExecuteCmdlet()
        {
            var taxonomySession = TaxonomySession.GetTaxonomySession(ClientContext);

            TermStore termStore = null;

            if (TermStore == null)
            {
                termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
            }
            else
            {
                termStore = TermStore.GetTermStore(taxonomySession);
            }

            termStore.EnsureProperty(ts => ts.DefaultLanguage);

            Term term = null;

            if (ParameterSetName == ParameterSet_BYID)
            {
                term = Term.GetTerm(ClientContext, termStore, null, false, null);
            }
            else
            {
                var termGroup = TermGroup.GetGroup(termStore);
                var termSet   = TermSet.GetTermSet(termGroup);
                term = Term.GetTerm(ClientContext, termStore, termSet, false, null);
            }

            var label = term.CreateLabel(Name, Lcid, IsDefault.IsPresent ? IsDefault.ToBool() : false);

            ClientContext.Load(label);
            ClientContext.ExecuteQueryRetry();
            WriteObject(label);
        }
Exemplo n.º 5
0
        protected override void ExecuteCmdlet()
        {
            var taxonomySession = TaxonomySession.GetTaxonomySession(ClientContext);
            // Get Term Store
            TermStore termStore = null;

            if (TermStore == null)
            {
                termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
            }
            else
            {
                termStore = TermStore.GetTermStore(taxonomySession);
            }
            termStore.EnsureProperty(ts => ts.DefaultLanguage);

            var termGroup = TermGroup.GetGroup(termStore);
            var termSet   = TermSet.GetTermSet(termGroup);
            var term      = Identity.GetTerm(ClientContext, termStore, termSet, false, null);

            if (ParameterSpecified(nameof(Name)))
            {
                term.Name = TaxonomyExtensions.NormalizeName(Name);
            }
            if (ParameterSpecified(nameof(Description)))
            {
                if (!ParameterSpecified(nameof(Lcid)))
                {
                    Lcid = termStore.EnsureProperty(ts => ts.DefaultLanguage);
                }
                term.SetDescription(Description, Lcid);
            }
            if (ParameterSpecified(nameof(DeleteAllCustomProperties)))
            {
                term.DeleteAllCustomProperties();
            }
            if (ParameterSpecified(nameof(DeleteAllLocalCustomProperties)))
            {
                term.DeleteAllLocalCustomProperties();
            }
            if (ParameterSpecified(nameof(CustomProperties)))
            {
                var customProperties = CustomProperties ?? new Hashtable();
                foreach (var key in customProperties.Keys)
                {
                    term.SetCustomProperty(key as string, customProperties[key] as string);
                }
            }
            if (ParameterSpecified(nameof(LocalCustomProperties)))
            {
                var localCustomProperties = LocalCustomProperties ?? new Hashtable();
                foreach (var key in localCustomProperties.Keys)
                {
                    term.SetCustomProperty(key as string, localCustomProperties[key] as string);
                }
            }
            if (ParameterSpecified(nameof(Deprecated)))
            {
                term.Deprecate(Deprecated);
            }
            ClientContext.Load(term);
            termStore.CommitAll();
            ClientContext.ExecuteQueryRetry();
            WriteObject(term);
        }