protected bool ClearHostedFeatureLayer() { bool isDone = false; string jsonData = "f=json&where=1=1&rollbackOnFailure=false"; string url = this.FeatureLayer.AgolLayerUrl + (this.FeatureLayer.AgolLayerUrl.EndsWith("/") ? "deleteFeatures" : "/deleteFeatures"); HttpWebRequest agolRequest = CreateHttpRequest(url, jsonData); using (HttpWebResponse response = (HttpWebResponse)agolRequest.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(FeatureLayerEditResults)); FeatureLayerEditResults editResults = (FeatureLayerEditResults)serializer.ReadObject(responseStream); if (editResults.error != null) { if (numTries < maxTries && editResults.error.details[0].IndexOf("operation is not supported") > -1) { numTries++; RunEnableEditingTask(); } else { numTries = 0; isErrorLogged = true; if (logCallback != null) { logCallback(string.Format("Delete {0} Features Error - {1}, {2}", this.FeatureLayer.Name, editResults.error.message, string.Join(",", editResults.error.details)), EventLogEntryType.Error); } } } else { PostEditProcess(editResults.deleteResults, null, "Delete"); } isDone = true; } } return(isDone); }
protected bool ApplyEdits(List <SpatialObject> adds, List <SpatialObject> updates, List <SpatialObject> deletes) { bool isDone = false; try { string jsonAdds = BuildFeatuesJson(adds, this.FeatureLayer.SrWKID, "add"); string jsonUpdates = BuildFeatuesJson(updates, this.FeatureLayer.SrWKID, "update"); string jsonDeletes = BuildFeatuesJson(deletes, this.FeatureLayer.SrWKID, "delete"); string jsonData = string.Format("f=json&adds={0}&updates={1}&deletes={2}&rollbackOnFailure=true", jsonAdds, jsonUpdates, jsonDeletes); string url = this.FeatureLayer.AgolLayerUrl + (this.FeatureLayer.AgolLayerUrl.EndsWith("/") ? "applyEdits" : "/applyEdits"); HttpWebRequest agolRequest = CreateHttpRequest(url, jsonData); using (HttpWebResponse response = (HttpWebResponse)agolRequest.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(FeatureLayerEditResults)); FeatureLayerEditResults editResults = (FeatureLayerEditResults)serializer.ReadObject(responseStream); if (editResults != null) { if (editResults.error != null) { if (numTries < maxTries && editResults.error.details[0].IndexOf("operation is not supported") > -1) { numTries++; RunEnableEditingTask(); } else { numTries = 0; isErrorLogged = true; if (logCallback != null) { logCallback(string.Format("Editing {0} Feature Layer Error - {1}, {2}", this.FeatureLayer.Name, editResults.error.message, string.Join(",", editResults.error.details)), EventLogEntryType.Error); } } } else { PostEditProcess(editResults.addResults, adds, "Add"); PostEditProcess(editResults.updateResults, null, "Update"); PostEditProcess(editResults.deleteResults, null, "Delete"); } } isDone = true; } } } catch (Exception ex) { isDone = true; isErrorLogged = true; if (logCallback != null) { logCallback(string.Format("JSON Formatting {0} Features Error: {1}", this.FeatureLayer.Name, ex.Message), EventLogEntryType.Error); } } return(isDone); }