diff --git a/FluentlySharepoint/FluentlySharePoint/CSOMOperation.cs b/FluentlySharepoint/FluentlySharePoint/CSOMOperation.cs index 0894f0f..2533863 100644 --- a/FluentlySharepoint/FluentlySharePoint/CSOMOperation.cs +++ b/FluentlySharepoint/FluentlySharePoint/CSOMOperation.cs @@ -4,6 +4,7 @@ using KeenMate.FluentlySharePoint.Assets; using KeenMate.FluentlySharePoint.Interfaces; using KeenMate.FluentlySharePoint.Loggers; +using KeenMate.FluentlySharePoint.Models; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.Taxonomy; @@ -34,10 +35,8 @@ public class CSOMOperation : IDisposable public List LastList { get; private set; } public ContentType LastContentType { get; private set; } - public TaxonomySession TaxonomySession { get; set; } - public TermStore TaxonomyStore { get; set; } - - + public TaxonomyOperation TaxonomyOperation { get; set; } + public CSOMOperation(ClientContext context) : this(context, null) { } diff --git a/FluentlySharepoint/FluentlySharePoint/Extensions/Taxonomy.cs b/FluentlySharepoint/FluentlySharePoint/Extensions/Taxonomy.cs index fc0e025..bae85d3 100644 --- a/FluentlySharepoint/FluentlySharePoint/Extensions/Taxonomy.cs +++ b/FluentlySharepoint/FluentlySharePoint/Extensions/Taxonomy.cs @@ -1,36 +1,51 @@ using System; +using KeenMate.FluentlySharePoint.Models; using Microsoft.SharePoint.Client.Taxonomy; namespace KeenMate.FluentlySharePoint.Extensions { public static class Taxonomy { + private static void EnsureTaxonomyOperation(CSOMOperation operation) + { + operation.TaxonomyOperation = operation.TaxonomyOperation ?? new TaxonomyOperation(); + } public static CSOMOperation OpenTaxonomySession(this CSOMOperation operation) { - operation.TaxonomySession = TaxonomySession.GetTaxonomySession(operation.Context); - operation.Context.Load(operation.TaxonomySession); + operation.TaxonomyOperation.Session = TaxonomySession.GetTaxonomySession(operation.Context); + operation.Context.Load(operation.TaxonomyOperation.Session); return operation; } public static CSOMOperation SelectTaxonomyStore(this CSOMOperation operation, string storeName="", Guid? storeGuid = null) { + var op = operation.TaxonomyOperation; if (!string.IsNullOrEmpty(storeName)) - operation.TaxonomyStore = operation.TaxonomySession.TermStores.GetByName(storeName); + op.LastTermStore = op.Session.TermStores.GetByName(storeName); else if (storeGuid.HasValue) - operation.TaxonomyStore = operation.TaxonomySession.TermStores.GetById(storeGuid.Value); + op.LastTermStore = op.Session.TermStores.GetById(storeGuid.Value); else - operation.TaxonomyStore = operation.TaxonomySession.GetDefaultSiteCollectionTermStore(); + op.LastTermStore = op.Session.GetDefaultSiteCollectionTermStore(); - operation.Context.Load(operation.TaxonomyStore); + operation.Context.Load(op.LastTermStore); return operation; } - public static CSOMOperation CreateTaxonomyGroup(this CSOMOperation operation, string name) + public static CSOMOperation CreateTermGroup(this CSOMOperation operation, string name, Guid? guid = null) { - operation.TaxonomyStore.CreateGroup() + var op = operation.TaxonomyOperation; + + op.LastTermGroup = op.LastTermStore.CreateGroup(name, guid ?? Guid.NewGuid()); + + return operation; } - + + public static CSOMOperation CreateTermSet(this CSOMOperation operation, string name, Guid? guid = null) + { + throw new NotImplementedException(); + } + } } \ No newline at end of file diff --git a/FluentlySharepoint/FluentlySharePoint/Models/TaxonomyOperation.cs b/FluentlySharepoint/FluentlySharePoint/Models/TaxonomyOperation.cs new file mode 100644 index 0000000..f20348e --- /dev/null +++ b/FluentlySharepoint/FluentlySharePoint/Models/TaxonomyOperation.cs @@ -0,0 +1,15 @@ +using Microsoft.SharePoint.Client.Taxonomy; + +namespace KeenMate.FluentlySharePoint.Models +{ + public class TaxonomyOperation + { + public TaxonomySession Session { get; set; } + public TermStore LastTermStore { get; set; } + + public TermGroup LastTermGroup { get; set; } + public TermSet LastTermSet { get; set; } + public Term LastTerm { get; set; } + + } +} \ No newline at end of file