Пример #1
0
        /// <summary>
        /// Creates a new instance of the <see cref="WorldGeocoder"/> class for the specified
        /// service configuration.
        /// </summary>
        /// <param name="serviceInfo">The instance of the geocoding service configuration
        /// specifying World geocoder service to create geocoder for.</param>
        /// <param name="exceptionHandler">Exception handler.</param>
        /// <returns>A new instance of the <see cref="WorldGeocoder"/> class.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="serviceInfo"/> is a null
        /// reference.</exception>
        public static GeocoderBase CreateWorldGeocoder(GeocodingServiceInfo serviceInfo,
                                                       IServiceExceptionHandler exceptionHandler)
        {
            CodeContract.RequiresNotNull("serviceInfo", serviceInfo);

            // Create binding for the geocoder REST service.
            var webBinding             = ServiceHelper.CreateWebHttpBinding("WorldGeocoder");
            var binding                = new CustomBinding(webBinding);
            var messageEncodingElement = binding.Elements.Find <WebMessageEncodingBindingElement>();

            messageEncodingElement.ContentTypeMapper = new ArcGisWebContentTypeMapper();

            // Create endpoint for the geocoder REST service.
            var contract       = ContractDescription.GetContract(typeof(IGeocodingService));
            var serviceAddress = new EndpointAddress(serviceInfo.RestUrl);
            var endpoint       = new WebHttpEndpoint(contract, serviceAddress);

            endpoint.Binding = binding;

            // Replace default endpoint behavior with a customized one.
            endpoint.Behaviors.Remove <WebHttpBehavior>();
            endpoint.Behaviors.Add(new GeocodingServiceWebHttpBehavior());

            // Create the geocoder instance.
            var channelFactory = new WebChannelFactory <IGeocodingService>(endpoint);
            var client         = new GeocodingServiceClient(channelFactory, serviceInfo, exceptionHandler);

            return(new WorldGeocoder(serviceInfo, client));
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="geocodingServiceInfo">Geocoding service info.</param>
        /// <param name="geocodeServer">Geocode server.</param>
        /// <param name="exceptionHandler">Exception handler.</param>
        /// <exception cref="System.ArgumentException">Is thrown in case if geocodingServiceInfo
        /// or geocodeServer parameters is null.</exception>
        internal ArcGiscomGeocoder(GeocodingServiceInfo geocodingServiceInfo,
                                   AgsServer geocodeServer, IServiceExceptionHandler exceptionHandler)
            : base(geocodingServiceInfo, geocodeServer, exceptionHandler)
        {
            if (geocodingServiceInfo == null)
            {
                throw new ArgumentException("geocodingServiceInfo");
            }
            if (geocodeServer == null)
            {
                throw new ArgumentException("geocodeServer");
            }

            var list = new List <string>();

            // Fill collection with names of exact locators types.
            foreach (var locator in geocodingServiceInfo.ExactLocators.Locators)
            {
                list.Add(locator.Type);
            }

            // Local storage is exact locator.
            list.Add(LOCAL_STORAGE_ADDRESS_TYPE);

            ExactLocatorsTypesNames = list;
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WorldGeocoder"/> class.
        /// </summary>
        /// <param name="serviceInfo">The geocoding service configuration information.</param>
        /// <param name="client">The geocoding service client object.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="serviceInfo"/> or
        /// <paramref name="client"/> is a null reference.</exception>
        public WorldGeocoder(
            GeocodingServiceInfo serviceInfo,
            IGeocodingServiceClient client)
        {
            CodeContract.RequiresNotNull("serviceInfo", serviceInfo);
            CodeContract.RequiresNotNull("client", client);

            _serviceInfo = serviceInfo;
            _client      = client;

            _client.ReverseGeocodeCompleted += _ClientReverseGeocodeCompleted;

            _locatorsInfos = new ReadOnlyCollection <LocatorInfo>(new List <LocatorInfo>());
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeocodingServiceClient"/> class.
        /// </summary>
        /// <param name="channelFactory">The reference to the channel factory instance
        /// to be used for creating communication channels for the geocoder service.</param>
        /// <param name="serviceInfo">The configuration information for the geocoder
        /// service.</param>
        /// <param name="exceptionHandler">Exception handler.</param>
        /// <exception cref="ArgumentNullException"><paramref name="channelFactory"/> or
        /// <paramref name="serviceInfo"/> is a null reference.</exception>
        public GeocodingServiceClient(
            ChannelFactory <IGeocodingService> channelFactory,
            GeocodingServiceInfo serviceInfo,
            IServiceExceptionHandler exceptionHandler)
        {
            CodeContract.RequiresNotNull("channelFactory", channelFactory);
            CodeContract.RequiresNotNull("serviceInfo", serviceInfo);
            CodeContract.RequiresNotNull("exceptionHandler", exceptionHandler);

            _serviceClient = new RestServiceClient <IGeocodingService>(
                channelFactory,
                serviceInfo.Title,
                exceptionHandler);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="geocodingServiceInfo">Geocoding info from data layer.</param>
        internal GeocodingInfo(GeocodingServiceInfo geocodingServiceInfo)
        {
            Debug.Assert(geocodingServiceInfo != null);

            // Copy internal locators info.
            if (geocodingServiceInfo.InternalLocators != null)
            {
                _locators = new List <LocatorInfo>();

                foreach (SublocatorInfo sublocator in geocodingServiceInfo.InternalLocators.SublocatorInfo)
                {
                    LocatorInfo LocatorInfo = LocatorInfo.CreateLocatorInfo(sublocator);
                    _locators.Add(LocatorInfo);
                }
            }
        }
Пример #6
0
        private AgsServer _GetCurrentGcServer(GeocodingServiceInfo geocodingServiceInfo)
        {
            AgsServer currentServer = null;

            foreach (AgsServer server in _servers)
            {
                if (server.Name.Equals(geocodingServiceInfo.serverName,
                                       StringComparison.OrdinalIgnoreCase))
                {
                    Debug.Assert(currentServer == null);
                    currentServer = server;
                }
            }

            if (currentServer == null)
            {
                string message = Properties.Resources.ServerNameNotFound;
                throw new SettingsException(message);
            }

            return(currentServer);
        }
Пример #7
0
        private void _CreateGeocoder()
        {
            GeocodingServiceInfo currentGeocodingServiceInfo = null;

            for (int index = 0; index < _servicesInfo.GeocodingInfo.GeocodingServiceInfo.Length; index++)
            {
                GeocodingServiceInfo geocodingServiceInfo = _servicesInfo.GeocodingInfo.GeocodingServiceInfo[index];
                if (geocodingServiceInfo.current)
                {
                    if (currentGeocodingServiceInfo != null)
                    {
                        throw new ApplicationException(Properties.Resources.DefaultGeocodingInfoIsNotUnique);
                    }
                    currentGeocodingServiceInfo = geocodingServiceInfo;
                }

                var isStreetsGeocoder = string.Equals(
                    geocodingServiceInfo.type,
                    STREETS_GEOCODER_TYPE,
                    StringComparison.OrdinalIgnoreCase);
                if (isStreetsGeocoder && this.StreetsGeocoder == null)
                {
                    var streetsGeocoderServer = _GetCurrentGcServer(geocodingServiceInfo);
                    var streetsGeocoder       = new Geocoder(geocodingServiceInfo,
                                                             streetsGeocoderServer, _exceptionHandler);
                    this.StreetsGeocoder = streetsGeocoder;
                }
            }

            // Detect that geocoder type is ArcGisGeocoder.
            var isArcGisGeocoder = string.Equals(
                currentGeocodingServiceInfo.type,
                ARCGIS_GEOCODER_TYPE,
                StringComparison.OrdinalIgnoreCase);

            var isWorldGeocoder = string.Equals(
                currentGeocodingServiceInfo.type,
                "WorldGeocoder",
                StringComparison.OrdinalIgnoreCase);

            // If it is arcgis geocoder - create it and use as default.
            if (isArcGisGeocoder)
            {
                AgsServer geocodeServer = _GetCurrentGcServer(currentGeocodingServiceInfo);
                _geocoder = new ArcGiscomGeocoder(currentGeocodingServiceInfo,
                                                  geocodeServer, _exceptionHandler);
                this.StreetsGeocoder = _geocoder;
            }
            else if (isWorldGeocoder)
            {
                var worldGeocoder = WorldGeocoder.CreateWorldGeocoder(
                    currentGeocodingServiceInfo, _exceptionHandler);
                _geocoder            = worldGeocoder;
                this.StreetsGeocoder = worldGeocoder;
            }
            else
            {
                AgsServer geocodeServer = _GetCurrentGcServer(currentGeocodingServiceInfo);
                _geocoder = new Geocoder(currentGeocodingServiceInfo,
                                         geocodeServer, _exceptionHandler);
            }

            if (this.StreetsGeocoder == null)
            {
                this.StreetsGeocoder = _geocoder;
            }
        }