// Creates a default set of searches and adds them to the selected set private void initializeDefaultProviders() { // Add provider for place search ArcGISLocatorPlaceSearchProvider placeSearch = new ArcGISLocatorPlaceSearchProvider(_map, "http://geocode.arcgis.com/ArcGIS/rest/services/World/GeocodeServer"); Properties.SetDescription(placeSearch, placeSearch.GetDescription()); SelectedSearchProviders.Add(placeSearch); // Add provider for ArcGIS Portal search ArcGISPortalServiceSearchProvider portalSearch = new ArcGISPortalServiceSearchProvider(); Binding b = new Binding("Portal") { Source = MapApplication.Current }; BindingOperations.SetBinding(portalSearch, ArcGISPortalServiceSearchProvider.PortalProperty, b); Properties.SetDescription(portalSearch, portalSearch.GetDescription()); SelectedSearchProviders.Add(portalSearch); // Add provider for web search GoogleServiceSearchProvider webSearch = new GoogleServiceSearchProvider(); Properties.SetDescription(webSearch, webSearch.GetDescription()); SelectedSearchProviders.Add(webSearch); }
// Adds a new instance of the passed-in search provider private void doAddProvider(object parameter) { if (!canAddProvider(parameter)) { throw new Exception(Strings.AddSearchError); } SelectedSearchProviders.Add(instantiateSearchProvider(parameter.GetType())); }
internal void LoadConfiguration(string configData) { // Remove providers individually because Clear does not raise CollectionChanged int count = SelectedSearchProviders.Count; for (int i = 0; i < count; i++) { SelectedSearchProviders.RemoveAt(0); } try { // Deserialize the configuration. The configuration is represented as a list of KeyValuePairs - one // for each search provider. The key is the fully qualified type name of the provider, so that it // can be instantiated from configuration data. The value is a dictionary which stores the name, // description, and serialized configuration of each provider. List <KeyValuePair <string, Dictionary <string, string> > > configuration = configData.DataContractDeserialize <List <KeyValuePair <string, Dictionary <string, string> > > >(); if (configuration != null) { // Loop through the configuration for each provider foreach (KeyValuePair <string, Dictionary <string, string> > configEntry in configuration) { // Instanitate the provider string typeName = configEntry.Key; ISearchProvider provider = instantiateSearchProvider(Type.GetType(typeName)); // Get the stored name and description Dictionary <string, string> configSettings = configEntry.Value; if (provider is DependencyObject) { DependencyObject d = (DependencyObject)provider; // TODO: Store name and description in default tool XML as resource string // names surrounded by a well-known prefix & suffix (e.g. "___"). Check for // prefix & suffix and populate from resource file if found. Otherwise, use // value from config file directly Properties.SetDisplayName(d, configSettings["Name"]); Properties.SetDescription(d, configSettings["Description"]); } // Load the serialized provider's configuration, if it exists if (provider is ISupportsConfiguration) { ((ISupportsConfiguration)provider).LoadConfiguration(configSettings["Configuration"]); } if (provider is ArcGISPortalServiceSearchProvider) { var portalSearch = (ArcGISPortalServiceSearchProvider)provider; Binding b = new Binding("Portal") { Source = MapApplication.Current }; BindingOperations.SetBinding(portalSearch, ArcGISPortalServiceSearchProvider.PortalProperty, b); } SelectedSearchProviders.Add(provider); } } else { initializeDefaultProviders(); } } catch { initializeDefaultProviders(); } }