Exemple #1
0
        // 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
        }