Skip to content

Commit

Permalink
#15 New taxonomy method and default retrievals
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejValenta committed Jul 9, 2018
1 parent 92b1131 commit 33deca8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
61 changes: 56 additions & 5 deletions FluentlySharepoint/FluentlySharePoint/Extensions/Taxonomy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,39 @@ namespace KeenMate.FluentlySharePoint.Extensions
{
public static class Taxonomy
{
public static class DefaultRetrievals
{
public static Expression<Func<TermGroup, object>>[] TermGroup = new Expression<Func<TermGroup, object>>[]
{
g=>g.ContributorPrincipalNames,
g=>g.Description,
g=>g.GroupManagerPrincipalNames,
g=>g.IsSiteCollectionGroup,
g=>g.IsSystemGroup,
};

public static Expression<Func<TermSet, object>>[] TermSet = new Expression<Func<TermSet, object>>[]
{
s=>s.Contact,
s=>s.Description,
s=>s.IsOpenForTermCreation,
s=>s.Names,
s=>s.Stakeholders,
};

public static Expression<Func<Term, object>>[] Term = new Expression<Func<Term, object>>[]
{
t=>t.Description,
t=>t.IsDeprecated,
t=>t.IsKeyword,
t=>t.IsRoot,
t=>t.LocalCustomProperties,
t=>t.CustomProperties,
t=>t.TermsCount,
};
}


private static void EnsureTaxonomyOperation(CSOMOperation operation)
{
operation.TaxonomyOperation = operation.TaxonomyOperation ?? new TaxonomyOperation();
Expand Down Expand Up @@ -95,12 +128,12 @@ public static CSOMOperation CreateTerm(this CSOMOperation operation, string name
/// <param name="guid">Id of the term group</param>
/// <remarks>This method does not add loaded group into <see cref="TaxonomyOperation.LoadedTermGroups"/> because the name is not available yet</remarks>
/// <returns></returns>
public static CSOMOperation LoadTermGroup(this CSOMOperation operation, Guid guid)
public static CSOMOperation LoadTermGroup(this CSOMOperation operation, Guid guid, params Expression<Func<TermGroup, object>>[] retrievals)
{
var op = operation.TaxonomyOperation;

op.LastTermGroup = op.LastTermStore.Groups.GetById(guid);
operation.Load(op.LastTermGroup);
operation.Load(op.LastTermGroup, retrievals.Length == 0 ? DefaultRetrievals.TermGroup : retrievals);

return operation;
}
Expand All @@ -110,14 +143,14 @@ public static CSOMOperation LoadTermGroup(this CSOMOperation operation, Guid gui
/// </summary>
/// <param name="operation"></param>
/// <param name="name">Name of the term group</param>
/// <param name="retrivals"></param>
/// <param name="retrievals">When not retrievals are supplied <see cref="DefaultRetrievals.TermGroup"/> are used.</param>
/// <returns></returns>
public static CSOMOperation LoadTermGroup(this CSOMOperation operation, string name, params Expression<Func<TermGroup, object>>[] retrivals)
public static CSOMOperation LoadTermGroup(this CSOMOperation operation, string name, params Expression<Func<TermGroup, object>>[] retrievals)
{
var op = operation.TaxonomyOperation;

op.LastTermGroup = op.LastTermStore.Groups.GetByName(name);
operation.Load(op.LastTermGroup, retrivals);
operation.Load(op.LastTermGroup, retrievals.Length == 0 ? DefaultRetrievals.TermGroup : retrievals);

if (op.LoadedTermGroups.ContainsKey(name.ToLower()))
{
Expand Down Expand Up @@ -145,5 +178,23 @@ public static CSOMOperation SelectTermGroup(this CSOMOperation operation, string
return operation;
}

public static CSOMOperation LoadTermSet(this CSOMOperation operation, string name, params Expression<Func<TermSet, object>>[] retrievals)
{
var op = operation.TaxonomyOperation;
var key = name.ToLower();
op.LastTermSet = op.LastTermGroup.TermSets.GetByName(name);
operation.Load(op.LastTermSet, retrievals.Length == 0 ? DefaultRetrievals.TermSet : retrievals);

if (op.LoadedTermSets.ContainsKey(key))
{
op.LoadedTermSets[key] = op.LastTermSet;
}
else
{
op.LoadedTermSets.Add(key, op.LastTermSet);
}

return operation;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum LockLevel
public class TaxonomyOperation
{
public Dictionary<string, TermGroup> LoadedTermGroups { get; } = new Dictionary<string, TermGroup>(5);
public Dictionary<string, TermSet> LoadedTermSets { get; } = new Dictionary<string, TermSet>(5);
public Dictionary<string, Term> LoadedTerms { get; } = new Dictionary<string, Term>(5);

public LockLevel LevelLock { get; set; }
Expand Down

0 comments on commit 33deca8

Please sign in to comment.