public void Read_ReadsWaypointUnsortedMetadataAndExtension() { var data = TestDataReader.Open("gpx-waypoint-with-metadata.gpx"); GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = true }); var result = target.Read() as GpxPoint; Assert.Equal(0.98, result.Metadata.MagVar); Assert.Equal(12.5, result.Metadata.GeoidHeight); Assert.Equal(GpsFix.Fix3D, result.Metadata.Fix); Assert.Equal(8, result.Metadata.SatellitesCount); Assert.Equal(5.1, result.Metadata.Hdop); Assert.Equal(8.1, result.Metadata.Vdop); Assert.Equal(10.8, result.Metadata.Pdop); Assert.Equal(45, result.Metadata.AgeOfDgpsData); Assert.Equal(124, result.Metadata.DgpsId); Assert.Equal("WPT Comment", result.Metadata.Comment); Assert.Equal("WPT Description", result.Metadata.Description); Assert.Equal("WPT Name", result.Metadata.Name); Assert.Equal("WPT Source", result.Metadata.Source); Assert.Equal(1, result.Metadata.Links.Count); GpxLink link = result.Metadata.Links.Single(); Assert.Equal("http://www.topografix.com", link.Url.OriginalString); Assert.Equal("Link text", link.Text); Assert.Equal("plain/text", link.Type); }
public void Constructor_Url_SetsUrl() { Uri url = new Uri("http://spatial.litesolutions.net"); GpxLink target = new GpxLink(url); Assert.Same(url, target.Url); }
private GpxLink ReadGpxLink() { GpxLink link = new GpxLink(); string elementName = reader.Name; bool isEmptyElement = reader.IsEmptyElement; while (reader.MoveToNextAttribute()) { switch (reader.Name) { case "href": link.Href = reader.Value; break; } } if (isEmptyElement) { return(link); } while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.Name) { case "text": link.Text = reader.ReadElementContentAsString(); break; case "type": link.MimeType = reader.ReadElementContentAsString(); break; default: reader.SkipElement(); break; } break; case XmlNodeType.EndElement: if (reader.Name != elementName) { throw new FormatException(reader.Name); } return(link); } } throw new FormatException(elementName); }
private void WriteLink(string elementName, GpxLink link) { Writer_.WriteStartElement(elementName); Writer_.WriteAttributeString("href", link.Href); if (link.Text != null) { Writer_.WriteElementString("text", link.Text); } if (link.MimeType != null) { Writer_.WriteElementString("type", link.MimeType); } Writer_.WriteEndElement(); }
/// <summary> /// Writes the given link to the output stream /// </summary> /// <param name="link">The link to be written</param> private void WriteLink(GpxLink link) { _xmlWriter.WriteStartElement("link"); _xmlWriter.WriteAttributeString("href", link.Url.OriginalString); if (link.Text != null) { _xmlWriter.WriteElementString("text", link.Text); } if (link.Type != null) { _xmlWriter.WriteElementString("type", link.Type); } _xmlWriter.WriteEndElement(); }
public void Read_ParsesTrackMetadata() { var data = TestDataReader.Open("gpx-track-with-metadata.gpx"); GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = true }); var result = target.Read() as GpxTrack; Assert.Equal("TRK Comment", result.Metadata.Comment); Assert.Equal("TRK Description", result.Metadata.Description); Assert.Equal("TRK Name", result.Metadata.Name); Assert.Equal("TRK Source", result.Metadata.Source); Assert.Equal("TRK Type", result.Metadata.Type); GpxLink link = result.Metadata.Links.Single(); Assert.Equal("http://www.topografix.com", link.Url.OriginalString); Assert.Equal("Link text", link.Text); Assert.Equal("plain/text", link.Type); }
public void Read_ParsesRouteWithMetadata() { MemoryStream data = new MemoryStream(GpxTestData.gpx_route_with_metadata); GpxReader target = new GpxReader(data, new GpxReaderSettings() { ReadMetadata = true }); var result = target.Read() as GpxRoute; Assert.Equal("RTE Comment", result.Metadata.Comment); Assert.Equal("RTE Description", result.Metadata.Description); Assert.Equal("RTE Name", result.Metadata.Name); Assert.Equal("RTE Source", result.Metadata.Source); Assert.Equal("RTE Type", result.Metadata.Type); Assert.Equal(1, result.Metadata.Links.Count); GpxLink link = result.Metadata.Links.Single(); Assert.Equal("http://www.topografix.com", link.Url.OriginalString); Assert.Equal("Link text", link.Text); Assert.Equal("plain/text", link.Type); }
private GpxLink ReadGpxLink(XmlReader reader) { GpxLink link = new GpxLink(); string elementName = reader.Name; bool isEmptyElement = reader.IsEmptyElement; while (reader.MoveToNextAttribute()) { switch (reader.Name) { case "href": link.Href = new Uri(reader.Value); break; } } if (isEmptyElement) return link; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.Name) { case "text": link.Text = ReadContentAsString(reader); break; case "type": link.MimeType = ReadContentAsString(reader); break; default: throw new FormatException(reader.Name); } break; case XmlNodeType.EndElement: if (reader.Name != elementName) throw new FormatException(reader.Name); return link; } } throw new FormatException(elementName); }
private void WriteLink(string elementName, GpxLink link) { Writer_.WriteStartElement(elementName); Writer_.WriteAttributeString("href", link.Href.ToString()); if (!string.IsNullOrWhiteSpace(link.Text)) Writer_.WriteElementString("text", link.Text); if (!string.IsNullOrWhiteSpace(link.MimeType)) Writer_.WriteElementString("type", link.MimeType); Writer_.WriteEndElement(); }
private void WriteLink(string elementName, GpxLink link) { Writer_.WriteStartElement(elementName); Writer_.WriteAttributeString("href", link.Href); if (link.Text != null) Writer_.WriteElementString("text", link.Text); if (link.MimeType != null) Writer_.WriteElementString("type", link.MimeType); Writer_.WriteEndElement(); }