// Raised when the asynchronous call to search the ArcGIS Portal has completed. private void SearchItemsCompleted(SearchResultInfo <ArcGISPortalItem> result, Exception ex) { if (ex != null) // Error occurred { IsSearching = false; // Reset busy state OnSearchFailed(ex); // Fire failed event return; } if (_cancelled) // search was cancelled { _cancelled = false; return; } if (!_pageChangeSearch) // Result of a new search { // Add and initialize results foreach (ArcGISPortalItem item in result.Results) { SearchResultViewModel viewModel = new SearchResultViewModel(item) { ProxyUrl = this.UseProxy ? this.ProxyUrl : null }; _results.Add(viewModel); viewModel.Initialize(); } // Add empty results for each of the pages not yet returned for (int i = 0; i < result.TotalCount - _pageSize; i++) { SearchResultViewModel viewModel = new SearchResultViewModel() { ProxyUrl = this.UseProxy ? this.ProxyUrl : null }; _results.Add(viewModel); } OnSearchCompleted(); // Fire completed event } else // Result of a search initiated by a page change { // index in the entire collection of the first result on the current page int i = _searchStartIndex - 1; foreach (ArcGISPortalItem item in result.Results) { // Update the empty result corresponding to the return portal item SearchResultViewModel viewModel = _results[i]; viewModel.Result = item; viewModel.Initialize(); i++; } // Execute the requested page change PagedResults.MoveToPage(_pagesRetrieved[_pagesRetrieved.Count - 1]); // Reset flag _pageChangeSearch = false; } IsSearching = false; // Reset busy state }
// Raised when the asynchronous call to search the ArcGIS Portal has completed. private void SearchItemsCompleted(SearchResultInfo<ArcGISPortalItem> result, Exception ex) { if (ex != null) // Error occurred { IsSearching = false; // Reset busy state OnSearchFailed(ex); // Fire failed event return; } if (_cancelled) // search was cancelled { _cancelled = false; return; } if (!_pageChangeSearch) // Result of a new search { // Add and initialize results foreach (ArcGISPortalItem item in result.Results) { SearchResultViewModel viewModel = new SearchResultViewModel(item) { ProxyUrl = this.UseProxy ? this.ProxyUrl : null }; _results.Add(viewModel); viewModel.Initialize(); } // Add empty results for each of the pages not yet returned for (int i = 0; i < result.TotalCount - _pageSize; i++) { SearchResultViewModel viewModel = new SearchResultViewModel() { ProxyUrl = this.UseProxy ? this.ProxyUrl : null }; _results.Add(viewModel); } OnSearchCompleted(); // Fire completed event } else // Result of a search initiated by a page change { // index in the entire collection of the first result on the current page int i = _searchStartIndex - 1; foreach (ArcGISPortalItem item in result.Results) { // Update the empty result corresponding to the return portal item SearchResultViewModel viewModel = _results[i]; viewModel.Result = item; viewModel.Initialize(); i++; } // Execute the requested page change PagedResults.MoveToPage(_pagesRetrieved[_pagesRetrieved.Count - 1]); // Reset flag _pageChangeSearch = false; } IsSearching = false; // Reset busy state }
/// <summary> /// Raised when the asynchronous call to check if the map service is accessible has completed. /// </summary> private void CheckServiceAccessCompleted(object sender, ServiceEventArgs e) { if (e.Service == null) return; //the map service is not accessible // Check the current result against the ones already received. Duplicates are often found. bool alreadyAdded = false; foreach (SearchResultViewModel result in _checkedResults) { ArcGISService webSearchRes = (ArcGISService)result.Result; if (webSearchRes.Title.Equals(e.Service.Title) && webSearchRes.Url.Equals(e.Service.Url)) { alreadyAdded = true; //add search results only once break; } } // If it's a new service, initialize the result viewModel and add it to the collection of // results that have had their service access checked if (!alreadyAdded && !_cancelled) { SearchResultViewModel viewModel = new SearchResultViewModel(e.Service) { ProxyUrl = this.UseProxy ? this.ProxyUrl : null }; _checkedResults.Add(viewModel); viewModel.Initialized += resultViewModel_Initialized; viewModel.Initialize(); } }