예제 #1
0
        internal unsafe DirectoryVirtualListView RetrieveVLVResponse()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            // get the vlv response back
            AdsSearchColumn  column  = new AdsSearchColumn();
            AdsSearchColumn *pColumn = &column;

            SearchObject.GetColumn(Handle, _adsVLVResponseName, (INTPTR_INTPTRCAST)pColumn);
            try
            {
                AdsValue *pValue = column.pADsValues;
                DirectoryVirtualListView value = (DirectoryVirtualListView) new AdsValueHelper(*pValue).GetVlvValue();
                return(value);
            }
            finally
            {
                try
                {
                    SearchObject.FreeColumn((INTPTR_INTPTRCAST)pColumn);
                }
                catch (COMException)
                {
                }
            }
        }
        public SearchResult FindOne()
        {
            SearchResult           result  = null;
            SearchResultCollection results = this.FindAll(false);

            try
            {
                foreach (SearchResult result2 in results)
                {
                    if (this.directorySynchronizationSpecified)
                    {
                        System.DirectoryServices.DirectorySynchronization directorySynchronization = this.DirectorySynchronization;
                    }
                    if (this.directoryVirtualListViewSpecified)
                    {
                        DirectoryVirtualListView virtualListView = this.VirtualListView;
                    }
                    return(result2);
                }
                return(result);
            }
            finally
            {
                this.searchResult = null;
                results.Dispose();
            }
            return(result);
        }
예제 #3
0
            /// <include file='doc\SearchResultCollection.uex' path='docs/doc[@for="SearchResultCollection.ResultsEnumerator.MoveNext"]/*' />
            /// <devdoc>
            ///    <para>Advances
            ///       the enumerator to the next element of the collection
            ///       and returns a Boolean value indicating whether a valid element is available.</para>
            /// </devdoc>
            public bool MoveNext()
            {
                DirectorySynchronization tempsync = null;
                DirectoryVirtualListView tempvlv  = null;
                int errorCode = 0;

                if (_eof)
                {
                    return(false);
                }

                _currentResult = null;
                if (!_initialized)
                {
                    int hr = _results.SearchObject.GetFirstRow(_results.Handle);

                    if (hr != UnsafeNativeMethods.S_ADS_NOMORE_ROWS)
                    {
                        //throw a clearer exception if the filter was invalid
                        if (hr == UnsafeNativeMethods.INVALID_FILTER)
                        {
                            throw new ArgumentException(Res.GetString(Res.DSInvalidSearchFilter, _results.Filter));
                        }
                        if (hr != 0)
                        {
                            throw COMExceptionHelper.CreateFormattedComException(hr);
                        }

                        _eof         = false;
                        _initialized = true;
                        return(true);
                    }

                    _initialized = true;
                }

                while (true)
                {
                    // clear the last error first
                    CleanLastError();
                    errorCode = 0;

                    int hr = _results.SearchObject.GetNextRow(_results.Handle);
                    //  SIZE_LIMIT_EXCEEDED occurs when we supply too generic filter or small SizeLimit value.
                    if (hr == UnsafeNativeMethods.S_ADS_NOMORE_ROWS || hr == UnsafeNativeMethods.SIZE_LIMIT_EXCEEDED)
                    {
                        // need to make sure this is not the case that server actually still has record not returned yet
                        if (hr == UnsafeNativeMethods.S_ADS_NOMORE_ROWS)
                        {
                            hr = GetLastError(ref errorCode);
                            // get last error call failed, we need to bail out
                            if (hr != 0)
                            {
                                throw COMExceptionHelper.CreateFormattedComException(hr);
                            }
                        }

                        // not the case that server still has result, we are done here
                        if (errorCode != SafeNativeMethods.ERROR_MORE_DATA)
                        {
                            // get the dirsync cookie as we finished all the rows
                            if (_results.srch.directorySynchronizationSpecified)
                            {
                                tempsync = _results.srch.DirectorySynchronization;
                            }

                            // get the vlv response as we finished all the rows
                            if (_results.srch.directoryVirtualListViewSpecified)
                            {
                                tempvlv = _results.srch.VirtualListView;
                            }

                            _results.srch.searchResult = null;

                            _eof         = true;
                            _initialized = false;
                            return(false);
                        }
                        else
                        {
                            // if user chooses to wait to continue the search
                            if (_waitForResult)
                            {
                                continue;
                            }
                            else
                            {
                                uint temp = (uint)errorCode;
                                temp = ((((temp) & 0x0000FFFF) | (7 << 16) | 0x80000000));
                                throw COMExceptionHelper.CreateFormattedComException((int)temp);
                            }
                        }
                    }
                    //throw a clearer exception if the filter was invalid
                    if (hr == UnsafeNativeMethods.INVALID_FILTER)
                    {
                        throw new ArgumentException(Res.GetString(Res.DSInvalidSearchFilter, _results.Filter));
                    }
                    if (hr != 0)
                    {
                        throw COMExceptionHelper.CreateFormattedComException(hr);
                    }

                    _eof = false;
                    return(true);
                }
            }
 public object GetVlvValue()
 {
     AdsVLV structure = new AdsVLV();
     Marshal.PtrToStructure(this.adsvalue.octetString.value, structure);
     byte[] destination = null;
     if ((structure.contextID != IntPtr.Zero) && (structure.contextIDlength != 0))
     {
         destination = new byte[structure.contextIDlength];
         Marshal.Copy(structure.contextID, destination, 0, structure.contextIDlength);
     }
     DirectoryVirtualListView view = new DirectoryVirtualListView {
         Offset = structure.offset,
         ApproximateTotal = structure.contentCount
     };
     DirectoryVirtualListViewContext context = new DirectoryVirtualListViewContext(destination);
     view.DirectoryVirtualListViewContext = context;
     return view;
 }
예제 #5
0
            public bool MoveNext()
            {
                int errorCode = 0;

                if (this.eof)
                {
                    return(false);
                }
                this.currentResult = null;
                if (!this.initialized)
                {
                    int firstRow = this.results.SearchObject.GetFirstRow(this.results.Handle);
                    switch (firstRow)
                    {
                    case 0x5012:
                        this.initialized = true;
                        break;

                    case -2147016642:
                        throw new ArgumentException(Res.GetString("DSInvalidSearchFilter", new object[] { this.results.Filter }));

                    default:
                        if (firstRow != 0)
                        {
                            throw COMExceptionHelper.CreateFormattedComException(firstRow);
                        }
                        this.eof         = false;
                        this.initialized = true;
                        return(true);
                    }
                }
Label_0091:
                this.CleanLastError();
                errorCode = 0;
                int nextRow = this.results.SearchObject.GetNextRow(this.results.Handle);

                switch (nextRow)
                {
                case 0x5012:
                case -2147016669:
                    if (nextRow == 0x5012)
                    {
                        nextRow = this.GetLastError(ref errorCode);
                        if (nextRow != 0)
                        {
                            throw COMExceptionHelper.CreateFormattedComException(nextRow);
                        }
                    }
                    if (errorCode != 0xea)
                    {
                        if (this.results.srch.directorySynchronizationSpecified)
                        {
                            DirectorySynchronization directorySynchronization = this.results.srch.DirectorySynchronization;
                        }
                        if (this.results.srch.directoryVirtualListViewSpecified)
                        {
                            DirectoryVirtualListView virtualListView = this.results.srch.VirtualListView;
                        }
                        this.results.srch.searchResult = null;
                        this.eof         = true;
                        this.initialized = false;
                        return(false);
                    }
                    if (!this.waitForResult)
                    {
                        uint num4 = (uint)errorCode;
                        num4 = ((num4 & 0xffff) | 0x70000) | 0x80000000;
                        throw COMExceptionHelper.CreateFormattedComException((int)num4);
                    }
                    goto Label_0091;

                case -2147016642:
                    throw new ArgumentException(Res.GetString("DSInvalidSearchFilter", new object[] { this.results.Filter }));
                }
                if (nextRow != 0)
                {
                    throw COMExceptionHelper.CreateFormattedComException(nextRow);
                }
                this.eof = false;
                return(true);
            }