/// </summary>
public class DirectorySearcher : Component
{
-
+ private static readonly TimeSpan DefaultTimeSpan = new TimeSpan(-TimeSpan.TicksPerSecond);
private DirectoryEntry _SearchRoot=null;
private bool _CacheResults=true;
- private TimeSpan _ClientTimeout = new TimeSpan(-10000000);
+ private TimeSpan _ClientTimeout = DefaultTimeSpan;
private string _Filter="(objectClass=*)";
private int _PageSize=0;
private StringCollection _PropertiesToLoad=new StringCollection();
System.DirectoryServices.ReferralChasingOption.External;
private SearchScope _SearchScope=
System.DirectoryServices.SearchScope.Subtree;
- private TimeSpan _ServerPageTimeLimit=new TimeSpan(-10000000);
- private TimeSpan _serverTimeLimit = new TimeSpan(-10000000);
+ private TimeSpan _ServerPageTimeLimit = DefaultTimeSpan;
+ private TimeSpan _serverTimeLimit = DefaultTimeSpan;
private int _SizeLimit=0;
private LdapConnection _conn = null;
private string _Host=null;
/// </returns>
public SearchResult FindOne()
{
+ // TBD : should search for no more than single result
if (SrchColl.Count == 0) {
return null;
}
}
String[] attrs= new String[PropertiesToLoad.Count];
PropertiesToLoad.CopyTo(attrs,0);
-
- int connScope = LdapConnection.SCOPE_SUB;
- switch (_SearchScope)
- {
- case SearchScope.Base:
- connScope = LdapConnection.SCOPE_BASE;
- break;
-
- case SearchScope.OneLevel:
- connScope = LdapConnection.SCOPE_ONE;
- break;
-
- case SearchScope.Subtree:
- connScope = LdapConnection.SCOPE_SUB;
- break;
-
- default:
- connScope = LdapConnection.SCOPE_SUB;
- break;
+
+ LdapSearchConstraints cons = _conn.SearchConstraints;
+ if (SizeLimit > 0) {
+ cons.MaxResults = SizeLimit;
+ }
+ if (ServerTimeLimit != DefaultTimeSpan) {
+ cons.ServerTimeLimit = (int)ServerTimeLimit.TotalSeconds;
}
+ int connScope = LdapConnection.SCOPE_SUB;\r
+ switch (_SearchScope)\r
+ {\r
+ case SearchScope.Base:\r
+ connScope = LdapConnection.SCOPE_BASE;\r
+ break;\r
+\r
+ case SearchScope.OneLevel:\r
+ connScope = LdapConnection.SCOPE_ONE;\r
+ break;\r
+\r
+ case SearchScope.Subtree:\r
+ connScope = LdapConnection.SCOPE_SUB;\r
+ break;\r
+\r
+ default:\r
+ connScope = LdapConnection.SCOPE_SUB;\r
+ break;\r
+ }
LdapSearchResults lsc=_conn.Search( SearchRoot.Fdn,
- connScope,
+ connScope,
Filter,
attrs,
- false);
+ false,cons);
while(lsc.hasMore())
{
-
LdapEntry nextEntry = null;
try
{
}
catch(LdapException e)
{
- Console.WriteLine("Error: " + e.LdapErrorMessage);
- // Exception is thrown, go for next entry
- throw e;
+ switch (e.ResultCode) {
+ // in case of this return codes exception should not be thrown
+ case LdapException.SIZE_LIMIT_EXCEEDED:
+ case LdapException.TIME_LIMIT_EXCEEDED:
+ continue;
+ default :
+ throw e;
+ }
}
DirectoryEntry de = new DirectoryEntry(_conn);
PropertyCollection pcoll = new PropertyCollection();
}
}
if (!pcoll.Contains("ADsPath")) {
- pcoll["ADsPath"].Add(nextEntry.DN);
+ pcoll["ADsPath"].Add(de.Path);
}
// _SrchColl.Add(new SearchResult(de,PropertiesToLoad));
_SrchColl.Add(new SearchResult(de,pcoll));
[MonoTODO]
protected override void Dispose(bool disposing)
{
- throw new NotImplementedException();
+ if (disposing) {\r
+ if(_conn.Connected) {\r
+ _conn.Disconnect();\r
+ }\r
+ }\r
+ base.Dispose(disposing);
}
private void ClearCachedResults()