本文整理汇总了C#中TermStore.ValidateNotNullOrEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# TermStore.ValidateNotNullOrEmpty方法的具体用法?C# TermStore.ValidateNotNullOrEmpty怎么用?C# TermStore.ValidateNotNullOrEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TermStore
的用法示例。
在下文中一共展示了TermStore.ValidateNotNullOrEmpty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportTerms
/// <summary>
/// Imports an array of | delimited strings into the deafult site collection termstore. Specify strings in this format:
/// TermGroup|TermSet|Term
///
/// E.g. "Locations|Nordics|Sweden"
///
/// </summary>
/// <param name="site"></param>
/// <param name="termLines"></param>
/// <param name="lcid"></param>
/// <param name="termStore">The termstore to import the terms into</param>
/// <param name="delimiter"></param>
public static void ImportTerms(this Site site, string[] termLines, int lcid, TermStore termStore, string delimiter = "|")
{
termLines.ValidateNotNullOrEmpty("termLines");
termStore.ValidateNotNullOrEmpty("termStore");
var clientContext = site.Context;
TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
if (termStore.ServerObjectIsNull == true)
{
clientContext.Load(termStore);
clientContext.ExecuteQuery();
}
clientContext.Load(termStore);
clientContext.ExecuteQuery();
foreach (string line in termLines)
{
// split up
string[] items = line.Split(new string[] { delimiter }, StringSplitOptions.None);
if (items.Count() > 0)
{
string groupItem = items[0];
string groupName = groupItem;
Guid groupId = Guid.Empty;
if (groupItem.IndexOf(";#") > -1)
{
groupName = groupItem.Split(new string[] { ";#" }, StringSplitOptions.None)[0];
groupId = new Guid(groupItem.Split(new string[] { ";#" }, StringSplitOptions.None)[1]);
}
TermGroup termGroup = null;
if (groupId != Guid.Empty)
{
termGroup = termStore.Groups.GetById(groupId);
}
else
{
termGroup = termStore.Groups.GetByName(NormalizeName(groupName));
}
try
{
clientContext.Load(termGroup);
clientContext.ExecuteQuery();
}
catch
{
}
if (termGroup.ServerObjectIsNull == null)
{
groupId = Guid.NewGuid();
termGroup = termStore.CreateGroup(NormalizeName(groupName), groupId);
clientContext.Load(termGroup);
clientContext.ExecuteQuery();
}
if (items.Count() > 1)
{
// TermSet
if (termGroup.ServerObjectIsNull == false)
{
string termsetItem = items[1];
string termsetName = termsetItem;
Guid termsetId = Guid.Empty;
if (termsetItem.IndexOf(";#") > -1)
{
termsetName = termsetItem.Split(new string[] { ";#" }, StringSplitOptions.None)[0];
termsetId = new Guid(termsetItem.Split(new string[] { ";#" }, StringSplitOptions.None)[1]);
}
TermSet termSet = null;
if (termsetId != Guid.Empty)
{
termSet = termGroup.TermSets.GetById(termsetId);
}
else
{
termSet = termGroup.TermSets.GetByName(NormalizeName(termsetName));
}
clientContext.Load(termSet);
try
{
clientContext.ExecuteQuery();
}
catch { }
if (termSet.ServerObjectIsNull == null)
{
termsetId = Guid.NewGuid();
termSet = termGroup.CreateTermSet(NormalizeName(termsetName), termsetId, lcid);
clientContext.Load(termSet);
clientContext.ExecuteQuery();
}
//.........这里部分代码省略.........