public SearchResultCollection FindAll() { List <string> sPaths = deSearchRoot.FindAllChild(sFilter, searchScope, propertiesToLoad); SearchResultCollection collectionResult = new SearchResultCollection(); if (sPaths != null && sPaths.Count > 0) { foreach (string path in sPaths) { collectionResult.Add(new SearchResult(path)); if (sizeLimit != 0 && collectionResult.Count == sizeLimit) { break; } } } return(collectionResult); }
private void DoSearch() { InitBlock(); String[] attrs = new String[PropertiesToLoad.Count]; PropertiesToLoad.CopyTo(attrs, 0); LdapSearchConstraints cons = _conn.SearchConstraints; if (SizeLimit > 0) { cons.MaxResults = SizeLimit; } if (ServerTimeLimit != DefaultTimeSpan) { cons.ServerTimeLimit = (int)ServerTimeLimit.TotalSeconds; } 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; } LdapSearchResults lsc = _conn.Search(SearchRoot.Fdn, connScope, Filter, attrs, PropertyNamesOnly, cons); while (lsc.hasMore()) { LdapEntry nextEntry = null; try { nextEntry = lsc.next(); } catch (LdapException 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: case LdapException.REFERRAL: continue; default: throw e; } } DirectoryEntry de = new DirectoryEntry(_conn); PropertyCollection pcoll = new PropertyCollection(); // de.SetProperties(); de.Path = DirectoryEntry.GetLdapUrlString(_Host, _Port, nextEntry.DN); LdapAttributeSet attributeSet = nextEntry.getAttributeSet(); System.Collections.IEnumerator ienum = attributeSet.GetEnumerator(); if (ienum != null) { while (ienum.MoveNext()) { LdapAttribute attribute = (LdapAttribute)ienum.Current; string attributeName = attribute.Name; pcoll[attributeName].AddRange(attribute.StringValueArray); // de.Properties[attributeName].AddRange(attribute.StringValueArray); // de.Properties[attributeName].Mbit=false; } } if (!pcoll.Contains("ADsPath")) { pcoll["ADsPath"].Add(de.Path); } // _SrchColl.Add(new SearchResult(de,PropertiesToLoad)); _SrchColl.Add(new SearchResult(de, pcoll)); } return; }