예제 #1
0
        /// <summary>
        ///     Gets the ou users groups data.
        /// </summary>
        /// <param name="principalContext">The principal context.</param>
        /// <returns>IEnumerable&lt;ExpandoObject&gt;.</returns>
        /// TODO Edit XML Comment Template for GetOuUsersGroupsData
        private IEnumerable <ExpandoObject> GetOuUsersGroupsData(
            PrincipalContext principalContext)
        {
            var data = new List <ExpandoObject>();

            using (var principal = new UserPrincipal(principalContext))
                using (var principalSearcher = new PrincipalSearcher(principal))
                    using (var principalSearchResult = principalSearcher.FindAll())
                    {
                        foreach (var userPrincipal in principalSearchResult
                                 .GetUserPrincipals())
                        {
                            CancellationToken.ThrowIfCancellationRequested();
                            using (var groups = userPrincipal.GetGroups())
                            {
                                foreach (var groupPrincipal in
                                         groups.GetGroupPrincipals())
                                {
                                    CancellationToken.ThrowIfCancellationRequested();
                                    data.Add(
                                        DataPreparer.PrepareData(
                                            DefaultUserGroupsProperties,
                                            userPrincipal: userPrincipal,
                                            groupPrincipal: groupPrincipal));
                                }
                            }
                        }
                    }

            return(data);
        }
예제 #2
0
        /// <summary>
        ///     Gets the search user data.
        /// </summary>
        /// <param name="principalContext">The principal context.</param>
        /// <returns>IEnumerable&lt;ExpandoObject&gt;.</returns>
        /// TODO Edit XML Comment Template for GetSearchUserData
        private IEnumerable <ExpandoObject> GetSearchUserData(
            PrincipalContext principalContext)
        {
            var data = new List <ExpandoObject>();

            using (var principal = new UserPrincipal(principalContext))
            {
                principal.Name = Asterisk + SearchText + Asterisk;
                using (var principalSearcher = new PrincipalSearcher(principal))
                    using (var principalSearchResult = principalSearcher.FindAll())
                    {
                        foreach (var userPrincipal in principalSearchResult
                                 .GetUserPrincipals())
                        {
                            CancellationToken.ThrowIfCancellationRequested();
                            data.Add(
                                DataPreparer.PrepareData(
                                    DefaultUserProperties,
                                    userPrincipal: userPrincipal));
                        }
                    }
            }

            return(data);
        }
예제 #3
0
        /// <summary>
        ///     Gets the groups summaries data.
        /// </summary>
        /// <returns>IEnumerable&lt;ExpandoObject&gt;.</returns>
        /// TODO Edit XML Comment Template for GetGroupsSummariesData
        private IEnumerable <ExpandoObject> GetGroupsSummariesData()
        {
            var data = new List <ExpandoObject>();

            foreach (var distinguishedName in DistinguishedNames)
            {
                using (var principalContext = GetPrincipalContext())
                    using (var groupPrincipal = GroupPrincipal.FindByIdentity(
                               principalContext,
                               IdentityType.DistinguishedName,
                               distinguishedName))
                    {
                        if (groupPrincipal == null)
                        {
                            continue;
                        }

                        data.Add(
                            DataPreparer.PrepareData(
                                DefaultGroupProperties,
                                groupPrincipal: groupPrincipal));
                    }
            }

            return(data);
        }
예제 #4
0
        /// <summary>
        ///     Gets the computers summaries data.
        /// </summary>
        /// <returns>IEnumerable&lt;ExpandoObject&gt;.</returns>
        /// TODO Edit XML Comment Template for GetComputersSummariesData
        private IEnumerable <ExpandoObject> GetComputersSummariesData()
        {
            var data = new List <ExpandoObject>();

            foreach (var distinguishedName in DistinguishedNames)
            {
                CancellationToken.ThrowIfCancellationRequested();
                using (var principalContext = GetPrincipalContext())
                    using (var computerPrincipal = ComputerPrincipal.FindByIdentity(
                               principalContext,
                               IdentityType.DistinguishedName,
                               distinguishedName))
                    {
                        if (computerPrincipal == null)
                        {
                            continue;
                        }

                        data.Add(
                            DataPreparer.PrepareData(
                                DefaultComputerProperties,
                                computerPrincipal));
                    }
            }

            return(data);
        }
예제 #5
0
        /// <summary>
        ///     Gets the groups users direct reports data.
        /// </summary>
        /// <returns>IEnumerable&lt;ExpandoObject&gt;.</returns>
        /// TODO Edit XML Comment Template for GetGroupsUsersDirectReportsData
        private IEnumerable <ExpandoObject> GetGroupsUsersDirectReportsData()
        {
            var data = new List <ExpandoObject>();

            foreach (var distinguishedName in DistinguishedNames)
            {
                CancellationToken.ThrowIfCancellationRequested();
                using (var principalContext = GetPrincipalContext())
                    using (var groupPrincipal = GroupPrincipal.FindByIdentity(
                               principalContext,
                               IdentityType.DistinguishedName,
                               distinguishedName))
                    {
                        if (groupPrincipal == null)
                        {
                            continue;
                        }

                        using (var members = groupPrincipal.GetMembers())
                        {
                            foreach (var userPrincipal in
                                     members.GetUserPrincipals())
                            {
                                CancellationToken.ThrowIfCancellationRequested();
                                if (userPrincipal == null)
                                {
                                    continue;
                                }

                                foreach (var directReportDistinguishedName in
                                         userPrincipal
                                         .GetDirectReportDistinguishedNames())
                                {
                                    CancellationToken
                                    .ThrowIfCancellationRequested();
                                    using (var directReportUserPrincipal =
                                               UserPrincipal.FindByIdentity(
                                                   principalContext,
                                                   IdentityType.DistinguishedName,
                                                   directReportDistinguishedName))
                                    {
                                        data.Add(
                                            DataPreparer.PrepareData(
                                                DefaultGroupUsersDirectReportsProperties,
                                                containerGroupPrincipal:
                                                groupPrincipal,
                                                userPrincipal: userPrincipal,
                                                directReportUserPrincipal:
                                                directReportUserPrincipal));
                                    }
                                }
                            }
                        }
                    }
            }

            return(data);
        }
예제 #6
0
 /// <summary>
 ///     Initializes a new instance of the
 ///     <see cref="Searcher" /> class.
 /// </summary>
 /// <param name="queryType">Type of the query.</param>
 /// <param name="scope">The scope.</param>
 /// <param name="distinguishedNames">The distinguished names.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <param name="searchText">The search text.</param>
 /// TODO Edit XML Comment Template for #ctor
 public Searcher(
     QueryType queryType,
     Scope scope,
     IEnumerable <string> distinguishedNames,
     CancellationToken cancellationToken,
     string searchText)
 {
     QueryType          = queryType;
     Scope              = scope;
     DistinguishedNames = distinguishedNames;
     CancellationToken  = cancellationToken;
     SearchText         = searchText;
     DataPreparer       = new DataPreparer(cancellationToken);
 }
예제 #7
0
        /// <summary>
        ///     Gets the ou users direct reports data.
        /// </summary>
        /// <param name="principalContext">The principal context.</param>
        /// <returns>IEnumerable&lt;ExpandoObject&gt;.</returns>
        /// TODO Edit XML Comment Template for GetOuUsersDirectReportsData
        private IEnumerable <ExpandoObject> GetOuUsersDirectReportsData(
            PrincipalContext principalContext)
        {
            var data = new List <ExpandoObject>();

            using (var principal = new UserPrincipal(principalContext))
                using (var principalSearcher = new PrincipalSearcher(principal))
                    using (var principalSearchResult = principalSearcher.FindAll())
                    {
                        foreach (var userPrincipal in principalSearchResult
                                 .GetUserPrincipals())
                        {
                            CancellationToken.ThrowIfCancellationRequested();
                            var directReportDistinguishedNames = userPrincipal
                                                                 .GetDirectReportDistinguishedNames();
                            foreach (var directReportDistinguishedName in
                                     directReportDistinguishedNames)
                            {
                                CancellationToken.ThrowIfCancellationRequested();
                                using (var defaultPrincipalContext =
                                           GetPrincipalContext())
                                    using (var directReportUserPrincipal =
                                               UserPrincipal.FindByIdentity(
                                                   defaultPrincipalContext,
                                                   IdentityType.DistinguishedName,
                                                   directReportDistinguishedName))
                                    {
                                        if (directReportUserPrincipal == null)
                                        {
                                            continue;
                                        }

                                        data.Add(
                                            DataPreparer.PrepareData(
                                                DefaultUserDirectReportsProperties,
                                                userPrincipal: userPrincipal,
                                                directReportUserPrincipal:
                                                directReportUserPrincipal));
                                    }
                            }
                        }
                    }

            return(data);
        }
예제 #8
0
        /// <summary>
        ///     Gets the ou computers data.
        /// </summary>
        /// <param name="principalContext">The principal context.</param>
        /// <returns>IEnumerable&lt;ExpandoObject&gt;.</returns>
        /// TODO Edit XML Comment Template for GetOuComputersData
        private IEnumerable <ExpandoObject> GetOuComputersData(
            PrincipalContext principalContext)
        {
            var data = new List <ExpandoObject>();

            using (var principal = new ComputerPrincipal(principalContext))
                using (var principalSearcher = new PrincipalSearcher(principal))
                    using (var principalSearchResult = principalSearcher.FindAll())
                    {
                        foreach (var computerPrincipal in principalSearchResult
                                 .GetComputerPrincipals())
                        {
                            CancellationToken.ThrowIfCancellationRequested();
                            data.Add(
                                DataPreparer.PrepareData(
                                    DefaultComputerProperties,
                                    computerPrincipal));
                        }
                    }

            return(data);
        }
예제 #9
0
        /// <summary>
        ///     Gets the users groups data.
        /// </summary>
        /// <returns>IEnumerable&lt;ExpandoObject&gt;.</returns>
        /// TODO Edit XML Comment Template for GetUsersGroupsData
        private IEnumerable <ExpandoObject> GetUsersGroupsData()
        {
            var data = new List <ExpandoObject>();

            foreach (var distinguishedName in DistinguishedNames)
            {
                CancellationToken.ThrowIfCancellationRequested();
                using (var principalContext = GetPrincipalContext())
                    using (var userPrincipal = UserPrincipal.FindByIdentity(
                               principalContext,
                               IdentityType.DistinguishedName,
                               distinguishedName))
                    {
                        if (userPrincipal == null)
                        {
                            continue;
                        }

                        using (var groups = userPrincipal.GetGroups())
                        {
                            foreach (var groupPrincipal in
                                     groups.GetGroupPrincipals())
                            {
                                CancellationToken.ThrowIfCancellationRequested();
                                data.Add(
                                    DataPreparer.PrepareData(
                                        DefaultUserGroupsProperties,
                                        userPrincipal: userPrincipal,
                                        groupPrincipal: groupPrincipal));
                            }
                        }
                    }
            }

            return(data);
        }