Esempio n. 1
0
        private void RunAsyncSearch(IAsyncResult asyncResult)
        {
            try
            {
                // end the send request search operation
                SearchResponse response =
                    (SearchResponse)_ldapConnectionUsers.EndSendRequest(asyncResult);
                LdapHelper.SetLDAPConnection(_ldapConnectionUsers);
                List <string> GroupData     = new List <string>();
                List <string> GroupDataLDAP = new List <string>();
                var           groupData     = string.Empty;
                if (response != null && response.Entries.Count == 1)
                {
                    SearchResultAttributeCollection a = response.Entries[0].Attributes;

                    SearchResultEntry obj = response.Entries[0];
                    var groups            = obj.Attributes["memberOf"][0];
                    var groupCount        = ((System.Collections.CollectionBase)(obj.Attributes["memberOf"])).Count;
                    for (int i = 0; i < groupCount; i++)
                    {
                        groupData = obj.Attributes["memberOf"][i].ToString();
                        GroupData.Add(groupData.ToString().Split('=')[1].Split(',')[0]);
                        GroupDataLDAP.Add(groupData);
                    }
                }
                watchGetGrioups.Stop();
                var elapsedMsForParentGourps = watchGetGrioups.ElapsedMilliseconds;
                Console.WriteLine("Parent Groups:-" + elapsedMsForParentGourps);
                var watchGetNestedGrioups = System.Diagnostics.Stopwatch.StartNew();
                // LdapHelper.GtGroups();
                //GetNestedGroups(GroupDataLDAP);
                LdapHelper.GetLdapGroups();
                GetUsers(GroupDataLDAP);
                //watchGetNestedGrioups.Stop();
                //var elapsedMsFornestedGourps = watchGetNestedGrioups.ElapsedMilliseconds;
                //Console.WriteLine("Nested Groups:-" + elapsedMsFornestedGourps);
                //GroupData.AddRange(LdapHelper._subGroupList);
                //GroupData = GroupData.Distinct().OrderBy(x => x).ToList();
                //Console.WriteLine("\n");
                //foreach (var item in GroupData)
                //{

                //    Console.WriteLine(item);
                //}
                //    LdapHelper.GetLdapGroups();
                //LdapHelper.GetUsersLdap();
                Console.WriteLine("Search Ended");
            }

            catch (DirectoryOperationException e)
            {
                Console.WriteLine(e.Message);
                SearchResponse response = (SearchResponse)e.Response;

                foreach (SearchResultEntry entry in response.Entries)
                {
                    Console.WriteLine("{0}:{1}",
                                      response.Entries.IndexOf(entry),
                                      entry.DistinguishedName);
                }
            }
            catch (LdapException e)
            {
                Console.WriteLine(e.Message);
            }
        }