Skip to content

Commit

Permalink
Merge pull request #926 from SubPointSolutions/dev
Browse files Browse the repository at this point in the history
SPMeta2 v1.2.95-beta4, October 2016
  • Loading branch information
SubPointSupport authored Oct 31, 2016
2 parents 75fea74 + ee51273 commit c114214
Show file tree
Hide file tree
Showing 78 changed files with 5,877 additions and 2,421 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace SPMeta2.CSOM.Standard.Config
{
public class MetadataNavigationHierarchyConfig
{
public MetadataNavigationHierarchyConfig(Guid fieldId)
{
this.FieldId = fieldId;
}

public Guid FieldId { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace SPMeta2.CSOM.Standard.Config
{
public class MetadataNavigationHierarchyConfig
{
#region constructors
public MetadataNavigationHierarchyConfig()
{

}
#endregion

#region properties
public Guid FieldId { get; set; }
public string FieldType { get; set; }
public string CachedName { get; set; }
public string CachedDisplayName { get; set; }
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ namespace SPMeta2.CSOM.Standard.Config
{
public class MetadataNavigationKeyFilterConfig
{
public MetadataNavigationKeyFilterConfig(Guid fieldId)
{
this.FieldId = fieldId;
}

public Guid FieldId { get; set; }
#region constructors
public MetadataNavigationKeyFilterConfig()
{

}
#endregion

#region properties
public Guid FieldId { get; set; }
public string FieldType { get; set; }
public string CachedName { get; set; }
public string CachedDisplayName { get; set; }
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,212 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Xml.Linq;
using Microsoft.SharePoint.Client;
using SPMeta2.CSOM.Extensions;
using SPMeta2.Enumerations;
using SPMeta2.Exceptions;
using SPMeta2.Utils;

namespace SPMeta2.CSOM.Standard.Config
{
public class MetadataNavigationSettingsConfig
{
#region constructors

public MetadataNavigationSettingsConfig()
{
SettingDocument = new XDocument(new XElement("MetadataNavigationSettings"));

SettingDocument.Root.SetAttribute("SchemaVersion", "1");
SettingDocument.Root.SetAttribute("IsEnabled", "True");
SettingDocument.Root.SetAttribute("AutoIndex", "True");
}

#endregion

#region properties

protected XDocument SettingDocument { get; set; }


#endregion

#region static

public static MetadataNavigationSettingsConfig GetMetadataNavigationSettings(List list)
{
throw new SPMeta2NotImplementedException("MetadataNavigationSettings provision for CSOM isnot yet implemented by M2 - https://github.com/SubPointSolutions/spmeta2/issues/738");
var result = new MetadataNavigationSettingsConfig();

var context = list.Context;

context.Load(list, l => l.RootFolder);
context.ExecuteQueryWithTrace();

#if NET35
throw new SPMeta2NotImplementedException("Not implemented for SP2010 and NET35");
#endif

#if !NET35
var props = list.RootFolder.Properties;

if (props.FieldValues.ContainsKey("client_MOSS_MetadataNavigationSettings"))
{
var value = ConvertUtils.ToString(props["client_MOSS_MetadataNavigationSettings"]);

if (!string.IsNullOrEmpty(value))
{
result.SettingDocument = XDocument.Parse(value);
}
}

#endif

return result;
}

public void AddConfiguredHierarchy(MetadataNavigationHierarchyConfig metadataNavigationHierarchy)
#endregion

#region methods

public void AddConfiguredHierarchy(MetadataNavigationHierarchyConfig item)
{
throw new SPMeta2NotImplementedException("MetadataNavigationSettings provision for CSOM isnot yet implemented by M2 - https://github.com/SubPointSolutions/spmeta2/issues/738");
var currentKey = FindConfiguredKeyFilter(item.FieldId);

if (currentKey == null)
{
var root = SettingDocument.Root;

var parentNode = root.Descendants("NavigationHierarchies").FirstOrDefault();

if (parentNode == null)
{
parentNode = new XElement("NavigationHierarchies");
root.Add(parentNode);

var folderHierarchyNode = new XElement("FolderHierarchy");

folderHierarchyNode.SetAttribute("HideFoldersNode", "False");
parentNode.Add(folderHierarchyNode);
}

var newNode = new XElement("MetadataField");

newNode.SetAttributeValue("FieldID", item.FieldId.ToString("D"));
newNode.SetAttributeValue("FieldType", item.FieldType);

newNode.SetAttributeValue("CachedName", item.CachedName);
newNode.SetAttributeValue("CachedDisplayName", item.CachedDisplayName);

parentNode.Add(newNode);
}
}

public void AddConfiguredKeyFilter(MetadataNavigationKeyFilterConfig metadataNavigationKeyFilterConfig)
public void AddConfiguredKeyFilter(MetadataNavigationKeyFilterConfig item)
{
throw new SPMeta2NotImplementedException("MetadataNavigationSettings provision for CSOM isnot yet implemented by M2 - https://github.com/SubPointSolutions/spmeta2/issues/738");
var currentKey = FindConfiguredKeyFilter(item.FieldId);

if (currentKey == null)
{
var root = SettingDocument.Root;

var parentNode = root.Descendants("KeyFilters").FirstOrDefault();

if (parentNode == null)
{
parentNode = new XElement("KeyFilters");
root.Add(parentNode);
}

var newNode = new XElement("MetadataField");

newNode.SetAttributeValue("FieldID", item.FieldId.ToString("D"));
newNode.SetAttributeValue("FieldType", item.FieldType);

newNode.SetAttributeValue("CachedName", item.CachedName);
newNode.SetAttributeValue("CachedDisplayName", item.CachedDisplayName);

parentNode.Add(newNode);
}
}

public static void SetMetadataNavigationSettings(List list, MetadataNavigationSettingsConfig settings)
{
throw new SPMeta2NotImplementedException("MetadataNavigationSettings provision for CSOM isnot yet implemented by M2 - https://github.com/SubPointSolutions/spmeta2/issues/738");
var xmlValue = settings.SettingDocument.Root.ToString();

var context = list.Context;

context.Load(list, l => l.RootFolder);
context.ExecuteQueryWithTrace();

#if NET35
throw new SPMeta2NotImplementedException("Not implemented for SP2010 and NET35");
#endif

#if !NET35

list.RootFolder.Properties["client_MOSS_MetadataNavigationSettings"] = xmlValue;
list.RootFolder.Update();
list.Update();

context.ExecuteQueryWithTrace();
#endif
}

public MetadataNavigationHierarchyConfig FindConfiguredHierarchy(Guid guid)
{
throw new SPMeta2NotImplementedException("MetadataNavigationSettings provision for CSOM isnot yet implemented by M2 - https://github.com/SubPointSolutions/spmeta2/issues/738");
var root = SettingDocument.Root;
var parentNode = root.Descendants("NavigationHierarchies").FirstOrDefault();

if (parentNode == null)
return null;

var nodes = parentNode.Descendants("MetadataField");
var targetNode = nodes.FirstOrDefault(n => n.GetAttributeValue("FieldID") == guid.ToString("D"));

if (targetNode != null)
{
var result = new MetadataNavigationHierarchyConfig();

result.FieldId = ConvertUtils.ToGuid(targetNode.GetAttributeValue("FieldID")).Value;

result.FieldType = ConvertUtils.ToString(targetNode.GetAttributeValue("FieldType"));
result.CachedDisplayName = ConvertUtils.ToString(targetNode.GetAttributeValue("CachedDisplayName"));
result.CachedName = ConvertUtils.ToString(targetNode.GetAttributeValue("CachedName"));

return result;
}

return null;
}

public MetadataNavigationKeyFilterConfig FindConfiguredKeyFilter(Guid guid)
{
throw new SPMeta2NotImplementedException("MetadataNavigationSettings provision for CSOM isnot yet implemented by M2 - https://github.com/SubPointSolutions/spmeta2/issues/738");
var root = SettingDocument.Root;
var parentNode = root.Descendants("KeyFilters").FirstOrDefault();

if (parentNode == null)
return null;

var nodes = parentNode.Descendants("MetadataField");
var targetNode = nodes.FirstOrDefault(n => n.GetAttributeValue("FieldID") == guid.ToString("D"));

if (targetNode != null)
{
var result = new MetadataNavigationKeyFilterConfig();

result.FieldId = ConvertUtils.ToGuid(targetNode.GetAttributeValue("FieldID")).Value;

result.FieldType = ConvertUtils.ToString(targetNode.GetAttributeValue("FieldType"));
result.CachedDisplayName = ConvertUtils.ToString(targetNode.GetAttributeValue("CachedDisplayName"));
result.CachedName = ConvertUtils.ToString(targetNode.GetAttributeValue("CachedName"));

return result;
}

return null;
}

#endregion
}
}
Loading

0 comments on commit c114214

Please sign in to comment.