void proxy_getRecords_QuickSearchBySBACompleted(object sender, getRecords_QuickSearchBySBACompletedEventArgs e) { if (e.Error != null) { //records = null; cannotStartSearchYet = false; } else { CSWGetRecordsSearchResults results = e.Result; iterateGetAllRecords(results); } }
//Iterate to get all the records(each step only get certain number of records) public void proxy_GetRecords_BasicSearchCompleted(object sender, getRecords_BasicSearchCompletedEventArgs e) { if (e.Error != null) { cannotStartSearchYet = false; } else { SearchingResultPage.setSearchButtonEnabled(); CSWGetRecordsSearchResults results = e.Result; iterateGetAllRecords(results); } }
private void iterateGetAllRecords(CSWGetRecordsSearchResults results) { if (results == null) { return; } // if current searched records num equal or larger than expect, then stop current search and do not add records into result list any more. if (currentGotRecordsNumber >= maxRecordsExpectToGet) { return; } TimeSpan tspan = DateTime.Now.Subtract(time_BeforeSearch); double time1 = tspan.TotalMilliseconds; double responseTime = time1 / 1000; allSearchTimeFromFirstRequest.Add(responseTime); int numberOfRecordsMatchedInCurrentCatalog = results.numberOfRecordsMatched; string catalogURL = results.MetadataRepositoryURL; CatalogsSearchStatus currentCatalogStatus = null; foreach (CatalogsSearchStatus catalogsSearchStatus in catalogsSearchStatusList) { if (catalogsSearchStatus.CatalogURL.Equals(catalogURL)) { currentCatalogStatus = catalogsSearchStatus; } } if (!currentCatalogStatus.hasGotTotalMatchedNumber) { allMatchedRecordsNumberInSearchedCatalogs += results.numberOfRecordsMatched; currentCatalogStatus.matchedNumber = results.numberOfRecordsMatched; currentCatalogStatus.hasGotTotalMatchedNumber = true; } ObservableCollection <Record> records = null; records = results.recordList; bool continueSearching = false; string seachingStatus = ConstantCollection.searchStatus_InProcessing; //foreach (Record record in records) //{ // StringList a = new StringList(); // a.AddRange(record.SBAs); // record.SBAListObject = a; //} if (ConstantCollection.isQueryServicePerformanceScore && (!ConstantCollection.queryServicePerformanceScoreAtServerSide)) { if (records != null && records.Count > 0) { queryPerformanceFunctions.getGeospatialServiceQoSSummaryInfo(records); } } if (ConstantCollection.isQueryServerLocationLonLat && (!ConstantCollection.queryServerLocationLonLatAtServerSide)) { if (records != null && records.Count > 0) { ObservableCollection <string> URLList = new ObservableCollection <string>(); foreach (Record record in records) { //currently, we only query the server information of OGC web services if (record.Type.Equals(ConstantCollection.ServiceType_CSW) || record.Type.Equals(ConstantCollection.ServiceType_WMS) || record.Type.Equals(ConstantCollection.ServiceType_WCS) || record.Type.Equals(ConstantCollection.ServiceType_WPS) || record.Type.Equals(ConstantCollection.ServiceType_WFS)) { if (record.URLLocation == null || record.URLLocation.Trim().Equals("")) { URLList.Add(record.AccessURL); } } } if (URLList.Count > 0) { otherQueryFuntions.getServerInformationFromURLS(URLList, ID); } } } int local_potentialNumber = currentGotRecordsNumber + results.numberOfRecordsReturned; int potentialNumber = local_potentialNumber; foreach (CatalogsSearchStatus catalogsSearchStatus in catalogsSearchStatusList) { if (catalogsSearchStatus.isTerminated == false && catalogsSearchStatus.potentioalRetrieveNumber > 0) { potentialNumber += catalogsSearchStatus.potentioalRetrieveNumber; } } int nextRecordInCurrentCatalog = results.nextRecord; if (nextRecordInCurrentCatalog == 0 || nextRecordInCurrentCatalog > numberOfRecordsMatchedInCurrentCatalog) { nextRecordInCurrentCatalog = numberOfRecordsMatchedInCurrentCatalog; } currentCatalogStatus.nextRecord = nextRecordInCurrentCatalog; //if potentialNumber less than maxRecordsWantToResult, and nextRecordInCurrentCatalog less then numberOfRecordsMatchedInCurrentCatalog, then continue search if (potentialNumber < maxRecordsExpectToGet && nextRecordInCurrentCatalog < numberOfRecordsMatchedInCurrentCatalog) { continueSearching = true; seachingStatus = ConstantCollection.searchStatus_InProcessing; //User can start a new search now, no needs to want all the records of current are queried. cannotStartSearchYet = false; } else { cannotStartSearchYet = false; continueSearching = false; //if local potentialNumber greater than maxRecordsWantToResult, then change status if (local_potentialNumber >= maxRecordsExpectToGet) { seachingStatus = ConstantCollection.searchStatus_Finished; isAllSearchTerminated = true; } else if (nextRecordInCurrentCatalog >= numberOfRecordsMatchedInCurrentCatalog) { currentCatalogStatus.isTerminated = true; bool allFinished = true; foreach (CatalogsSearchStatus catalogsSearchStatus in catalogsSearchStatusList) { if (catalogsSearchStatus.isTerminated == false) { allFinished = false; } } if (allFinished) { seachingStatus = ConstantCollection.searchStatus_Finished; isAllSearchTerminated = true; } else { seachingStatus = ConstantCollection.searchStatus_InProcessing; } } } //if zero record is responsed and the search status is abnormal, then set the search status to show the problems. if (results.numberOfRecordsMatched == 0 && results.numberOfRecordsReturned == 0 && results.SearchStatus != null) { seachingStatus = results.SearchStatus; //if response error also means this catalog's search is over currentCatalogStatus.isTerminated = true; currentCatalogStatus.isFailed = true; bool allFinished = true; bool allFailed = true; foreach (CatalogsSearchStatus catalogsSearchStatus in catalogsSearchStatusList) { if (catalogsSearchStatus.isTerminated == false) { allFinished = false; } if (catalogsSearchStatus.isFailed == false) { allFailed = false; } } if (allFinished) { isAllSearchTerminated = true; if (!allFailed) { seachingStatus = ConstantCollection.searchStatus_Finished; } } } //if currentSearchedNum less than maxRecordsWantToResult and numOfRecords, continue search if (continueSearching) { int requestRecordsNumber = ConstantCollection.eachInvokeSearchNum_ExceptFirstTime; if (potentialNumber < maxRecordsExpectToGet) { //if (maxRecordsExpectToGet - potentialNumber) < retrieve interval, set retrieve interval to that value int num = maxRecordsExpectToGet - potentialNumber; if (num < requestRecordsNumber) { requestRecordsNumber = num; } } //if number of rest matched records is less then retrieve interval, just set current retrieve interval to the rest number int num1 = currentCatalogStatus.matchedNumber - results.nextRecord + 1; if (num1 > 0 && num1 < requestRecordsNumber) { requestRecordsNumber = num1; } int nextRecord = results.nextRecord; if (searchingContentObject != null) { cswQueryServiceClient.getRecords_AdvancedSearchAsync(searchingContentObject, nextRecord + "", requestRecordsNumber + "", catalogURL, ConstantCollection.queryServicePerformanceScoreAtServerSide && ConstantCollection.isQueryServicePerformanceScore, ConstantCollection.calculateRelevanceAtServerSide && ConstantCollection.isCalculateRelevance); } else if (vocabularyObject != null) { cswQueryServiceClient.getRecords_QuickSearchBySBAAsync(vocabularyObject, nextRecord + "", requestRecordsNumber + "", catalogURL, ConstantCollection.queryServicePerformanceScoreAtServerSide && ConstantCollection.isQueryServicePerformanceScore, ConstantCollection.calculateRelevanceAtServerSide && ConstantCollection.isCalculateRelevance); } else { cswQueryServiceClient.getRecords_BasicSearchAsync(contentToSearching, nextRecord + "", requestRecordsNumber + "", catalogURL, ConstantCollection.queryServicePerformanceScoreAtServerSide && ConstantCollection.isQueryServicePerformanceScore, ConstantCollection.calculateRelevanceAtServerSide && ConstantCollection.isCalculateRelevance); } currentCatalogStatus.potentioalRetrieveNumber = requestRecordsNumber; } SearchingResultPage currentResultPage = null; if (isFirstInvokeToSearch) { currentGotRecordsNumber = results.numberOfRecordsReturned; SearchingResultPage.showSearchingResultPage(contentToSearching, currentGotRecordsNumber, allMatchedRecordsNumberInSearchedCatalogs, responseTime, seachingStatus, records, sortingRule, isResult_CategorizedInTabItems); isFirstInvokeToSearch = false; } else { App app = (App)Application.Current; UIElement uiElement = app.RootVisual; if (uiElement is UserControl) { UserControl control = uiElement as UserControl; UIElement root = control.Content; if (root is SearchingResultPage) { currentResultPage = root as SearchingResultPage; //if user trigger new search during current search stage, current search results will be ignored and this iterative search will be ended. //if not, these search results will be add to current result page if (SearchingResultPage.ID == ID) { int newAddNum = results.numberOfRecordsReturned; bool willOverflow = false; if (currentGotRecordsNumber + newAddNum > maxRecordsExpectToGet) { newAddNum = maxRecordsExpectToGet - currentGotRecordsNumber; willOverflow = true; } int numAfterAddOperation = newAddNum + currentGotRecordsNumber; currentResultPage.setSearchStutusBarInformation(numAfterAddOperation, allMatchedRecordsNumberInSearchedCatalogs, responseTime, seachingStatus); if (!willOverflow) { if (currentResultPage.noRecord == true) { currentResultPage.setResultPageContents(contentToSearching, numAfterAddOperation, allMatchedRecordsNumberInSearchedCatalogs, responseTime, seachingStatus, records, sortingRule); } else { if (records != null) { foreach (Record record in records) { ClientSideRecord newRecord = ClientSideRecord.cloneRecord(record); currentResultPage.insertRecordsIntoResultPage(newRecord, sortingRule); } } currentResultPage.setRecordCountTextBlockValue(); } } else { int i = 0; foreach (Record record in records) { if (i++ < newAddNum) { ClientSideRecord newRecord = ClientSideRecord.cloneRecord(record); currentResultPage.insertRecordsIntoResultPage(newRecord, sortingRule); } } currentResultPage.setRecordCountTextBlockValue(); } currentGotRecordsNumber = numAfterAddOperation; } else { return; } } } currentCatalogStatus.potentioalRetrieveNumber = 0; } if (isAllSearchTerminated) { if (currentResultPage != null) { currentResultPage.SearchSummaryViewer.Visibility = Visibility.Visible; } } }