本文整理汇总了C#中TermStore.GetTerm方法的典型用法代码示例。如果您正苦于以下问题:C# TermStore.GetTerm方法的具体用法?C# TermStore.GetTerm怎么用?C# TermStore.GetTerm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TermStore
的用法示例。
在下文中一共展示了TermStore.GetTerm方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LookupTerm
public static Term LookupTerm(SPSite site, TermStore tesmStore, TaxonomyFieldDefinition taxFieldModel)
{
Group currentGroup = null;
var termGroupName = taxFieldModel.TermGroupName;
var groupId = taxFieldModel.TermGroupId;
var isSiteCollectionGroup = taxFieldModel.IsSiteCollectionGroup;
if (!string.IsNullOrEmpty(termGroupName))
{
currentGroup = tesmStore.Groups.FirstOrDefault(g => g.Name.ToUpper() == termGroupName.ToUpper());
}
else if (groupId != null && groupId.HasGuidValue())
{
currentGroup = tesmStore.GetGroup(groupId.Value);
}
else if (isSiteCollectionGroup.HasValue && isSiteCollectionGroup.Value)
{
currentGroup = tesmStore.GetSiteCollectionGroup(site);
}
// TODO
// that should also check if the TermSet is there, so to scope the term
if (currentGroup != null)
{
if (taxFieldModel.TermId.HasValue)
return tesmStore.GetTerm(taxFieldModel.TermId.Value);
if (!string.IsNullOrEmpty(taxFieldModel.TermName))
{
return tesmStore.GetTerms(taxFieldModel.TermName, taxFieldModel.TermLCID, false)
.FirstOrDefault(t => t.TermSet.Group.Name == currentGroup.Name);
}
}
else
{
if (taxFieldModel.TermId.HasValue)
return tesmStore.GetTerm(taxFieldModel.TermId.Value);
if (!string.IsNullOrEmpty(taxFieldModel.TermName))
return tesmStore.GetTerms(taxFieldModel.TermName, taxFieldModel.TermLCID, false).FirstOrDefault();
}
return null;
}
示例2: LookupTerm
public static Term LookupTerm(TermStore tesmStore, TaxonomyFieldDefinition taxFieldModel)
{
if (taxFieldModel.TermId.HasValue)
return tesmStore.GetTerm(taxFieldModel.TermId.Value);
if (!string.IsNullOrEmpty(taxFieldModel.TermName))
return tesmStore.GetTerms(taxFieldModel.TermName, taxFieldModel.TermLCID, false).FirstOrDefault();
return null;
}
示例3: LookupTerm
public static Term LookupTerm(ClientContext clientContext, TermStore termStore,
TermSet termSet,
TaxonomyFieldDefinition termModel)
{
var context = clientContext;
var site = clientContext.Site;
Term result = null;
TermGroup currenGroup = null;
var termGroupName = termModel.TermGroupName;
var termGroupId = termModel.TermGroupId;
var isSiteCollectionGroup = termModel.IsSiteCollectionGroup;
if (!string.IsNullOrEmpty(termGroupName))
{
currenGroup = termStore.Groups.GetByName(termGroupName);
context.Load(currenGroup);
context.ExecuteQueryWithTrace();
}
else if (termGroupId != null && termGroupId.HasGuidValue())
{
currenGroup = termStore.Groups.GetById(termGroupId.Value);
context.Load(currenGroup);
context.ExecuteQueryWithTrace();
}
else if (isSiteCollectionGroup == true)
{
currenGroup = termStore.GetSiteCollectionGroup(site, false);
context.Load(currenGroup);
context.ExecuteQueryWithTrace();
}
if (currenGroup != null)
{
if (termModel.TermId.HasValue)
{
// by ID, the only one match
var scope = new ExceptionHandlingScope(context);
using (scope.StartScope())
{
using (scope.StartTry())
{
result = termStore.GetTerm(termModel.TermId.Value);
context.Load(result);
}
using (scope.StartCatch())
{
}
}
context.ExecuteQueryWithTrace();
}
else if (!string.IsNullOrEmpty(termModel.TermName))
{
var terms = termStore.GetTerms(new LabelMatchInformation(context)
{
Lcid = termModel.TermLCID,
TermLabel = termModel.TermName,
TrimUnavailable = false
});
context.Load(terms, t => t.Include(
i => i.Id,
i => i.Name,
i => i.TermSet,
i => i.TermSet.Group,
i => i.TermSet.Group.Name
));
context.ExecuteQueryWithTrace();
result = terms.FirstOrDefault(t => t.TermSet.Group.Name == currenGroup.Name);
if ( (result == null) && (termSet != null ))
// sometimes label match information does not return the term
{
var allTerms = termSet.GetAllTerms();
context.Load(allTerms, t => t.Include(
i => i.Id,
i => i.Name,
i => i.TermSet,
i => i.TermSet.Group,
i => i.TermSet.Group.Name,
i => i.Labels
));
context.ExecuteQueryWithTrace();
result = allTerms.FirstOrDefault(t => (t.TermSet.Group.Name == currenGroup.Name) && (t.Labels.Any(l=>l.Value == termModel.TermName && l.Language == termModel.TermLCID)));
}
}
}
else
//.........这里部分代码省略.........
示例4: CreateNewTargetTermGroup
private void CreateNewTargetTermGroup(ClientContext sourceClientContext, ClientContext targetClientContext, TermGroup sourceTermGroup, TermStore targetTermStore, List<int> languagesToProcess)
{
TermGroup destinationTermGroup = targetTermStore.CreateGroup(sourceTermGroup.Name, sourceTermGroup.Id);
if (!string.IsNullOrEmpty(sourceTermGroup.Description))
{
destinationTermGroup.Description = sourceTermGroup.Description;
}
TermSetCollection sourceTermSetCollection = sourceTermGroup.TermSets;
if (sourceTermSetCollection.Count > 0)
{
foreach (TermSet sourceTermSet in sourceTermSetCollection)
{
sourceClientContext.Load(sourceTermSet,
set => set.Name,
set => set.Description,
set => set.Id,
set => set.Contact,
set => set.CustomProperties,
set => set.IsAvailableForTagging,
set => set.IsOpenForTermCreation,
set => set.CustomProperties,
set => set.Terms.Include(
term => term.Name,
term => term.Description,
term => term.Id,
term => term.IsAvailableForTagging,
term => term.LocalCustomProperties,
term => term.CustomProperties,
term => term.IsDeprecated,
term => term.Labels.Include(label => label.Value, label => label.Language, label => label.IsDefaultForLanguage)));
sourceClientContext.ExecuteQuery();
TermSet targetTermSet = destinationTermGroup.CreateTermSet(sourceTermSet.Name, sourceTermSet.Id, targetTermStore.DefaultLanguage);
targetClientContext.Load(targetTermSet, set => set.CustomProperties);
targetClientContext.ExecuteQuery();
UpdateTermSet(sourceClientContext, targetClientContext, sourceTermSet, targetTermSet);
foreach (Term sourceTerm in sourceTermSet.Terms)
{
Term reusedTerm = targetTermStore.GetTerm(sourceTerm.Id);
targetClientContext.Load(reusedTerm);
targetClientContext.ExecuteQuery();
Term targetTerm;
if (reusedTerm.ServerObjectIsNull.Value)
{
try
{
targetTerm = targetTermSet.CreateTerm(sourceTerm.Name, targetTermStore.DefaultLanguage, sourceTerm.Id);
targetClientContext.Load(targetTerm, term => term.IsDeprecated,
term => term.CustomProperties,
term => term.LocalCustomProperties);
targetClientContext.ExecuteQuery();
UpdateTerm(sourceClientContext, targetClientContext, sourceTerm, targetTerm, languagesToProcess);
}
catch (ServerException ex)
{
if (ex.Message.IndexOf("Failed to read from or write to database. Refresh and try again.") > -1)
{
// This exception was due to caching issues and generally is thrown when there's term reuse accross groups
targetTerm = targetTermSet.ReuseTerm(reusedTerm, false);
}
else
{
throw ex;
}
}
}
else
{
targetTerm = targetTermSet.ReuseTerm(reusedTerm, false);
}
targetClientContext.Load(targetTerm);
targetClientContext.ExecuteQuery();
targetTermStore.UpdateCache();
//Refresh session and termstore references to force reload of the term just added. This is
//needed cause there can be a update change event following next and without this trick
//the newly created termset cannot be obtained from the server
targetTermStore = GetTermStoreObject(targetClientContext);
//recursively add the other terms
ProcessSubTerms(sourceClientContext, targetClientContext, targetTermSet, targetTerm, sourceTerm, languagesToProcess, targetTermStore.DefaultLanguage);
}
}
}
targetClientContext.ExecuteQuery();
}
示例5: CreateTerm
private void CreateTerm(ClientContext context, TermStore termStore, ShTerm shTerm, TermSetItem parentTerm)
{
var spTerm = termStore.GetTerm(shTerm.Id);
context.Load(spTerm, t => t.Terms);
context.ExecuteQuery();
if (spTerm.ServerObjectIsNull != null && spTerm.ServerObjectIsNull.Value)
{
spTerm = parentTerm.CreateTerm(shTerm.Title, termStore.DefaultLanguage, shTerm.Id);
if (!string.IsNullOrEmpty(shTerm.CustomSortOrder)) spTerm.CustomSortOrder = shTerm.CustomSortOrder;
spTerm.IsAvailableForTagging = !shTerm.NotAvailableForTagging;
foreach(var prop in shTerm.CustomProperties) {
spTerm.SetCustomProperty(prop.Key, prop.Value);
}
foreach (var prop in shTerm.LocalCustomProperties)
{
spTerm.SetLocalCustomProperty(prop.Key, prop.Value);
}
context.Load(spTerm);
context.ExecuteQuery();
}
foreach (ShTerm childTerm in shTerm.Terms)
{
CreateTerm(context, termStore, childTerm, spTerm);
}
}
示例6: LookupTerm
public static Term LookupTerm(SiteModelHost currentSiteModelHost, TermStore termStore, TaxonomyFieldDefinition termModel)
{
var context = currentSiteModelHost.HostClientContext;
Term result = null;
if (termModel.TermId.HasValue)
{
var scope = new ExceptionHandlingScope(context);
using (scope.StartScope())
{
using (scope.StartTry())
{
result = termStore.GetTerm(termModel.TermId.Value);
context.Load(result);
}
using (scope.StartCatch())
{
}
}
context.ExecuteQueryWithTrace();
}
else if (!string.IsNullOrEmpty(termModel.TermName))
{
var terms = termStore.GetTerms(new LabelMatchInformation(context)
{
Lcid = termModel.TermLCID,
TermLabel = termModel.TermName,
TrimUnavailable = false
});
context.Load(terms);
context.ExecuteQueryWithTrace();
result = terms.FirstOrDefault();
}
if (result != null && result.ServerObjectIsNull == false)
{
context.Load(result);
context.ExecuteQueryWithTrace();
return result;
}
return null;
}