当前位置: 首页>>代码示例>>C#>>正文


C# Term.CreateLabel方法代码示例

本文整理汇总了C#中Term.CreateLabel方法的典型用法代码示例。如果您正苦于以下问题:C# Term.CreateLabel方法的具体用法?C# Term.CreateLabel怎么用?C# Term.CreateLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Term的用法示例。


在下文中一共展示了Term.CreateLabel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateTerm

        private void UpdateTerm(ClientContext sourceClientContext, ClientContext targetClientContext, Term sourceTerm, Term targetTerm, List<int> languagesToProcess)
        {
            targetTerm.Name = sourceTerm.Name;
            targetTerm.IsAvailableForTagging = sourceTerm.IsAvailableForTagging;

            // Process custom properties
            if (sourceTerm.LocalCustomProperties.Count > 0)
            {
                // add properties from source
                foreach (KeyValuePair<string, string> property in sourceTerm.LocalCustomProperties)
                {
                    targetTerm.SetLocalCustomProperty(property.Key, property.Value);
                }
            }

            if (targetTerm.LocalCustomProperties.Count > 0)
            {
                //remove properties which are not needed anymore
                foreach (KeyValuePair<string, string> property in targetTerm.LocalCustomProperties)
                {
                    if (!sourceTerm.LocalCustomProperties.Keys.Contains(property.Key, StringComparer.InvariantCultureIgnoreCase))
                    {
                        targetTerm.DeleteLocalCustomProperty(property.Key);
                    }
                }
            }

            if (sourceTerm.CustomProperties.Count > 0)
            {
                // add properties from source
                foreach (KeyValuePair<string, string> property in sourceTerm.CustomProperties)
                {
                    targetTerm.SetCustomProperty(property.Key, property.Value);
                }
            }

            if (targetTerm.CustomProperties.Count > 0)
            {
                //remove properties which are not needed anymore
                foreach (KeyValuePair<string, string> property in targetTerm.CustomProperties)
                {
                    if (!sourceTerm.CustomProperties.Keys.Contains(property.Key, StringComparer.InvariantCultureIgnoreCase))
                    {
                        targetTerm.DeleteCustomProperty(property.Key);
                    }
                }
            }

            targetClientContext.ExecuteQuery();

            foreach (int language in languagesToProcess)
            {
                ClientResult<string> targetTermDescription = sourceTerm.GetDescription(language);
                sourceClientContext.ExecuteQuery();
                targetTerm.SetDescription(targetTermDescription.Value, language);

                //Process labels
                // Add new labels if needed
                LabelCollection sourceLabels = sourceTerm.GetAllLabels(language);
                sourceClientContext.Load(sourceLabels);
                sourceClientContext.ExecuteQuery();
                LabelCollection targetLabels = targetTerm.GetAllLabels(language);
                targetClientContext.Load(targetLabels);
                targetClientContext.ExecuteQuery();
                foreach (Label sourceLabel in sourceLabels)
                {
                    Label test = targetLabels.FirstOrDefault<Label>(label => label.Value.Equals(sourceLabel.Value));

                    if (test == null)
                    {
                        targetTerm.CreateLabel(sourceLabel.Value, sourceLabel.Language, sourceLabel.IsDefaultForLanguage);
                    }
                }
                targetClientContext.ExecuteQuery();

                // remove non existing labels
                targetLabels = targetTerm.GetAllLabels(language);
                targetClientContext.Load(targetLabels);
                targetClientContext.ExecuteQuery();
                List<Label> labelsToRemove = new List<Label>();
                foreach (Label targetLabel in targetLabels)
                {
                    Label test = sourceLabels.FirstOrDefault<Label>(label => label.Value.Equals(targetLabel.Value));
                    if (test == null)
                    {
                        labelsToRemove.Add(targetLabel);
                    }
                }

                foreach (Label label in labelsToRemove)
                {
                    label.DeleteObject();
                    targetClientContext.ExecuteQuery();
                }
            }

            // Deprecating terms on the target is tricky...this will prevent reuse of deprecited terms later on
            //if (sourceTerm.IsDeprecated && !targetTerm.IsDeprecated)
            //{
            //    targetTerm.Deprecate(true);
//.........这里部分代码省略.........
开发者ID:AaronSaikovski,项目名称:PnP,代码行数:101,代码来源:MMSSyncManager.cs


注:本文中的Term.CreateLabel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。