Exemplo n.º 1
0
        internal static IEnumerable <ExtendedOrganizationalUnit> FindSubTreeChildOrganizationalUnit(bool includeContainers, IConfigurationSession session, ADObjectId rootId, QueryFilter preFilter)
        {
            QueryFilter queryFilter = new OrFilter(new QueryFilter[]
            {
                new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, ADOrganizationalUnit.MostDerivedClass),
                new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, ADDomain.MostDerivedClass)
            });

            if (!ExtendedOrganizationalUnit.IsTenant(session))
            {
                IList <QueryFilter>    list       = new List <QueryFilter>();
                IList <QueryFilter>    list2      = new List <QueryFilter>();
                IEnumerable <ADDomain> enumerable = ADForest.GetLocalForest(session.DomainController).FindDomains();
                foreach (ADDomain addomain in enumerable)
                {
                    ExchangeOrganizationalUnit exchangeOrganizationalUnit = session.ResolveWellKnownGuid <ExchangeOrganizationalUnit>(WellKnownGuid.DomainControllersWkGuid, addomain.Id);
                    if (exchangeOrganizationalUnit != null)
                    {
                        list.Add(new ComparisonFilter(ComparisonOperator.NotEqual, ADObjectSchema.Id, exchangeOrganizationalUnit.Id));
                    }
                    ExchangeOrganizationalUnit exchangeOrganizationalUnit2 = session.ResolveWellKnownGuid <ExchangeOrganizationalUnit>(WellKnownGuid.UsersWkGuid, addomain.Id);
                    if (exchangeOrganizationalUnit2 != null)
                    {
                        list2.Add(new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Id, exchangeOrganizationalUnit2.Id));
                    }
                }
                foreach (QueryFilter queryFilter2 in list)
                {
                    queryFilter = new AndFilter(new QueryFilter[]
                    {
                        queryFilter,
                        queryFilter2
                    });
                }
                if (includeContainers)
                {
                    foreach (QueryFilter queryFilter3 in list2)
                    {
                        queryFilter = new OrFilter(new QueryFilter[]
                        {
                            queryFilter,
                            queryFilter3
                        });
                    }
                }
            }
            if (preFilter != null)
            {
                queryFilter = new AndFilter(new QueryFilter[]
                {
                    preFilter,
                    queryFilter
                });
            }
            return(session.FindPaged <ExtendedOrganizationalUnit>(rootId, QueryScope.SubTree, queryFilter, null, 0));
        }
Exemplo n.º 2
0
        internal static IEnumerable <ExtendedOrganizationalUnit> FindFirstLevelChildOrganizationalUnit(bool includeContainers, IConfigurationSession session, ADObjectId rootId, QueryFilter preFilter, SortBy sortBy, int pageSize)
        {
            QueryFilter queryFilter = new OrFilter(new QueryFilter[]
            {
                new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, ADOrganizationalUnit.MostDerivedClass),
                new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, ADDomain.MostDerivedClass)
            });

            if (!ExtendedOrganizationalUnit.IsTenant(session))
            {
                ExchangeOrganizationalUnit exchangeOrganizationalUnit  = session.ResolveWellKnownGuid <ExchangeOrganizationalUnit>(WellKnownGuid.DomainControllersWkGuid, rootId);
                ExchangeOrganizationalUnit exchangeOrganizationalUnit2 = session.ResolveWellKnownGuid <ExchangeOrganizationalUnit>(WellKnownGuid.UsersWkGuid, rootId);
                if (exchangeOrganizationalUnit != null)
                {
                    queryFilter = new AndFilter(new QueryFilter[]
                    {
                        queryFilter,
                        new ComparisonFilter(ComparisonOperator.NotEqual, ADObjectSchema.Id, exchangeOrganizationalUnit.Id)
                    });
                }
                if (includeContainers && exchangeOrganizationalUnit2 != null)
                {
                    queryFilter = new OrFilter(new QueryFilter[]
                    {
                        queryFilter,
                        new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Id, exchangeOrganizationalUnit2.Id)
                    });
                }
            }
            if (preFilter != null)
            {
                queryFilter = new AndFilter(new QueryFilter[]
                {
                    preFilter,
                    queryFilter
                });
            }
            return(session.FindPaged <ExtendedOrganizationalUnit>(rootId, QueryScope.OneLevel, queryFilter, sortBy, pageSize));
        }