本文整理汇总了C#中TermStore.GetSiteCollectionGroup方法的典型用法代码示例。如果您正苦于以下问题:C# TermStore.GetSiteCollectionGroup方法的具体用法?C# TermStore.GetSiteCollectionGroup怎么用?C# TermStore.GetSiteCollectionGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TermStore
的用法示例。
在下文中一共展示了TermStore.GetSiteCollectionGroup方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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(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
//.........这里部分代码省略.........
示例3: LookupTermSet
public static TermSet LookupTermSet(ClientRuntimeContext context, TermStore termStore,
Site site,
string termGroupName, Guid? termGroupId, bool? isSiteCollectionGroup,
string termSetName, Guid? termSetId, int termSetLCID)
{
var storeContext = context;
TermGroup currenGroup = null;
if (!string.IsNullOrEmpty(termGroupName))
{
currenGroup = termStore.Groups.GetByName(termGroupName);
storeContext.Load(currenGroup);
storeContext.ExecuteQueryWithTrace();
}
else if (termGroupId != null && termGroupId.HasGuidValue())
{
currenGroup = termStore.Groups.GetById(termGroupId.Value);
storeContext.Load(currenGroup);
storeContext.ExecuteQueryWithTrace();
}
else if (isSiteCollectionGroup == true)
{
currenGroup = termStore.GetSiteCollectionGroup(site, false);
storeContext.Load(currenGroup);
storeContext.ExecuteQueryWithTrace();
}
if (!string.IsNullOrEmpty(termSetName))
{
if (currenGroup != null && (currenGroup.ServerObjectIsNull == false))
{
TermSet termSet = null;
var scope = new ExceptionHandlingScope(storeContext);
using (scope.StartScope())
{
using (scope.StartTry())
{
termSet = currenGroup.TermSets.GetByName(termSetName);
storeContext.Load(termSet);
}
using (scope.StartCatch())
{
}
}
storeContext.ExecuteQueryWithTrace();
if (termSet != null && termSet.ServerObjectIsNull == false)
{
storeContext.Load(termSet, g => g.Id);
storeContext.ExecuteQueryWithTrace();
return termSet;
}
}
else
{
var termSets = termStore.GetTermSetsByName(termSetName, termSetLCID);
storeContext.Load(termSets);
storeContext.ExecuteQueryWithTrace();
return termSets.FirstOrDefault();
}
}
if (termSetId.HasGuidValue())
{
if (currenGroup != null && (currenGroup.ServerObjectIsNull == false))
{
TermSet termSet = null;
var scope = new ExceptionHandlingScope(storeContext);
using (scope.StartScope())
{
using (scope.StartTry())
{
termSet = currenGroup.TermSets.GetById(termSetId.Value);
storeContext.Load(termSet);
}
using (scope.StartCatch())
{
}
}
storeContext.ExecuteQueryWithTrace();
if (termSet != null && termSet.ServerObjectIsNull == false)
{
storeContext.Load(termSet, g => g.Id);
storeContext.ExecuteQueryWithTrace();
//.........这里部分代码省略.........
示例4: LookupTermSet
public static TermSet LookupTermSet(
TermStore tesmStore,
string termGroupName, Guid? groupId, bool? isSiteCollectionGroup, SPSite site,
string termSetName, Guid? termSetId, int termSetLCID)
{
Group currentGroup = null;
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);
}
if (termSetId.HasGuidValue())
{
if (currentGroup != null)
return currentGroup.TermSets.FirstOrDefault(t => t.Id == termSetId.Value);
return tesmStore.GetTermSet(termSetId.Value);
}
if (!string.IsNullOrEmpty(termSetName))
{
if (currentGroup != null)
return currentGroup.TermSets.FirstOrDefault(t => t.Name.ToUpper() == termSetName.ToUpper());
return tesmStore.GetTermSets(termSetName, termSetLCID).FirstOrDefault();
}
return null;
}
示例5: CreateTermSet
private TermSet CreateTermSet(TermStore termStore, Guid termSetID, SPWeb currentWeb, TermStoreType tsType)
{
//termSet is null. Create new termSet, and set the property in the property bag.
Group siteCollectionGroup = termStore.GetSiteCollectionGroup(currentWeb.Site);
//Group navTermsGroup = termStore.Groups["Navigation"]; //TODO: Get this from configuration or passed in.
string termStoreName = (tsType == TermStoreType.Global) ? string.Format("Global_Nav_For{0}", termSetID) : string.Format("Local_Nav_For{0}", termSetID);
TermSet newTermSet = siteCollectionGroup.CreateTermSet(termStoreName, termSetID);
NavigationTermSet navTermSet = NavigationTermSet.GetAsResolvedByWeb(newTermSet, currentWeb, StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider);
navTermSet.IsNavigationTermSet = true;
navTermSet.TargetUrlForChildTerms.Value = "~site/SitePages/Home.aspx";
uint langID = (uint) currentWeb.Locale.LCID;
string webTemplateID = Convert.ToString(currentWeb.Site.RootWeb.AllProperties["MARTA.WebTemplateID"]);
string termStoreType = (tsType == TermStoreType.Global) ? "Global" : "Local";
string termMap = SPUtility.GetLocalizedString(string.Format("$Resources:MARTANavigation,{0}_{1}", webTemplateID, termStoreType) , "MARTANavigation", langID);
string relativeURL = currentWeb.Site.ServerRelativeUrl;
BuildNavTerms(navTermSet, termMap, relativeURL);
termStore.CommitAll();
return newTermSet;
//Add this to the property bag of the web as well.
}
示例6: GetReturnFlag
/// <summary>
/// Iterates through the taxonomy hierarchy for the specified term set group.
/// </summary>
/// <param name="clientContext">Client content for specified site</param>
/// <param name="termStore">Term Store object</param>
/// <param name="termStoreDetails">Term Store object containing Term store data</param>
/// <returns>Fetch Group Terms Status</returns>
internal static string GetReturnFlag(ClientContext clientContext, TermStore termStore, TermStoreDetails termStoreDetails)
{
string returnFlagStatus = ConstantStrings.FALSE;
if (ServiceConstantStrings.IsTenantDeployment)
{
foreach (TermGroup termGroup in termStore.Groups)
{
if (termGroup.Name == termStoreDetails.TermGroup)
{
returnFlagStatus = FetchGroupTerms(clientContext, termGroup, termStoreDetails, returnFlagStatus);
}
}
}
else
{
TermGroup termGroup = termStore.GetSiteCollectionGroup(clientContext.Site, false);
returnFlagStatus = FetchGroupTerms(clientContext, termGroup, termStoreDetails, returnFlagStatus);
}
// Returns the taxonomy hierarchy for the specified term set group
return returnFlagStatus;
}
示例7: DeleteTermGroupsImplementation
private void DeleteTermGroupsImplementation(ClientContext cc, TermStore termStore)
{
cc.Load(termStore.Groups, p => p.Include(t => t.Name, t => t.TermSets.Include(s => s.Name, s => s.Terms.Include(q => q.IsDeprecated, q => q.ReusedTerms))));
cc.ExecuteQueryRetry();
foreach (var termGroup in termStore.Groups.ToList())
{
DeleteTermGroupImplementation(cc, termGroup);
}
var siteCollectionGroup = termStore.GetSiteCollectionGroup(cc.Site, true);
cc.Load(siteCollectionGroup, t => t.Name, t => t.TermSets.Include(s => s.Name, s => s.Terms.Include(q => q.IsDeprecated, q => q.ReusedTerms)));
cc.ExecuteQueryRetry();
DeleteTermGroupImplementation(cc, siteCollectionGroup, true);
termStore.CommitAll();
termStore.UpdateCache();
cc.ExecuteQueryRetry();
}
示例8: GetTaxonomyHierarchy
/// <summary>
/// Iterates through the taxonomy hierarchy for the specified term set group.
/// </summary>
/// <param name="clientContext">Client content for specified site</param>
/// <param name="termStore">Term Store object</param>
/// <param name="termStoreDetails">Term Store object containing Term store data</param>
/// <returns>Fetch Group Terms Status</returns>
private TaxonomyResponseVM GetTaxonomyHierarchy (TermStore termStore, TermStoreDetails termStoreDetails)
{
try {
if (generalSettings.IsTenantDeployment)
{
foreach (TermGroup termGroup in termStore.Groups)
{
if (termGroup.Name == termStoreDetails.TermGroup)
{
taxonomyResponseVM = FetchGroupTerms(termGroup, termStoreDetails);
break;
}
}
}
else
{
TermGroup termGroup = termStore.GetSiteCollectionGroup(clientContext.Site, false);
taxonomyResponseVM = FetchGroupTerms(termGroup, termStoreDetails);
}
}
catch(Exception ex)
{
customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
throw;
}
return taxonomyResponseVM;
}
示例9: Import
private void Import(XmlElement groupElement, TermStore parentTermStore)
{
string groupName = groupElement.GetAttribute("Name");
Group group = null;
if (bool.Parse(groupElement.GetAttribute("IsSiteCollectionGroup")))
{
XmlNodeList siteCollectionIdNodes = groupElement.SelectNodes("./SiteCollectionAccessIds/SiteCollectionAccessId");
if (siteCollectionIdNodes != null)
{
foreach (XmlElement siteCollectionIdElement in siteCollectionIdNodes)
{
SPSite site = null;
if (!string.IsNullOrEmpty(siteCollectionIdElement.GetAttribute("Url")))
{
try
{
site = new SPSite(siteCollectionIdElement.GetAttribute("Url"));
}
catch
{
Logger.WriteWarning("Unable to locate a Site Collection at {0}", siteCollectionIdElement.GetAttribute("Url"));
}
}
else
{
try
{
site = new SPSite(new Guid(siteCollectionIdElement.GetAttribute("Id")));
}
catch
{
Logger.WriteWarning("Unable to locate a Site Collection with ID {0}", siteCollectionIdElement.GetAttribute("Id"));
}
}
if (site != null)
{
try
{
if (group == null)
{
group = parentTermStore.GetSiteCollectionGroup(site);
}
if (group != null && group.IsSiteCollectionGroup)
{
group.AddSiteCollectionAccess(site.ID);
}
}
catch (MissingMethodException)
{
Logger.WriteWarning("Unable to retrieve or add Site Collection group. SharePoint 2010 Service Pack 1 or greater is required. ID={0}, Url={1}", siteCollectionIdElement.GetAttribute("Id"), siteCollectionIdElement.GetAttribute("Url"));
}
finally
{
site.Dispose();
}
}
}
}
}
try
{
if (group == null)
group = parentTermStore.Groups[groupName];
}
catch (ArgumentException) {}
if (group == null)
{
Logger.Write("Creating Group: {0}", groupName);
#if SP2010
group = parentTermStore.CreateGroup(groupName);
#else
// Updated provided by John Calvert
if (!string.IsNullOrEmpty(groupElement.GetAttribute("Id")))
{
Guid id = new Guid(groupElement.GetAttribute("Id"));
group = parentTermStore.CreateGroup(groupName, id);
}
else
group = parentTermStore.CreateGroup(groupName);
// End update
#endif
group.Description = groupElement.GetAttribute("Description");
}
parentTermStore.CommitAll();//TEST
XmlNodeList termSetNodes = groupElement.SelectNodes("./TermSets/TermSet");
if (termSetNodes != null && termSetNodes.Count > 0)
{
foreach (XmlElement termSetElement in termSetNodes)
{
Import(termSetElement, group);
}
}
}