private static string GetSingleStringPropertyCollectionValue(System.DirectoryServices.PropertyCollection props, string name)
        {
            if (!props.Contains(name))
            {
                return(string.Empty);
            }

            PropertyValueCollection pvc = props[name];

            if (pvc == null || pvc.Count == 0)
            {
                return(string.Empty);
            }
            return(pvc[0] as string);
        }
예제 #2
0
		private void DoSearch()
		{
			InitBlock();
			String[] attrs= new String[PropertiesToLoad.Count];
			PropertiesToLoad.CopyTo(attrs,0);
			
			LdapSearchConstraints cons = _conn.SearchConstraints;
			if (SizeLimit > 0) {
				cons.MaxResults = SizeLimit;
			}
			if (ServerTimeLimit != DefaultTimeSpan) {
				cons.ServerTimeLimit = (int)ServerTimeLimit.TotalSeconds;
			}

			int connScope = LdapConnection.SCOPE_SUB;
			switch (_SearchScope)
			{
			case SearchScope.Base:
			  connScope = LdapConnection.SCOPE_BASE;
			  break;

			case SearchScope.OneLevel:
			  connScope = LdapConnection.SCOPE_ONE;
			  break;

			case SearchScope.Subtree:
			  connScope = LdapConnection.SCOPE_SUB;
			  break;

			default:
			  connScope = LdapConnection.SCOPE_SUB;
			  break;
			}
			LdapSearchResults lsc=_conn.Search(	SearchRoot.Fdn,
												connScope,
												Filter,
												attrs,
												PropertyNamesOnly,cons);

			while(lsc.hasMore())						
			{
				LdapEntry nextEntry = null;
				try 							
				{
					nextEntry = lsc.next();
				}
				catch(LdapException e) 							
				{
					switch (e.ResultCode) {
						// in case of this return codes exception should not be thrown
						case LdapException.SIZE_LIMIT_EXCEEDED:
						case LdapException.TIME_LIMIT_EXCEEDED:
						case LdapException.REFERRAL:
							continue;
						default :
							throw e;
					}
				}
				DirectoryEntry de = new DirectoryEntry(_conn);
				PropertyCollection pcoll = new PropertyCollection();
//				de.SetProperties();
				de.Path = DirectoryEntry.GetLdapUrlString(_Host,_Port,nextEntry.DN); 
				LdapAttributeSet attributeSet = nextEntry.getAttributeSet();
				System.Collections.IEnumerator ienum=attributeSet.GetEnumerator();
				if(ienum!=null)							
				{
					while(ienum.MoveNext())				
					{
						LdapAttribute attribute=(LdapAttribute)ienum.Current;
						string attributeName = attribute.Name;
						pcoll[attributeName].AddRange(attribute.StringValueArray);
//						de.Properties[attributeName].AddRange(attribute.StringValueArray);
//						de.Properties[attributeName].Mbit=false;
					}
				}
				if (!pcoll.Contains("ADsPath")) {
					pcoll["ADsPath"].Add(de.Path);
				}
//				_SrchColl.Add(new SearchResult(de,PropertiesToLoad));
				_SrchColl.Add(new SearchResult(de,pcoll));
			}
			return;
		}
예제 #3
0
        private void DoSearch()
        {
            InitBlock();
            String[] attrs = new String[PropertiesToLoad.Count];
            PropertiesToLoad.CopyTo(attrs, 0);

            LdapSearchConstraints cons = _conn.SearchConstraints;

            if (SizeLimit > 0)
            {
                cons.MaxResults = SizeLimit;
            }
            if (ServerTimeLimit != DefaultTimeSpan)
            {
                cons.ServerTimeLimit = (int)ServerTimeLimit.TotalSeconds;
            }

            int connScope = LdapConnection.SCOPE_SUB;

            switch (_SearchScope)
            {
            case SearchScope.Base:
                connScope = LdapConnection.SCOPE_BASE;
                break;

            case SearchScope.OneLevel:
                connScope = LdapConnection.SCOPE_ONE;
                break;

            case SearchScope.Subtree:
                connScope = LdapConnection.SCOPE_SUB;
                break;

            default:
                connScope = LdapConnection.SCOPE_SUB;
                break;
            }
            LdapSearchResults lsc = _conn.Search(SearchRoot.Fdn,
                                                 connScope,
                                                 Filter,
                                                 attrs,
                                                 PropertyNamesOnly, cons);

            while (lsc.hasMore())
            {
                LdapEntry nextEntry = null;
                try
                {
                    nextEntry = lsc.next();
                }
                catch (LdapException e)
                {
                    switch (e.ResultCode)
                    {
                    // in case of this return codes exception should not be thrown
                    case LdapException.SIZE_LIMIT_EXCEEDED:
                    case LdapException.TIME_LIMIT_EXCEEDED:
                    case LdapException.REFERRAL:
                        continue;

                    default:
                        throw e;
                    }
                }
                DirectoryEntry     de    = new DirectoryEntry(_conn);
                PropertyCollection pcoll = new PropertyCollection();
//				de.SetProperties();
                de.Path = DirectoryEntry.GetLdapUrlString(_Host, _Port, nextEntry.DN);
                LdapAttributeSet attributeSet        = nextEntry.getAttributeSet();
                System.Collections.IEnumerator ienum = attributeSet.GetEnumerator();
                if (ienum != null)
                {
                    while (ienum.MoveNext())
                    {
                        LdapAttribute attribute     = (LdapAttribute)ienum.Current;
                        string        attributeName = attribute.Name;
                        pcoll[attributeName].AddRange(attribute.StringValueArray);
//						de.Properties[attributeName].AddRange(attribute.StringValueArray);
//						de.Properties[attributeName].Mbit=false;
                    }
                }
                if (!pcoll.Contains("ADsPath"))
                {
                    pcoll["ADsPath"].Add(de.Path);
                }
//				_SrchColl.Add(new SearchResult(de,PropertiesToLoad));
                _SrchColl.Add(new SearchResult(de, pcoll));
            }
            return;
        }