protected void ProcessSearch(object o) { List <IScrapeResult> result = ((object[])o)[0] as List <IScrapeResult>; SearchCategory searchCategory = ((object[])o)[1] as SearchCategory; SearchCategory searchCategory2 = ((object[])o)[2] as SearchCategory; string text = ((object[])o)[3] as string; AbstractScraper.PageProcessDelegate pageProcessDelegate = ((object[])o)[4] as AbstractScraper.PageProcessDelegate; int num = this.initialPageNum; string empty = string.Empty; while (!this.terminated) { num++; if (this.downloader.DownloadUrl(this.GetUrl(searchCategory, searchCategory2, text, num), out empty) && this.terminated) { return; } if (!pageProcessDelegate(empty, result, searchCategory, searchCategory2)) { return; } } }
public virtual void Search() { if (this.Callback != null) { this.Callback.Init(this.Locations.Count * this.Categories.Count); } this.terminated = false; string text = UrlDownloader.UrlEncode(this.Keyword); if (this.Categories.Count <= 0) { if (!this.allowsCategorylessSearch) { if (this.downloader != null && this.downloader.errorCallback != null) { this.downloader.errorCallback.Log("No categories selected."); } return; } if (string.IsNullOrEmpty(text)) { if (this.downloader != null && this.downloader.errorCallback != null) { this.downloader.errorCallback.Log("No keyword and categories selected."); } return; } } if (this.Locations.Count <= 0) { if (this.downloader != null && this.downloader.errorCallback != null) { this.downloader.errorCallback.Log("No locations selected."); } return; } AbstractScraper.PageProcessDelegate pageProcessDelegate = string.IsNullOrEmpty(text) ? new AbstractScraper.PageProcessDelegate(this.ProcessSimpleRequest) : new AbstractScraper.PageProcessDelegate(this.ProcessKeywordRequest); Queue <KeyValuePair <Thread, object> > queue = new Queue <KeyValuePair <Thread, object> >(); if (this.Categories.Count > 0) { using (List <SearchCategory> .Enumerator enumerator = this.Locations.GetEnumerator()) { while (enumerator.MoveNext()) { SearchCategory current = enumerator.Current; foreach (SearchCategory current2 in this.Categories) { object[] value = new object[] { this.campaign.Leads, current, current2, text, pageProcessDelegate }; queue.Enqueue(new KeyValuePair <Thread, object>(new Thread(new ParameterizedThreadStart(this.ProcessSearch)) { Name = string.Format("{0}|{1}", current.Name, current2.Name) }, value)); } } goto IL_2C0; } } foreach (SearchCategory current3 in this.Locations) { SearchCategory searchCategory = new SearchCategory(); searchCategory.Name = text; searchCategory.Url = text; object[] value2 = new object[] { this.campaign.Leads, current3, searchCategory, null, pageProcessDelegate }; queue.Enqueue(new KeyValuePair <Thread, object>(new Thread(new ParameterizedThreadStart(this.ProcessSearch)) { Name = string.Format("{0}|{1}", current3.Name, searchCategory.Name) }, value2)); } IL_2C0: List <Thread> list = new List <Thread>(this.maxThreadCount); Thread.CurrentThread.Priority = ThreadPriority.Lowest; int i = 0; while (queue.Count > 0 || list.Count > 0) { if (this.terminated) { break; } while (list.Count < this.maxThreadCount && queue.Count > 0) { KeyValuePair <Thread, object> keyValuePair = queue.Dequeue(); list.Add(keyValuePair.Key); keyValuePair.Key.Start(keyValuePair.Value); } if (this.terminated) { break; } i = 0; while (i < list.Count) { if (list[i].ThreadState == ThreadState.Stopped) { list.RemoveAt(i); if (this.Callback != null) { this.Callback.ShowProgress(); } } else { i++; } } } if (this.Callback != null) { this.Callback.Finish(); } if (this.downloader != null && this.downloader.errorCallback != null) { if (this.terminated) { this.downloader.errorCallback.Log("Search has been stopped."); return; } this.downloader.errorCallback.Log("Search finished."); } }