Novell.Directory.Ldap.LdapSearchResults.next C# (CSharp) Method

next() public method

Returns the next result as an LdapEntry. If automatic referral following is disabled or if a referral was not followed, next() will throw an LdapReferralException when the referral is received.
LdapException A general exception which includes an error /// message and an Ldap error code. /// LdapReferralException A referral was received and not /// followed. ///
public next ( ) : LdapEntry
return LdapEntry
        public virtual LdapEntry next()
        {
            if (completed && (entryIndex >= entryCount) && (referenceIndex >= referenceCount))
            {
                throw new System.ArgumentOutOfRangeException("LdapSearchResults.next() no more results");
            }
            // Check if the enumeration is empty and must be reloaded
            resetVectors();

            System.Object element = null;
            // Check for Search References & deliver to app as they come in
            // We only get here if not following referrals/references
            if (referenceIndex < referenceCount)
            {
                System.String[] refs = (System.String[]) (references[referenceIndex++]);
                LdapReferralException rex = new LdapReferralException(ExceptionMessages.REFERENCE_NOFOLLOW);
                rex.setReferrals(refs);
                throw rex;
            }
            else if (entryIndex < entryCount)
            {
                // Check for Search Entries and the Search Result
                element = entries[entryIndex++];
                if (element is LdapResponse)
                {
                    // Search done w/bad status
                    if (((LdapResponse) element).hasException())
                    {

                        LdapResponse lr = (LdapResponse) element;
                        ReferralInfo ri = lr.ActiveReferral;

                        if (ri != null)
                        {
                            // Error attempting to follow a search continuation reference
                            LdapReferralException rex = new LdapReferralException(ExceptionMessages.REFERENCE_ERROR, lr.Exception);
                            rex.setReferrals(ri.ReferralList);
                            rex.FailedReferral = ri.ReferralUrl.ToString();
                            throw rex;
                        }
                    }
                    // Throw an exception if not success
                    ((LdapResponse) element).chkResultCode();
                }
                else if (element is LdapException)
                {
                    throw (LdapException) element;
                }
            }
            else
            {
                // If not a Search Entry, Search Result, or search continuation
                // we are very confused.
                // LdapSearchResults.next(): No entry found & request is not complete
                throw new LdapException(ExceptionMessages.REFERRAL_LOCAL, new System.Object[]{"next"}, LdapException.LOCAL_ERROR, (System.String) null);
            }
            return (LdapEntry) element;
        }

Usage Example

Example #1
0
        private static LdapEntry[] toArray(LdapSearchResults results)
        {
            ArrayList entries;

            entries = new ArrayList();

            while(results.hasMore())
                entries.Add(results.next());

            return((LdapEntry[]) entries.ToArray(typeof(LdapEntry)));
        }