Skip to content

Commit

Permalink
#15 Separate TaxonomyOperation model to not bloat main CSOMOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejValenta committed Jun 28, 2018
1 parent 3999b69 commit 99f07a5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
7 changes: 3 additions & 4 deletions FluentlySharepoint/FluentlySharePoint/CSOMOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
}
Expand Down
33 changes: 24 additions & 9 deletions FluentlySharepoint/FluentlySharePoint/Extensions/Taxonomy.cs
Original file line number Diff line number Diff line change
@@ -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();
}

}
}
15 changes: 15 additions & 0 deletions FluentlySharepoint/FluentlySharePoint/Models/TaxonomyOperation.cs
Original file line number Diff line number Diff line change
@@ -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; }

}
}

0 comments on commit 99f07a5

Please sign in to comment.