/// <summary> /// /// </summary> /// <param name="htmlDocument"></param> /// <param name="searchItem"></param> /// <returns></returns> public override Models.SearchItem AnalyzeSearchCallback(string htmlDocument, Models.SearchItem searchItem) { Models.SearchItem _searchItem = null; Task <Models.SearchItem> resultTask = Task.Factory.StartNew(() => StartAnalyzeSearchCallback(htmlDocument, searchItem)); _searchItem = resultTask.Result; return(_searchItem); }
/// <summary> /// /// </summary> /// <param name="htmlDocument"></param> public void AnalyzeSearch(string htmlDocument) { this.ForceStopSearchAnalysis = false; this._IsBusy = true; Stopwatch _stopWatch = new Stopwatch(); _stopWatch.Reset(); _stopWatch.Start(); Models.SearchItem _searchItem = this.AnalyzeSearchCallback(htmlDocument, this.SearchItem); _stopWatch.Stop(); this.SearchItem = _searchItem; _DirectoryProviderRoutineStage = DirectoryProviderRoutineStageEnum.SearchAnalysisFinished; this._IsBusy = false; InvokeEventSearchAnalysisFinished(new Handlers.EventHandlers.SearchAnalysisFinishedEventArgs(_searchItem, _stopWatch.Elapsed)); }
/// <summary> /// /// </summary> /// <param name="searchItem"></param> private Models.SearchItem StartAnalyzeSearchCallback(string htmlDocument, Models.SearchItem searchItem) { Models.SearchItem _searchItem = (Models.SearchItem)searchItem; if (_searchItem.searchResult == null) { _searchItem.searchResult = new Models.SearchItem.SearchResult(); } string _errMsg = string.Empty; _searchItem.searchResult.PageOnError = this.ypTool.CheckPageIfError(htmlDocument, ref _errMsg); if (base.ForceStopSearchAnalysis) { return(null); } if (_searchItem.searchResult.PageOnError) { _searchItem.searchResult.PageErrorMessage = _errMsg; } else { _searchItem.searchResult.ResultsPerPage = this.ypTool.GetResultsPerPage(htmlDocument); _searchItem.searchResult.TotalResults = this.ypTool.GetTotalResults(htmlDocument); int _totPgs = (int)(_searchItem.searchResult.TotalResults % _searchItem.searchResult.ResultsPerPage); _searchItem.searchResult.TotalPages = (int)(_searchItem.searchResult.TotalResults / _searchItem.searchResult.ResultsPerPage) + (_totPgs > 0 ? 1 : 0); if (_searchItem.searchResult.pointers == null) { _searchItem.searchResult.pointers = new List <Models.SearchItem.SearchResult.UrlPointer>(); } for (int _ctr = 0; _ctr < _searchItem.searchResult.TotalPages; _ctr++) { if (base.ForceStopSearchAnalysis) { return(null); } string _searchUrl = Models.DirectoryProviderSetting.BuildSearchUrl(base.DirectoryProviderSetting , _searchItem.searchItem , _searchItem.searchLocation , _ctr + 1);; Models.SearchItem.SearchResult.UrlPointer _ptrItem = new Models.SearchItem.SearchResult.UrlPointer() { PageNo = _ctr + 1, SearchUrl = new Uri(_searchUrl), SearchHtml = (_ctr == 0 ? htmlDocument : string.Empty), IsValid = false, /* is to be decided T/F when processing */ }; _searchItem.searchResult.pointers.Add(_ptrItem); if (base.ForceStopSearchAnalysis) { return(null); } } } return(_searchItem); }
/// <summary> /// Important: Must not execute base class method because /// value should be returned by the implementing class /// </summary> /// <param name="htmlDocument"></param> /// <returns></returns> public virtual Models.SearchItem AnalyzeSearchCallback(string htmlDocument, Models.SearchItem searchItem) { throw new Exception("Must not execute base class method."); }