Paging

Paging with S.DS.P is accomplished by setting an initial page size. The server will generate a cookie that will give you the next page. From this RFC:
The client MUST consider the cookie to be an opaque structure and make no assumptions about its internal organization or value. When the client wants to retrieve more entries for the result set, it MUST send to the server a searchRequest with all values identical to the initial request with the exception of the messageID, the cookie, and optionally a modified pageSize. The cookie MUST be the octet string on the last searchResultDone response returned by the server. Returning cookies from previous searchResultDone responses besides the last one is undefined, as the server implementation may restrict cookies from being reused.
If you know that the LDAP server you're using will work with backwards paging, you can implement client side tracking of the previous cookies, but I can't support it because it's unpredictable between servers.

By default all requests will be paged, but there are a few options to control how paging works or disable it all together.
Automatic Paging
List<User> allEntries = context.Query<User>().ToList();
Automatic Paging With a Query Specific Page Size
List<User> allEntries = context.Query<User>().InPagesOf(1000);
Manual Paging
//start paging
List<string> list = new List<string>();
ILdapPage<string> page = context.Query<User>()
   .Where(u => u.FirstName.StartsWith("A"))
   .Select(u => u.DistinguishedName)
   .ToPage(10);

list.AddRange(page);
 
//go to next page
while (page.HasNextPage)
{
   page = context.Query<User>()
      .Select(u => u.DistinguishedName)
      .ToPage(page.PageSize, page.NextPage, page.Filter);

   list.AddRange(page);
}

//start paging
LdapPage<string> page = context.Query<User>()
   .Where(u => u.FirstName.StartsWith("A"))
   .Select(u => u.DistinguishedName)
   .WithControls(new [] { new PageResultRequestControl(10) })
   .ToList() as LdapPage<string>;

list.AddRange(page);
 
//go to next page
if (page.HasNextPage)
{
   page = context.Query<User>()
      .Where(u => u.FirstName.StartsWith("A"))
      .WithControls(
          new [] { new PageResultRequestControl(10){Cookie = page.NextPage} })
      .ToList() as LdapPage<string>;

   list.AddRange(page);
}
Disable Paging
Paging can be disabled globally with the DisablePaging method on LDAP Configuration or at the query level with the WithoutPaging method. However, without paging it is possible to encounter a size limit exceeded error from the directory.

List<string> allEntries = context.Query<User>()
   .Where(u => u.FirstName.StartsWith("A"))
   .Select(u => u.DistinguishedName)
   .WithoutPaging()
   .ToList();

Last edited Jun 12, 2012 at 2:30 AM by MadHatter22, version 9