public Task <IEnumerable <LDAPEntry> > Search(SearchLDAPEntriesParameter parameter) { IEnumerable <LDAPEntry> result = null; var level = parameter.BaseDistinguishedName.ComputeLevel(); switch (parameter.Scope) { case SearchScopeTypes.BaseObject: result = _entries.Where(r => r.DistinguishedName == parameter.BaseDistinguishedName); break; case SearchScopeTypes.SingleLevel: result = _entries.Where(r => r.DistinguishedName.EndsWith(parameter.BaseDistinguishedName) && r.Level == level + 1); break; case SearchScopeTypes.WholeSubtree: result = _entries.Where(r => r.DistinguishedName.EndsWith(parameter.BaseDistinguishedName)); break; } if (parameter.Filter != null) { var exprTree = (Expression <Func <LDAPEntry, bool> >)BuildExpression(parameter.Filter); var compiledExprTree = exprTree.Compile(); result = result.Where(compiledExprTree); } if (parameter.SizeLimit > 0) { result = result.Take(parameter.SizeLimit); } return(Task.FromResult(result)); }
private static SearchLDAPEntriesParameter Build(SearchRequest searchRequest) { var result = new SearchLDAPEntriesParameter { SizeLimit = searchRequest.SizeLimit.Value, BaseDistinguishedName = searchRequest.BaseObject.Value, Scope = (SearchScopeTypes)searchRequest.Scope.Value, Filter = Build(searchRequest.Filter) }; return(result); }