本文整理汇总了C#中TermStore.CreateGroup方法的典型用法代码示例。如果您正苦于以下问题:C# TermStore.CreateGroup方法的具体用法?C# TermStore.CreateGroup怎么用?C# TermStore.CreateGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TermStore
的用法示例。
在下文中一共展示了TermStore.CreateGroup方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddGroup
private static TermGroup AddGroup(ClientContext clientContext, TermStore termStore)
{
var groupId = new Guid("8de44223-5a8f-41cd-b0e2-5634b0bb953b");
var termGroup = termStore.GetGroup(groupId);
clientContext.Load(termGroup);
clientContext.ExecuteQuery();
if (termGroup.ServerObjectIsNull.Value)
{
termGroup = termStore.CreateGroup("Taxonomy Navigation", groupId);
clientContext.Load(termGroup);
clientContext.ExecuteQuery();
}
return termGroup;
}
示例2: ImportGroup
public void ImportGroup(TermStore termStore, XElement groupElement, bool recurse = true)
{
//Get the group name
string groupName = (string)groupElement.Attribute("Name");
//Check if the group exists
Group group = (from termgroup in termStore.Groups where termgroup.Name == groupName select termgroup).SingleOrDefault();
//If it doesn't exist, create it
if (group == null)
{
group = termStore.CreateGroup(groupName);
}
//Create all child term sets in the group
if (recurse)
{
foreach (XElement childElement in groupElement.Elements())
{
ImportTermSet(group, childElement, recurse);
}
}
}
示例3: 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>
/// <param name="synchronizeDeletions">Remove tags that are not present in the import</param>
public static void ImportTerms(this Site site, string[] termLines, int lcid, TermStore termStore, string delimiter = "|", bool synchronizeDeletions = false)
{
var groupDict = new Dictionary<TermGroup, List<string>>();
var clientContext = site.Context;
if (termStore.ServerObjectIsNull == true)
{
clientContext.Load(termStore);
clientContext.ExecuteQueryRetry();
}
clientContext.Load(termStore);
clientContext.ExecuteQueryRetry();
foreach (var line in termLines)
{
// Find termgroup
var items = line.Split(new[] { delimiter }, StringSplitOptions.None);
if (items.Any())
{
List<string> terms = null;
var groupItem = items[0];
var groupName = groupItem;
var groupId = Guid.Empty;
if (groupItem.IndexOf(";#", StringComparison.Ordinal) > -1)
{
groupName = groupItem.Split(new[] { ";#" }, StringSplitOptions.None)[0];
groupId = new Guid(groupItem.Split(new[] { ";#" }, StringSplitOptions.None)[1]);
}
TermGroup termGroup = null;
// Cached?
if (groupDict.Any())
{
KeyValuePair<TermGroup, List<string>> groupDictItem;
if (groupId != Guid.Empty)
{
groupDictItem = groupDict.FirstOrDefault(tg => tg.Key.Id == groupId);
termGroup = groupDictItem.Key;
terms = groupDictItem.Value;
}
else
{
groupDictItem = groupDict.FirstOrDefault(tg => tg.Key.Name == groupName);
termGroup = groupDictItem.Key;
terms = groupDictItem.Value;
}
}
if (termGroup == null)
{
if (groupId != Guid.Empty)
{
termGroup = termStore.Groups.GetById(groupId);
}
else
{
termGroup = termStore.Groups.GetByName(NormalizeName(groupName));
}
try
{
clientContext.Load(termGroup);
clientContext.ExecuteQueryRetry();
groupDict.Add(termGroup, new List<string>());
terms = new List<string>();
}
catch
{
}
}
if (termGroup.ServerObjectIsNull == null)
{
if (groupId == Guid.Empty)
{
groupId = Guid.NewGuid();
}
termGroup = termStore.CreateGroup(NormalizeName(groupName), groupId);
terms = new List<string>();
clientContext.Load(termGroup);
clientContext.ExecuteQueryRetry();
groupDict.Add(termGroup, new List<string>());
//.........这里部分代码省略.........
示例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: CreateGroup
public TermGroup CreateGroup(TermStore termStore, string groupname)
{
TermGroup group = termStore.Groups.FirstOrDefault(x => x.Name == groupname);
if (group == null)
{
group = termStore.CreateGroup(groupname, Guid.NewGuid());
}
Ctx.Load(group);
Ctx.ExecuteQuery();
return group;
}
示例6: IsCurrentUserTermStoreAdministrator
/// <summary>
/// Since the administrator members like TermStore.DoesUserHavePermissions aren't available in the client API, this is currently how we check if user has permissions
/// </summary>
/// <param name="context"></param>
/// <param name="termStore"></param>
/// <returns></returns>
private bool IsCurrentUserTermStoreAdministrator(ClientContext context, TermStore termStore)
{
const string testGroupName = "SherpaTemporaryTestGroup";
var testGroupGuid = new Guid("0972a735-b89a-400f-a858-b80e29492b62");
try
{
var termGroup = termStore.CreateGroup(testGroupName, testGroupGuid);
context.ExecuteQuery();
termGroup.DeleteObject();
context.ExecuteQuery();
return true;
}
catch (Exception)
{
return false;
}
}
示例7: Import
private void Import(XmlElement groupElement, TermStore parentTermStore)
{
string groupName = groupElement.GetAttribute("Name");
Guid groupId = new Guid(groupElement.GetAttribute("Id"));
LoadWorkingLanguage(parentTermStore);
TermGroup group = null;
ExceptionHandlingScope scope = new ExceptionHandlingScope(_ctx);
using (scope.StartScope())
{
using (scope.StartTry())
{
group = parentTermStore.Groups.GetByName(groupName);
_ctx.Load(group);
}
using (scope.StartCatch())
{
}
}
_ctx.ExecuteQuery();
if (group == null || group.ServerObjectIsNull == null || group.ServerObjectIsNull.Value)
{
_cmdlet.WriteVerbose(string.Format("Creating Group: {0}", groupName));
group = parentTermStore.CreateGroup(groupName, groupId);
group.Description = groupElement.GetAttribute("Description");
group.Context.ExecuteQuery();
parentTermStore.CommitAll();
parentTermStore.Context.ExecuteQuery();
}
XmlNodeList termSetNodes = groupElement.SelectNodes("./TermSets/TermSet");
if (termSetNodes != null && termSetNodes.Count > 0)
{
foreach (XmlElement termSetElement in termSetNodes)
{
Import(termSetElement, group);
}
}
}
示例8: 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();
}
//.........这里部分代码省略.........
示例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);
}
}
}
示例10: CreateTargetNewTermGroup
private void CreateTargetNewTermGroup(ClientContext sourceClientContext, ClientContext targetClientContext, TermGroup sourceTermGroup, TermStore targetTermStore)
{
try
{
this._destinationTermGroup = targetTermStore.CreateGroup(sourceTermGroup.Name, sourceTermGroup.Id);
if(!string.IsNullOrEmpty(sourceTermGroup.Description))
{
this._destinationTermGroup.Description = sourceTermGroup.Description;
}
TermOperation _op = new TermOperation();
_op.Term = sourceTermGroup.Name;
_op.Id = sourceTermGroup.Id.ToString();
_op.Operation = "Add";
_op.Type = "TermGroup";
this._termStoreOperations.Add(_op);
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.Terms.Include(
term => term.Name,
term => term.Id),
term => term.Description,
term => term.Contact);
sourceClientContext.ExecuteQuery();
TermSet _targetTermSet = _destinationTermGroup.CreateTermSet(_sourceTermSet.Name, _sourceTermSet.Id, targetTermStore.DefaultLanguage);
if(!string.IsNullOrEmpty(_sourceTermSet.Description))
{
_targetTermSet.Description = _sourceTermSet.Description;
}
foreach(Term _sourceTerm in _sourceTermSet.Terms)
{
Term _targetTerm = _targetTermSet.CreateTerm(_sourceTerm.Name, targetTermStore.DefaultLanguage, _sourceTerm.Id);
_op = new TermOperation();
_op.Term = _sourceTerm.Name;
_op.Id = _sourceTerm.Id.ToString();
_op.Operation = "Add";
_op.Type = "Term";
this._termStoreOperations.Add(_op);
}
}
}
try
{
targetClientContext.ExecuteQuery();
targetTermStore.CommitAll();
}
catch
{
throw;
}
}
catch
{
throw;
}
}