コード例 #1
0
 public PointInPolygoinQueryWithRelationCommand(PointInPolyArgsWithRelation searchArgs,
                                                IFeatureWorkspace workspace)
 {
     SearchArgs = searchArgs;
     Workspace  = workspace;
     Values     = new List <FieldValueMap>();
 }
        /// <summary>
        ///   Handles the incoming rest requests
        /// </summary>
        /// <param name="boundVariables"> The bound variables. </param>
        /// <param name="operationInput"> The operation input. </param>
        /// <param name="outputFormat"> The output format. </param>
        /// <param name="requestProperties"> The request properties. </param>
        /// <param name="responseProperties"> The response properties. </param>
        /// <returns> </returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static byte[] Handler(NameValueCollection boundVariables, JsonObject operationInput,
                                     string outputFormat, string requestProperties,
                                     out string responseProperties)
        {
            responseProperties = null;
            var errors = new ErrorModel(400);

            string layerName, relationshipClassName;
            double?utmx, utmy;

            object[] attributeListObj, relationshipAttributeListObj;

            var found = operationInput.TryGetString("layerName", out layerName);

            if (!found || string.IsNullOrEmpty(layerName))
            {
                throw new ArgumentNullException("layerName");
            }

            found = operationInput.TryGetString("relationshipClassName", out relationshipClassName);
            if (!found || string.IsNullOrEmpty(relationshipClassName))
            {
                throw new ArgumentNullException("relationshipClassName");
            }

            found = operationInput.TryGetAsDouble("utmx", out utmx);
            if (!found || !utmx.HasValue)
            {
                throw new ArgumentNullException("utmx");
            }

            found = operationInput.TryGetAsDouble("utmy", out utmy);
            if (!found || !utmy.HasValue)
            {
                throw new ArgumentNullException("utmy");
            }

            found = operationInput.TryGetArray("attributeList", out attributeListObj);
            if (!found || attributeListObj == null || attributeListObj.Length < 1)
            {
                throw new ArgumentNullException("attributeList");
            }

            found = operationInput.TryGetArray("relationshipAttributeListObj", out relationshipAttributeListObj);
            if (!found || relationshipAttributeListObj == null || relationshipAttributeListObj.Length < 1)
            {
                throw new ArgumentNullException("relationshipAttributeListObj");
            }

            var attributeList        = attributeListObj.Cast <string>().ToArray();
            var relatedAttributeList = relationshipAttributeListObj.Cast <string>().ToArray();

            var searchArgs = new PointInPolyArgsWithRelation(layerName, utmx.Value, utmy.Value, attributeList,
                                                             relatedAttributeList, relationshipClassName);

            var connector = SdeConnectorFactory.Create(layerName);

            if (connector == null)
            {
                return(Json(new
                {
                    Message = "Database does not exist for {0}".With(layerName)
                }));
            }

            var workspace = connector.Connect();

            var featureWorkSpace = workspace as IFeatureWorkspace;

            if (featureWorkSpace == null)
            {
                errors.Message = "Error connecting to SDE.";

                return(Json(errors));
            }

            var response = CommandExecutor.ExecuteCommand(new PointInPolygoinQueryCommand(searchArgs, featureWorkSpace));

            if (response == null)
            {
                errors.Message = "No features found in {2} at the location {0}, {1}.".With(
                    searchArgs.Point.X, searchArgs.Point.Y, searchArgs.LayerName);

                return(Json(errors));
            }

            return(Json(response));
        }