Пример #1
0
        public virtual IEnumerable <IDirectoryObject> FindAll(
            [NotNull] AdsPath searchRootAdsPath,
            [NotNull] SearchFilter searchFilter,
            [NotNull] DirectoryProperty asqProperty)
        {
            Guard.CheckNull(searchRootAdsPath, nameof(searchRootAdsPath));
            Guard.CheckNull(searchFilter, nameof(searchFilter));
            Guard.CheckNull(asqProperty, nameof(asqProperty));

            if (asqProperty.Syntax != DirectoryPropertySyntax.DNString)
            {
                throw new DirectoryServicesException(ErrorMessages.DirectoryServicesException_InvalidAsqPropertySyntax);
            }

            logger.Debug(
                "Search multiple objects in {SearchRoot} by {AsqProperty} with filter {SearchFilter}.",
                searchRootAdsPath,
                asqProperty,
                searchFilter);

            using (var root = new DirectoryEntry(searchRootAdsPath))
            {
                var searcher = CreateDirectorySearcher(searchFilter, root);
                searcher.SearchScope         = SearchScope.Base;
                searcher.AttributeScopeQuery = asqProperty;
                searcher.ReferralChasing     = ReferralChasingOption.All;
                searcher.PropertyNamesOnly   = true;

                var results = FindAllInternal(searcher);
                return(results);
            }
        }
Пример #2
0
        public virtual IDirectoryObject FindOne([NotNull] AdsPath searchRoot, [NotNull] SearchFilter searchFilter)
        {
            Guard.CheckNull(searchRoot, nameof(searchRoot));
            Guard.CheckNull(searchFilter, nameof(searchFilter));

            using (var root = new DirectoryEntry(searchRoot))
            {
                logger.Debug("Search one object in {SearchRoot} by filter {SearchFilter}.", searchRoot, searchFilter);

                var searcher     = CreateDirectorySearcher(searchFilter, root);
                var searchResult = searcher.FindOne();

                // ReSharper disable once ConditionIsAlwaysTrueOrFalse - Reason: Incorrect analysis
                // ReSharper disable HeuristicUnreachableCode - Reason: Incorrect analysis
                if (searchResult == null)
                {
                    logger.Debug("Search has no result.");
                    return(null);
                }
                // ReSharper restore HeuristicUnreachableCode

                var directoryEntry = searchResult.GetDirectoryEntry();

                var directoryObject = directoryEntry.ToDirectoryObject();

                logger.Debug("{DirectoryObject} has been found.", directoryObject);

                return(directoryObject);
            }
        }
Пример #3
0
 public virtual T FindOne <T>(
     [NotNull] AdsPath searchRoot,
     [NotNull] DirectoryProperty directoryProperty,
     object propertyValue)
     where T : class, IDirectoryObject
 {
     return(FindOne(searchRoot, directoryProperty, propertyValue) as T);
 }
Пример #4
0
        public virtual IDirectoryObject FindOne(
            [NotNull] AdsPath searchRoot,
            [NotNull] DirectoryProperty directoryProperty,
            object propertyValue)
        {
            Guard.CheckNull(directoryProperty, nameof(directoryProperty));

            var searchFilter = SearchFilter.Equality(
                directoryProperty,
                directoryProperty.CreateSearchFilterString(propertyValue));

            return(FindOne(searchRoot, searchFilter));
        }
Пример #5
0
        public virtual IEnumerable <IDirectoryObject> FindAll(
            [NotNull] AdsPath searchRootAdsPath,
            [NotNull] SearchFilter searchFilter)
        {
            Guard.CheckNull(searchRootAdsPath, nameof(searchRootAdsPath));
            Guard.CheckNull(searchFilter, nameof(searchFilter));

            logger.Debug("Search multiple objects in {SearchRoot} by filter {SearchFilter}.", searchRootAdsPath, searchFilter);

            using (var root = new DirectoryEntry(searchRootAdsPath))
            {
                var searcher = CreateDirectorySearcher(searchFilter, root);
                var results  = FindAllInternal(searcher);
                return(results);
            }
        }
Пример #6
0
 public virtual T FindOne <T>([NotNull] AdsPath searchRoot, [NotNull] SearchFilter searchFilter)
     where T : class, IDirectoryObject
 {
     return(FindOne(searchRoot, searchFilter) as T);
 }
Пример #7
0
        public virtual IDirectoryObject GetDirectoryObject(AdsPath adsPath)
        {
            var directoryObject = new DirectoryEntry(adsPath).ToDirectoryObject();

            return(directoryObject);
        }
Пример #8
0
 public virtual T GetDirectoryObject <T>(AdsPath adsPath)
     where T : class, IDirectoryObject
 {
     return(GetDirectoryObject(adsPath) as T);
 }