public void RelationDelete(Relation relation) { if (this._current_changeset == null) { throw new InvalidOperationException("No open changeset found!"); } if (!relation.Id.HasValue) { throw new ArgumentOutOfRangeException("Cannot update an object without an id!"); } relation relation1 = relation.ConvertTo(); relation1.changeset = this._current_changeset.id; relation1.changesetSpecified = true; osm osm1 = new osm(); osm1.relation = new relation[1]; osm1.relation[0] = relation1; XmlSerializer xmlSerializer = new XmlSerializer(typeof(osm)); MemoryStream memoryStream = new MemoryStream(); Stream stream1 = (Stream)memoryStream; Stream stream2 = stream1; osm osm2 = osm1; xmlSerializer.Serialize(stream2, (object)osm2); stream1.Flush(); memoryStream.Flush(); byte[] array = memoryStream.ToArray(); this.DoApiCall(1 != 0, string.Format("api/0.6/relation/{0}", (object)relation.Id.Value), APIConnection.Method.DELETE, array); }
public Relation RelationCreate(Relation relation) { if (this._current_changeset == null) { throw new InvalidOperationException("No open changeset found!"); } relation relation1 = relation.ConvertTo(); relation1.changeset = this._current_changeset.id; relation1.changesetSpecified = true; osm osm1 = new osm(); osm1.relation = new relation[1]; osm1.relation[0] = relation1; XmlSerializer xmlSerializer = new XmlSerializer(typeof(osm)); MemoryStream memoryStream = new MemoryStream(); Stream stream1 = (Stream)memoryStream; Stream stream2 = stream1; osm osm2 = osm1; xmlSerializer.Serialize(stream2, (object)osm2); stream1.Flush(); memoryStream.Flush(); string s = this.DoApiCall(true, "api/0.6/relation/create", APIConnection.Method.PUT, memoryStream.ToArray()); long result; if (!long.TryParse(s, out result)) { throw new APIException(string.Format("Invalid response when creating a new relation: {0}", (object)s)); } relation.Id = new long?(result); return(relation); }
/// <summary> /// Creates a new relation. /// </summary> /// <param name="relation"></param> /// <returns></returns> public Relation RelationCreate(Relation relation) { if (_current_changeset == null) { throw new InvalidOperationException("No open changeset found!"); } // build a new node. relation xml_relation = relation.ConvertTo(); xml_relation.changeset = _current_changeset.id; xml_relation.changesetSpecified = true; // encapsulate into an osm object. OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm(); osm.relation = new Osm.Xml.v0_6.relation[1]; osm.relation[0] = xml_relation; // serialize the changeset. XmlSerializer serializer = new XmlSerializer(typeof(OsmSharp.Osm.Xml.v0_6.osm)); MemoryStream mem_stream = new MemoryStream(); Stream stream = mem_stream; serializer.Serialize(stream, osm); stream.Flush(); mem_stream.Flush(); byte[] put_data = mem_stream.ToArray(); // do the api call. string response_string = this.DoApiCall(true, "api/0.6/relation/create", Method.PUT, put_data); // get the id-response. long id; if (!long.TryParse(response_string, out id)) { // invalid response! throw new APIException(string.Format("Invalid response when creating a new relation: {0}", response_string)); } relation.Id = id; return(relation); }
/// <summary> /// Deletes the given relation by adding it's deletion to the current changeset. /// </summary> /// <param name="relation"></param> public void RelationDelete(Relation relation) { if (_current_changeset == null) { throw new InvalidOperationException("No open changeset found!"); } if (!relation.Id.HasValue) { throw new ArgumentOutOfRangeException("Cannot update an object without an id!"); } // build a new node. relation xml_relation = relation.ConvertTo(); xml_relation.changeset = _current_changeset.id; xml_relation.changesetSpecified = true; // encapsulate into an osm object. OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm(); osm.relation = new Osm.Xml.v0_6.relation[1]; osm.relation[0] = xml_relation; // serialize the changeset. XmlSerializer serializer = new XmlSerializer(typeof(OsmSharp.Osm.Xml.v0_6.osm)); MemoryStream mem_stream = new MemoryStream(); Stream stream = mem_stream; serializer.Serialize(stream, osm); stream.Flush(); mem_stream.Flush(); byte[] put_data = mem_stream.ToArray(); // do the api call. this.DoApiCall(true, string.Format("api/0.6/relation/{0}", relation.Id.Value), Method.DELETE, put_data); }
/// <summary> /// Updates the given relation by adding it's changes to the current changeset. /// </summary> /// <param name="relation"></param> public void RelationUpdate(Relation relation) { if (_current_changeset == null) { throw new InvalidOperationException("No open changeset found!"); } if (!relation.Id.HasValue) { throw new ArgumentOutOfRangeException("Cannot update an object without an id!"); } // build a new node. relation xml_relation = relation.ConvertTo(); xml_relation.changeset = _current_changeset.id; xml_relation.changesetSpecified = true; // encapsulate into an osm object. OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm(); osm.relation = new Osm.Xml.v0_6.relation[1]; osm.relation[0] = xml_relation; // serialize the changeset. XmlSerializer serializer = new XmlSerializer(typeof(OsmSharp.Osm.Xml.v0_6.osm)); MemoryStream mem_stream = new MemoryStream(); Stream stream = mem_stream; serializer.Serialize(stream, osm); stream.Flush(); mem_stream.Flush(); byte[] put_data = mem_stream.ToArray(); // do the api call. this.DoApiCall(true, string.Format("api/0.6/relation/{0}", relation.Id.Value), Method.PUT, put_data); }
/// <summary> /// Creates a new relation. /// </summary> /// <param name="relation"></param> /// <returns></returns> public Relation RelationCreate(Relation relation) { if (_current_changeset == null) { throw new InvalidOperationException("No open changeset found!"); } // build a new node. relation xml_relation = relation.ConvertTo(); xml_relation.changeset = _current_changeset.id; xml_relation.changesetSpecified = true; // encapsulate into an osm object. OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm(); osm.relation = new Osm.Xml.v0_6.relation[1]; osm.relation[0] = xml_relation; // serialize the changeset. XmlSerializer serializer = new XmlSerializer(typeof(OsmSharp.Osm.Xml.v0_6.osm)); MemoryStream mem_stream = new MemoryStream(); Stream stream = mem_stream; serializer.Serialize(stream, osm); stream.Flush(); mem_stream.Flush(); byte[] put_data = mem_stream.ToArray(); // do the api call. string response_string = this.DoApiCall(true, "api/0.6/relation/create", Method.PUT, put_data); // get the id-response. long id; if (!long.TryParse(response_string, out id)) { // invalid response! throw new APIException(string.Format("Invalid response when creating a new relation: {0}", response_string)); } relation.Id = id; return relation; }