Ejemplo n.º 1
0
        /// <summary>
        /// Queries for directory entries matching a given filter up to a specified count
        /// </summary>
        /// <param name="count">The number of entries to find (-1 for no limit)</param>
        /// <returns>A SearchResultCollection containing matching directory entries</returns>
        public SearchResultCollection FindAll(int count)
        {
            // Always load ADsPath so that DirectoryEntry entities can be created
            if (!PropertiesToLoad.Contains("ADsPath"))
            {
                PropertiesToLoad.Add("ADsPath");
            }

            // Create an LDAP SearchRequest using the root's name and the provided filter, scope, and properties
            var req = new SearchRequest(SearchRoot.DistinguishedName, Filter, SearchScope, PropertiesToLoad.ToArray());

            if (count > 0)
            {
                // Limit the result size, if necessary
                req.SizeLimit = count;
            }

            // Use the SearchRoot's connection since it should already exist.
            var res = SearchRoot.Connection.SendRequest(req) as SearchResponse;

            if (res.ResultCode != ResultCode.Success)
            {
                throw new InvalidOperationException($"Error connecting to Active Directory: {res.ResultCode.ToString()}: {res.ErrorMessage}");
            }

            // Create and return a SearchResultCollection with the returned entries
            return(new SearchResultCollection(SearchRoot, res.Entries, PropertiesToLoad));
        }
Ejemplo n.º 2
0
        public PrincipalSearcher(DomainPath domainPath, DirectoryEntry searchRoot, ICollection <string> additionalPropertyNames = null)
            : base(searchRoot)
        {
            this.domainPath = domainPath;
            this.additionalPropertyNames = additionalPropertyNames;

            PropertiesToLoad.Add(ActiveDirectoryProperties.ObjectGuid);
            PropertiesToLoad.Add(ActiveDirectoryProperties.DisplayName);
            PropertiesToLoad.Add(ActiveDirectoryProperties.Member);
            PropertiesToLoad.Add(ActiveDirectoryProperties.MemberOf);

            if (additionalPropertyNames != null)
            {
                foreach (string propertyName in additionalPropertyNames)
                {
                    PropertiesToLoad.Add(propertyName);
                }
            }
        }
Ejemplo n.º 3
0
 private void NewPropertyToLoad(string propertyName)
 {
     PropertiesToLoad.Clear();
     PropertiesToLoad.Add(propertyName);
 }