示例#1
0
        /// <summary>
        /// Converts an API v6 xml changeset object to a SimpleChange object.
        /// </summary>
        /// <param name="xml_changeset"></param>
        /// <returns></returns>
        private ChangeSetInfo Convertv6XmlChangeSet(OsmSharp.Osm.Xml.v0_6.changeset xml_changeset)
        {
            ChangeSetInfo simple_changeset = new ChangeSetInfo();

            if (xml_changeset.idSpecified)
            {
                simple_changeset.Id = xml_changeset.id;
            }
            if (xml_changeset.closed_atSpecified)
            {
                simple_changeset.ClosedAt = xml_changeset.closed_at;
            }
            if (xml_changeset.closed_atSpecified)
            {
                simple_changeset.CreatedAt = xml_changeset.created_at;
            }
            if (xml_changeset.max_latSpecified)
            {
                simple_changeset.MaxLat = xml_changeset.max_lat;
            }
            if (xml_changeset.max_lonSpecified)
            {
                simple_changeset.MaxLon = xml_changeset.max_lon;
            }
            if (xml_changeset.min_latSpecified)
            {
                simple_changeset.MinLat = xml_changeset.min_lat;
            }
            if (xml_changeset.min_lonSpecified)
            {
                simple_changeset.MinLon = xml_changeset.min_lon;
            }
            if (xml_changeset.openSpecified)
            {
                simple_changeset.Open = xml_changeset.open;
            }
            if (xml_changeset.tag != null)
            {
                simple_changeset.Tags = new Dictionary <string, string>();
                foreach (Osm.Xml.v0_6.tag xml_tag in xml_changeset.tag)
                {
                    simple_changeset.Tags.Add(xml_tag.k, xml_tag.v);
                }
            }
            if (xml_changeset.uidSpecified)
            {
                simple_changeset.UserId = xml_changeset.uid;
            }
            simple_changeset.User = xml_changeset.user;
            return(simple_changeset);
        }
示例#2
0
        /// <summary>
        /// Creates a new changeset by opening one.
        /// </summary>
        /// <param name="comment"></param>
        /// <param name="created_by"></param>
        /// <returns></returns>
        public long ChangeSetOpen(string comment, string created_by)
        {
            if (created_by == null || created_by.Length == 0)
            { // a created by tag always has to exist and have a usefull value.
                throw new ArgumentOutOfRangeException("A created by tag always has to exist and have a usefull value.");
            }

            // build a new changeset.
            OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm();
            osm.changeset = new Osm.Xml.v0_6.changeset[1];
            OsmSharp.Osm.Xml.v0_6.changeset changeset = new Osm.Xml.v0_6.changeset();
            changeset.tag = new OsmSharp.Osm.Xml.v0_6.tag[1];
            changeset.tag[0] = new Osm.Xml.v0_6.tag();
            changeset.tag[0].k = "created_by";
            changeset.tag[0].v = created_by;
            osm.changeset[0] = changeset;

            // 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/changeset/create", Method.PUT, put_data);

            _current_changeset = changeset;
            _current_changeset.id = long.Parse(response_string);
            return _current_changeset.id;
        }