Esempio n. 1
0
        private IEnumerable <ADRawEntry> FindObjects(ADObjectId[] identities, IEnumerable <PropertyDefinition> propertiesToRead)
        {
            if (ADSessionSettings.GetThreadServerSettings() == null)
            {
                EcpRunspaceFactory ecpRunspaceFactory = new EcpRunspaceFactory(new InitialSessionStateSectionFactory());
                ADSessionSettings.SetThreadADContext(new ADDriverContext(ecpRunspaceFactory.CreateRunspaceServerSettings(), ContextMode.Cmdlet));
            }
            IDirectorySession  session = this.CreateAdSession();
            List <QueryFilter> filters = new List <QueryFilter>(this.properMaxCustomFilterTreeSize);
            int filterLenRemain        = 31197;
            int i = 0;

            while (i < identities.Length)
            {
                QueryFilter idFilter = new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Id, identities[i]);
                filters.Add(idFilter);
                string ldapIdFilter = LdapFilterBuilder.LdapFilterFromQueryFilter(idFilter);
                if (ldapIdFilter.Length > filterLenRemain || filters.Count == this.properMaxCustomFilterTreeSize || i == identities.Length - 1)
                {
                    ADPagedReader <ADRawEntry> entries = null;
                    try
                    {
                        entries = session.FindPagedADRawEntry(null, QueryScope.SubTree, new OrFilter(filters.ToArray()), null, this.properMaxCustomFilterTreeSize, propertiesToRead);
                    }
                    catch (ADFilterException)
                    {
                        if (this.isFirstError)
                        {
                            i -= filters.Count;
                            this.properMaxCustomFilterTreeSize /= 2;
                            filters.Clear();
                            filterLenRemain   = 31197;
                            this.isFirstError = false;
                            goto IL_22E;
                        }
                        throw;
                    }
                    foreach (ADRawEntry entry in entries)
                    {
                        yield return(entry);
                    }
                    filters.Clear();
                    filterLenRemain = 31197;
                    goto IL_216;
                }
                goto IL_216;
IL_22E:
                i++;
                continue;
IL_216:
                filterLenRemain -= ldapIdFilter.Length;
                goto IL_22E;
            }
            yield break;
        }
 internal override IEnumerable <T> PerformSearch <T>(QueryFilter filter, ADObjectId rootId, IDirectorySession session, bool deepSearch)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     if (typeof(T) != typeof(ADRawEntry))
     {
         throw new ArgumentException(Strings.ErrorInvalidType(typeof(T).Name), "type");
     }
     return((IEnumerable <T>)session.FindPagedADRawEntry(rootId, deepSearch ? QueryScope.SubTree : QueryScope.OneLevel, filter, null, 0, new PropertyDefinition[]
     {
         ADObjectSchema.Name,
         ADObjectSchema.Id,
         ADObjectSchema.ObjectClass
     }));
 }