Esempio n. 1
0
        public void AsyncQuery(string dc,
                               string searchBase,
                               string ldapFilter,
                               string[] propertiesToLoad,
                               SearchScope scope,
                               ReferralChasingOptions referralChasing,
                               QueryControl queryInfo,
                               bool performASQ = false)
        {
            CancelToken = false;

            GlobalEventHandler.ClearSearchCancelled();

            GlobalEventHandler.SearchCancelled += ReceivedCancellation;

            byte[] pagingCookie = null;

            ForestBase.CurrentPorts.SelectedPort = queryInfo.Port;

            Connect(dc, referralChasing, true, connectionLess: (searchBase.Length == 0));

            if (propertiesToLoad.Length == 0)
            {
                propertiesToLoad = null;
            }

            else if ((propertiesToLoad.Length == 1) && (propertiesToLoad[0] == "*"))
            {
                propertiesToLoad = null;
            }

            ForestBase.CurrentRequestExtender = new SearchRequestExtender(searchBase,
                                                                          ldapFilter,
                                                                          propertiesToLoad,
                                                                          scope,
                                                                          pagingCookie,
                                                                          queryInfo);


            base.AsyncComplete = false;
            base.AsyncCalls    = 0;

            GlobalEventHandler.AsyncQureyIsCompleted += AsyncSearchComplete;

            PagedAsyncQuery();
        }
Esempio n. 2
0
        public List <SearchResultEntry> Query(string dc,
                                              string searchBase,
                                              string ldapFilter,
                                              string[] propertiesToLoad,
                                              SearchScope scope,
                                              ReferralChasingOptions referralChasing,
                                              QueryControl queryInfo,
                                              string[] attributesRemebered = null,
                                              bool returnResults           = false)
        {
            CancelToken = false;

            GlobalEventHandler.ClearSearchCancelled();

            GlobalEventHandler.SearchCancelled += ReceivedCancellation;

            List <SearchResultEntry> ret = new List <SearchResultEntry> {
            };

            List <SearchResultEntry> fire = new List <SearchResultEntry> {
            };

            QueryHasConstructedAttribute(propertiesToLoad, scope, ref queryInfo);

            if (queryInfo.MustGetSingleObjectPath)
            {
                GetSingleObjectPaths(dc,
                                     searchBase,
                                     ldapFilter,
                                     propertiesToLoad,
                                     scope,
                                     referralChasing,
                                     queryInfo);
                return(ret);
            }

            ForestBase.CurrentPorts.SelectedPort = queryInfo.Port;

            byte[] pagingCookie = null;

            SearchRequestExtender reqstore = new SearchRequestExtender(searchBase,
                                                                       ldapFilter,
                                                                       propertiesToLoad,
                                                                       scope,
                                                                       pagingCookie,
                                                                       queryInfo);

            reqstore.DC = dc;

            reqstore.ReferralChasing = referralChasing;

            propertiesToLoad = reqstore.Attributes;

            while (true)
            {
                if (!reqstore.HasError)
                {
                    reqstore.PageCount++;
                }

                SearchResultEntryCollection colresult = null;

                if (!CancelToken)
                {
                    if (!queryInfo.PerformDirSync)
                    {
                        DateTime starttime = DateTime.Now;

                        colresult = PagedQuery(ref reqstore);

                        if (reqstore.CurrentPageSize > 0)
                        {
                            GlobalEventHandler.RaiseMessageOccured(String.Format("Page: {0} ({1}) [{2}] ms]", reqstore.PageCount, reqstore.CurrentPageSize, DateTime.Now.Subtract(starttime).TotalMilliseconds));
                        }
                    }

                    else
                    {
                        colresult = DirSyncQuery(ref reqstore);
                    }
                }

                else
                {
                    break;
                }

                if (reqstore.HasError)
                {
                    break;
                }

                if ((colresult != null) && (colresult.Count > 0) && ((colresult[0].DistinguishedName.Length != 0) || (searchBase == "")))
                {
                    SearchResultEntry[] temp = new SearchResultEntry[colresult.Count];

                    colresult.CopyTo(temp, 0);

                    fire = temp.ToList();

                    if (returnResults)
                    {
                        ret.AddRange(fire);
                    }
                }

                if ((queryInfo.CurrentResultEventType == QUERY_RESULT_EVENT_TYPE.FROM_SINGLE_OBJECT_PATH) && (attributesRemebered != null))
                {
                    reqstore.HandleAttributes(attributesRemebered);
                }

                if (reqstore.MoreData)
                {
                    if ((fire.Count > 0) && !returnResults)
                    {
                        GlobalEventHandler.RaiseQueryCompleted(fire, reqstore, QUERY_RESULT_EVENT_TYPE.IS_PARTIAL | queryInfo.CurrentResultEventType);
                    }

                    if ((queryInfo.CurrentResultEventType == QUERY_RESULT_EVENT_TYPE.FROM_SINGLE_OBJECT_PATH) && (attributesRemebered != null))
                    {
                        reqstore.HandleAttributes(propertiesToLoad);
                    }
                }

                else
                {
                    break;
                }
            }

            if (reqstore.DoPaging)
            {
                reqstore.AddMessage(String.Format("PageSize: {0}", reqstore.CurrentPageSize));
                reqstore.AddMessage(String.Format("Pages: {0}", reqstore.PageCount));
            }

            if (!returnResults)
            {
                GlobalEventHandler.RaiseQueryCompleted(fire, reqstore, QUERY_RESULT_EVENT_TYPE.IS_COMPLETED | queryInfo.CurrentResultEventType);
            }

            Disconnect();

            return(ret);
        }