-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#15 Separate TaxonomyOperation model to not bloat main CSOMOperation
- Loading branch information
1 parent
3999b69
commit 99f07a5
Showing
3 changed files
with
42 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 24 additions & 9 deletions
33
FluentlySharepoint/FluentlySharePoint/Extensions/Taxonomy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
FluentlySharepoint/FluentlySharePoint/Models/TaxonomyOperation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
|
||
} | ||
} |