Site Enumerator API Sample
using System;
using System.Collections.Generic;
namespace modulerixNavigation
{
public class CustomSiteEnumerator : ISiteEnumerator
{
public event EventHandler<SiteNodeEventArgs> SiteNodeEvent;
public INodesConfig Config { get; set; }
public void Cleanup()
{
}
public void GetNodes(INodesRequest Request)
{
try
{
var e = SiteNodeEvent;
if (e != null)
{
var parent = "";
if (Request.Ids.Count > 0)
parent = Request.Ids[0].Substring(1);
var sitelist = new List<NodeResponse>();
var itemcount = (50 - (Request.TreeDepth * 20));
if (itemcount < 5)
itemcount = 5;
for (int i = 1; i <= itemcount; i++)
{
var itemid = i.ToString("D3");
Config.CreateNode(new NodeInit()
{
id = "S" + parent + itemid,
SiteId = Guid.Empty,
WebId = Guid.Empty,
title = "Node " + parent + itemid,
description = "Description Node " + parent + itemid,
url = "#",
icon = "",
CollectionUrl = "",
AppUrl = "",
HasChildren = true,
tolist = sitelist,
Request = Request,
ProviderInternalObject = null,
sortindex = i
});
}
sitelist.Sort();
var Pos = 0;
var lower = Request.StartIndex;
var upper = (lower + Request.MaxItems - 1);
if (upper < lower)
upper = (sitelist.Count - 1);
sitelist.ForEach(item =>
{
if (Pos >= lower && Pos <= upper)
e(this, new SiteNodeEventArgs
{
NodeResponse = item,
Request = Request
});
Pos++;
});
}
}
catch (Exception exeption) { Request.EndRequestError = exeption.Message; }
}
}
}
modulerixNavigation Interface
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace modulerixNavigation
{
public interface ISiteEnumerator
{
event EventHandler<SiteNodeEventArgs> SiteNodeEvent;
INodesConfig Config { get; set; }
void GetNodes(INodesRequest Request);
void Cleanup();
}
public class SiteNodeEventArgs : EventArgs
{
public NodeResponse NodeResponse { get; set; }
public INodesRequest Request { get; set; }
}
public interface INodesConfig
{
Dictionary<string, string> ConfigProperties { get; set; }
void CreateNode(NodeInit init);
}
public class NodeInit
{
public string id;
public Guid SiteId;
public Guid WebId;
public string title;
public string url;
public string icon;
public string description;
public string CollectionUrl;
public string AppUrl;
public bool HasChildren;
public List<NodeResponse> tolist;
public INodesRequest Request;
public object ProviderInternalObject;
public int sortindex;
}
public interface INodesRequest
{
List<string> Ids { get; set; }
int StartIndex { get; set; }
int MaxItems { get; set; }
int TreeDepth { get; set; }
List<string> SortIndexList { get; set; }
object ProviderInternalObject { get; set; }
Dictionary<string, string> RequestProperties { get; set; }
Dictionary<string, string> ResponseProperties { get; set; }
bool EndRequestIsSPSiteID { get; set; }
int EndRequestMoreNodes { get; set; }
string EndRequestError { get; set; }
}
public class NodeResponse : IComparable<NodeResponse>
{
public Jnode Node { get; set; }
public Guid SiteId { get; set; }
public Guid WebId { get; set; }
public object ProviderInternalObject { get; set; }
public int sortindex { get; set; }
public int CompareTo(NodeResponse other)
{
if (sortindex == int.MaxValue && other.sortindex == int.MaxValue)
return Node.title.CompareTo(other.Node.title);
else
return sortindex.CompareTo(other.sortindex);
}
}
[DataContract]
public class Jnode
{
[DataMember(Name = "A")]
public string id { get; set; }
[DataMember(Name = "B")]
public string title { get; set; }
[DataMember(Name = "C")]
public string href { get; set; }
[DataMember(Name = "D", IsRequired = false, EmitDefaultValue = false)]
public string icon { get; set; }
[DataMember(Name = "E", IsRequired = false, EmitDefaultValue = false)]
public int state { get; set; }
[DataMember(Name = "F", IsRequired = false, EmitDefaultValue = false)]
public int selected { get; set; }
[DataMember(Name = "G", IsRequired = false, EmitDefaultValue = false)]
public int postback { get; set; }
[DataMember(Name = "H", IsRequired = false, EmitDefaultValue = false)]
public List<Jnode> children { get; set; }
[DataMember(Name = "I", IsRequired = false, EmitDefaultValue = false)]
public string description { get; set; }
}
}