${REST_EditFeaturesParameters_Title}

${REST_EditFeaturesParameters_Description}

        /// <summary>${REST_EditFeaturesService_method_ProcessAsync_D}</summary>
        /// <param name="parameters">${REST_EditFeaturesService_method_ProcessAsync_param_Parameters}</param>
        /// <param name="state">${REST_EditFeaturesService_method_ProcessAsync_param_state}</param>
        public async Task<EditFeaturesResult> ProcessAsync(EditFeaturesParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(ExceptionStrings.ArgumentIsNull);
            }
            if (string.IsNullOrEmpty(this.Url))
            {
                throw new InvalidOperationException(ExceptionStrings.InvalidUrl);
            }

            if (parameters.EditType == EditType.ADD)
            {
                base.Url += ".json?returnContent=true&debug=true";//直接获取添加地物SmID
            }
            else if (parameters.EditType == EditType.DELETE)
            {
                base.Url += ".json?_method=DELETE&debug=true";
            }
            else
            {
                base.Url += ".json?_method=PUT&debug=true";
            }

            var jsonResult = await base.SubmitRequest(base.Url, GetParameters(parameters), true, true);
            EditFeaturesResult result = null;
            if (JsonObject.Parse(jsonResult) is JsonObject)
            {
                JsonObject jsonObject = JsonObject.Parse(jsonResult);
                result = EditFeaturesResult.FromJson(jsonObject);

            }
            else
            {
                JsonArray json = JsonArray.Parse(jsonResult);
                result = new EditFeaturesResult();
                result.Succeed = true;
                result.IDs = new List<int>();
                for (int i = 0; i < json.Count; i++)
                {
                    result.IDs.Add((int)json[i].GetNumberEx());
                }
            }
            return result;
        }
        private System.Collections.Generic.Dictionary<string, string> GetParameters(EditFeaturesParameters parameters)
        {
            Dictionary<string, string> dictionary = new Dictionary<string, string>();

            if (parameters.EditType == EditType.DELETE)
            {
                if (parameters.IDs != null)
                {
                    string ids = string.Empty;
                    List<string> idslist = new List<string>();
                    for (int k = 0; k < parameters.IDs.Count; k++)
                    {
                        //idslist.Add(parameters.IDs[k].ToString());
                        dictionary.Add(k.ToString(), parameters.IDs[k].ToString());
                    }
                    //ids += string.Join(",", idslist.ToArray());
                    //dictionary.Add("Edit", ids);
                }
                else
                {
                    throw new ArgumentNullException(ExceptionStrings.ArgumentIsNull);
                }
            }
            else
            {
                if (parameters.Features != null && parameters.Features.Count > 0)
                {
                    string json = "";
                    List<string> list = new List<string>();

                    for (int i = 0; i < parameters.Features.Count; i++)
                    {
                        Dictionary<string, string> dict = new Dictionary<string, string>();
                        ServerFeature sf = parameters.Features[i].ToServerFeature();

                        //FiledNames
                        dict.Add("fieldNames", JsonHelper.FromIList(sf.FieldNames));

                        //FiledValues
                        dict.Add("fieldValues", JsonHelper.FromIList(sf.FieldValues));

                        //Geometry
                        if (parameters.EditType == EditType.UPDATA)
                        {
                            //更新时,ID的个数和Feature的个数不一致更新就不起作用!
                            if (parameters.IDs.Count == parameters.Features.Count)
                            {
                                if (sf.Geometry != null)
                                {
                                    sf.Geometry.ID = parameters.IDs[i];
                                }
                                else
                                {
                                    sf.ID = parameters.IDs[i];
                                }

                            }
                        }

                        dict.Add("ID", sf.ID.ToString());
                        dict.Add("geometry", sf.Geometry == null ? "null" : ServerGeometry.ToJson(sf.Geometry));

                        list.Add(EditGetStringFromDict(dict));
                    }


                    json += string.Join(",", list.ToArray());
                    dictionary.Add("Edit", json);
                }
            }

            return dictionary;
        }