/// <summary>
        /// Method collects information from solve request data for planned date and
        /// builds request object.
        /// </summary>
        /// <param name="data">Required data to get information from.</param>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="data"/> is null reference.</exception>
        /// <returns>Request object with filled information for request.</returns>
        public SubmitDiscoveryRequest BuildRequest(DiscoveryRequestData data)
        {
            // Validate inputs.
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            // Build request object.
            SubmitDiscoveryRequest req = new SubmitDiscoveryRequest();

            if (data.RegionPoint != null)
            {
                int wkid = data.MapExtent.SpatialReference.WKID;

                // Get depot point converted with correct spatial reference.
                Point   depotPoint = (Point)data.RegionPoint;
                Point   wmPoint    = WebMercatorUtil.ProjectPointToWebMercator(depotPoint, wkid);
                GPPoint gpPoint    = GPObjectHelper.PointToGPPoint(wmPoint);
                gpPoint.SpatialReference = new GPSpatialReference(wkid);

                // Fill required options.
                req.Geometry         = gpPoint;
                req.GeometryType     = NAGeometryType.esriGeometryPoint;
                req.SpatialReference = wkid;
                req.ResponseFormat   = NAOutputFormat.JSON;
                req.Layers           = NAIdentifyOperationLayers.AllLayers;
                req.Tolerance        = DEFAULT_TOLERANCE;

                req.ImageDisplay = _GetImageDisplayParameter(data.MapExtent);

                req.MapExtent = string.Format(MAP_EXTENT_PARAMETER_FORMAT, data.MapExtent.XMin,
                                              data.MapExtent.YMin, data.MapExtent.XMax, data.MapExtent.YMax);

                // Do not return geometry to optimize request.
                req.ReturnGeometry = false;
                req.ReturnZ        = false;
                req.ReturnM        = false;

                // Fill non-required options.
                req.LayerDefinitions   = string.Empty;
                req.Time               = string.Empty;
                req.LayerTimeOptions   = string.Empty;
                req.MaxAllowableOffset = string.Empty;
                req.DynamicLayers      = string.Empty;
            }

            return(req);
        }
        /// <summary>
        /// Gets geographic region name.
        /// </summary>
        /// <param name="request">Discovery request.</param>
        /// <param name="knownTypes">Collection of known types to parse result.</param>
        /// <returns>Returns empty string.</returns>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="request"/> or <paramref name="knownTypes"/> is null reference.
        /// </exception>
        public string GetRegionName(SubmitDiscoveryRequest request, IEnumerable <Type> knownTypes)
        {
            // Validate inputs.
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (knownTypes == null)
            {
                throw new ArgumentNullException("knownTypes");
            }

            return(string.Empty);
        }
Пример #3
0
        /// <summary>
        /// Gets geographic region name.
        /// </summary>
        /// <param name="request">Discovery request.</param>
        /// <param name="knownTypes">Collection of known types to parse result.</param>
        /// <returns>Region name if successfully found.</returns>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="request"/> or <paramref name="knownTypes"/> is null reference.
        /// </exception>
        /// <exception cref="T:ESRI.ArcLogistics.Routing.RouteException">
        /// Result region name is null or empty string.</exception>
        public string GetRegionName(SubmitDiscoveryRequest request, IEnumerable <Type> knownTypes)
        {
            // Validate inputs.
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (knownTypes == null)
            {
                throw new ArgumentNullException("knownTypes");
            }

            // Create appropriate service client to make requests.
            string baseUrl = UriHelper.Concat(_discoveryServiceConfig.RestUrl,
                                              QUERY_OBJ_IDENTIFY);
            var client = new DiscoveryClient(baseUrl, _server.OpenConnection());

            // Get query and context.
            string query = RestHelper.BuildQueryString(request,
                                                       DiscoveryRequestBuilder.JsonTypes, false);
            var context = new RequestContext(_server.OpenConnection(), knownTypes);

            // Get response from service.
            var response = client.GetRegionName(query, context);

            // Try to get region name from response.
            string regionName = string.Empty;

            if (response != null && response.Results != null)
            {
                // Get any first description object from the collection.
                var parameterObject = response.Results.FirstOrDefault();

                if (parameterObject != null && parameterObject.Attributes != null)
                {
                    // Get region name from anyone attributes collection.
                    parameterObject.Attributes.TryGet(REGION_MEMBER_NAME, out regionName);
                }
            }

            if (string.IsNullOrEmpty(regionName))
            {
                throw new RouteException(Properties.Messages.Error_InvalidRegionInformation);
            }

            return(regionName);
        }