Exemplo n.º 1
0
        /// <summary>
        /// Gets the users in group.
        /// </summary>
        /// <param name="group">
        /// The group.
        /// </param>
        /// <param name="eal">
        /// The eal.
        /// </param>
        /// <param name="searchedGroups">
        /// The searched groups.
        /// </param>
        /// <remarks>
        /// </remarks>
        private static void GetUsersInGroup(DirectoryEntry group, EmailAddressList eal, ArrayList searchedGroups)
        {
            // Search all users/groups in directoryentry
            var rootPath = group.Path;
            rootPath = rootPath.Substring(0, rootPath.IndexOf("/", 7) + 1);
            searchedGroups.Add(group.Path);

            for (var i = 0; i < group.Properties["member"].Count; i++)
            {
                var currentEntry = new DirectoryEntry(rootPath + group.Properties["member"][i]);
                if (GetAccountType(currentEntry) == ADAccountType.user)
                {
                    // add to eal
                    var values = currentEntry.Properties["mail"];
                    if (values.Count > 0)
                    {
                        var email = (string)values[0];
                        if (!eal.Contains(email))
                        {
                            try
                            {
                                eal.Add(email);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                else
                {
                    // see if we already had the group
                    if (!searchedGroups.Contains(currentEntry.Path))
                    {
                        GetUsersInGroup(currentEntry, eal, searchedGroups);
                    }
                }
            }
        }