From 5ab33e7b526b699c3934ed6f944fa2112ac64b57 Mon Sep 17 00:00:00 2001 From: Enrico Benedos Date: Mon, 3 Oct 2022 16:20:37 +0200 Subject: [PATCH 1/2] Added possibility to specify culture --- GPXReaderLib/GpxReader.cs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/GPXReaderLib/GpxReader.cs b/GPXReaderLib/GpxReader.cs index ef85366..cdb3f4f 100644 --- a/GPXReaderLib/GpxReader.cs +++ b/GPXReaderLib/GpxReader.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Xml; using System.Xml.Linq; @@ -13,11 +14,13 @@ public class GpxReader : IGpxReader { private readonly XDocument gpx; private readonly XmlNamespaceManager xmlNamespaceManager; + private CultureInfo cultureInfo; - public GpxReader(XDocument gpx, XmlNamespaceManager xmlNamespaceManager) + public GpxReader(XDocument gpx, XmlNamespaceManager xmlNamespaceManager, CultureInfo cultureInfo = default) { this.gpx = gpx; this.xmlNamespaceManager = xmlNamespaceManager; + this.cultureInfo = cultureInfo; } public string GetGpxName() @@ -30,11 +33,11 @@ public double GetElevation(ElevationType elevationType) switch (elevationType) { case ElevationType.Min: - return gpx.XPathSelectElements("//p:gpx//p:trk//p:trkseg//p:trkpt//p:ele", xmlNamespaceManager).Min(x => double.Parse(x.Value)); + return gpx.XPathSelectElements("//p:gpx//p:trk//p:trkseg//p:trkpt//p:ele", xmlNamespaceManager).Min(x => double.Parse(x.Value, cultureInfo)); case ElevationType.Max: - return gpx.XPathSelectElements("//p:gpx//p:trk//p:trkseg//p:trkpt//p:ele", xmlNamespaceManager).Max(x => double.Parse(x.Value)); + return gpx.XPathSelectElements("//p:gpx//p:trk//p:trkseg//p:trkpt//p:ele", xmlNamespaceManager).Max(x => double.Parse(x.Value, cultureInfo)); case ElevationType.Avg: - return gpx.XPathSelectElements("//p:gpx//p:trk//p:trkseg//p:trkpt//p:ele", xmlNamespaceManager).Average(x => double.Parse(x.Value)); + return gpx.XPathSelectElements("//p:gpx//p:trk//p:trkseg//p:trkpt//p:ele", xmlNamespaceManager).Average(x => double.Parse(x.Value, cultureInfo)); default: return 0.0; } @@ -72,12 +75,12 @@ public double GetElevationGain(double treshold = 0.22) public DateTime GetStartDt() { - return gpx.XPathSelectElements("//p:gpx//p:trk//p:trkseg//p:trkpt//p:time", xmlNamespaceManager).Min(x => DateTime.Parse(x.Value)); + return gpx.XPathSelectElements("//p:gpx//p:trk//p:trkseg//p:trkpt//p:time", xmlNamespaceManager).Min(x => DateTime.Parse(x.Value, cultureInfo)); } public DateTime GetEndDt() { - return gpx.XPathSelectElements("//p:gpx//p:trk//p:trkseg//p:trkpt//p:time", xmlNamespaceManager).Max(x => DateTime.Parse(x.Value)); + return gpx.XPathSelectElements("//p:gpx//p:trk//p:trkseg//p:trkpt//p:time", xmlNamespaceManager).Max(x => DateTime.Parse(x.Value, cultureInfo)); } public TimeSpan GetDuration() @@ -117,9 +120,9 @@ public IEnumerable GetGpxCoordinates() List gPXCoordinates = new List(); for (int i = 0; i < latitudesXAtt.Count; i++) //assume that two lists have same XAttributes count { - double latitude = double.Parse(latitudesXAtt[i].Value); - double longitude = double.Parse(longitudesXAtt[i].Value); - double elevation = double.Parse(elevationsXEl[i].Value); + double latitude = double.Parse(latitudesXAtt[i].Value, cultureInfo); + double longitude = double.Parse(longitudesXAtt[i].Value, cultureInfo); + double elevation = double.Parse(elevationsXEl[i].Value, cultureInfo); gPXCoordinates.Add(new TrackPoint(latitude, longitude, elevation)); } @@ -139,7 +142,7 @@ public GpxAltimetry GetGpxAltimetry() //Get list of all registered info record foreach (TrackPoint trackPoint in GetGpxCoordinates()) { - if(previousTrackPoint == null) + if (previousTrackPoint == null) { previousTrackPoint = trackPoint; } From 1a87bb5574a7f9659de9a2ca5d92d1d45d00445c Mon Sep 17 00:00:00 2001 From: Enrico Benedos Date: Tue, 4 Oct 2022 08:14:07 +0200 Subject: [PATCH 2/2] Updated versioning files --- CHANGELOG.md | 5 +++++ GPXReaderLib/GPXReaderLib.csproj | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 207b1dc..b943f59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.1.0] - 2022-xx-xx +### Added + +- Possibility to specify the current culture. (#12) + ## [2.0.1] - 2021-01-12 ### Fixed diff --git a/GPXReaderLib/GPXReaderLib.csproj b/GPXReaderLib/GPXReaderLib.csproj index 90a60cc..2481585 100644 --- a/GPXReaderLib/GPXReaderLib.csproj +++ b/GPXReaderLib/GPXReaderLib.csproj @@ -2,9 +2,9 @@ netstandard2.0 - 2.0.0 + 2.1.0 The main purpose is to fast read the main info of GPX file. (Tested only with Garmin's GPX) - 2.0.0 + 2.1.0 Enrico Benedos https://github.com/enricobenedos/GPXReaderLib/blob/master/LICENSE https://github.com/enricobenedos/GPXReaderLib