コード例 #1
0
        public void TestSerialize()
        {
            var osmChange = new OsmChange()
            {
                Version   = 0.6,
                Generator = "OsmSharp",
                Create    = new OsmGeo[]
                {
                    new Node()
                    {
                        Id = 1
                    },
                    new Way()
                    {
                        Id = 10
                    },
                    new Relation()
                    {
                        Id = 100
                    }
                },
                Modify = new OsmGeo[]
                {
                    new Node()
                    {
                        Id = 2
                    },
                    new Way()
                    {
                        Id = 20
                    },
                    new Relation()
                    {
                        Id = 200
                    }
                },
                Delete = new OsmGeo[]
                {
                    new Node()
                    {
                        Id = 3
                    },
                    new Way()
                    {
                        Id = 30
                    },
                    new Relation()
                    {
                        Id = 300
                    }
                }
            };

            var result = osmChange.SerializeToXml();

            Assert.AreEqual("<osmChange generator=\"OsmSharp\" version=\"0.6\"><create><node id=\"1\" /><way id=\"10\" /><relation id=\"100\" /></create><modify><node id=\"2\" /><way id=\"20\" /><relation id=\"200\" /></modify><delete><node id=\"3\" /><way id=\"30\" /><relation id=\"300\" /></delete></osmChange>",
                            result);
        }
コード例 #2
0
        /// <inheritdoc />
        public async Task <DiffResult> UploadChangeset(long changesetId, OsmChange osmChange)
        {
            var elements = new OsmGeo[][] { osmChange.Create, osmChange.Modify, osmChange.Delete }
            .Where(c => c != null).SelectMany(c => c);

            foreach (var osmGeo in elements)
            {
                osmGeo.ChangeSetId = changesetId;
            }

            var address = BaseAddress + $"0.6/changeset/{changesetId}/upload";
            var request = new StringContent(osmChange.SerializeToXml());

            return(await Post <DiffResult>(address, request));
        }
コード例 #3
0
ファイル: OsmGateway.cs プロジェクト: bnayalivne/Site
        public async Task <DiffResult> UploadChangeset(string changesetId, OsmChange osmChange)
        {
            using (var client = new HttpClient())
            {
                foreach (var osmGeo in osmChange.Create.Concat(osmChange.Modify).Concat(osmChange.Delete))
                {
                    osmGeo.ChangeSetId = long.Parse(changesetId);
                }
                var address = _uploadChangesetAddress.Replace(":id", changesetId);
                UpdateHeaders(client, address, "POST");
                var response = await client.PostAsync(address, new StringContent(osmChange.SerializeToXml()));

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    var message = await response.Content.ReadAsStringAsync();

                    throw new Exception($"Unable to upload changeset: {message}");
                }
                var serializer = new XmlSerializer(typeof(DiffResult));
                return(serializer.Deserialize(await response.Content.ReadAsStreamAsync()) as DiffResult);
            }
        }