public static List <TcxActivity> Convert(string xmlFilePath) { List <TcxActivity> result = new List <TcxActivity>(); string xmlContent = File.ReadAllText(xmlFilePath); XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlContent); // full document if (doc.HasChildNodes) { var trainingCenterDatabase = doc.GetElementsByTagName("TrainingCenterDatabase"); foreach (XmlNode trainingCenterDatabaseNode in trainingCenterDatabase) { var activities = GetChildren(trainingCenterDatabaseNode, "Activities"); foreach (XmlNode act in activities) { var activitiesChildren = GetChildren(act, "Activity"); foreach (XmlNode activity in activitiesChildren) { TcxActivity tcxAct = new TcxActivity(); var sport = activity.Attributes["Sport"]; var idChild = GetChildren(activity, "Id"); var lapChild = GetChildren(activity, "Lap"); tcxAct.Id = GetChildValue(activity, "Id"); tcxAct.Sport = sport.Value; tcxAct.Laps = new List <TcxLap>(); foreach (XmlNode lapNode in lapChild) { TcxLap lap = new TcxLap(); lap.StartTime = lapNode.Attributes["StartTime"].Value; lap.Track = new TcxTrack(); lap.Track.TrackPoints = new List <TcxTrackpoint>(); var trackNodes = GetChildren(lapNode, "Track"); foreach (var trackNode in trackNodes) { var trackPointsNodes = GetChildren(trackNode, "Trackpoint"); foreach (var trackPointNode in trackPointsNodes) { TcxTrackpoint point = LoadTrackpoint(trackPointNode); lap.Track.TrackPoints.Add(point); } } tcxAct.Laps.Add(lap); } result.Add(tcxAct); } } } } return(result); }
private void AssertLap(TcxLap lap) { Assert.AreEqual((point2Time - point1Time).TotalSeconds.ToString(), lap.TotalTimeSeconds); Assert.AreEqual("15.15", lap.DistanceMeters); Assert.AreEqual("14", lap.Calories); Assert.AreEqual("Active", lap.Intensity); Assert.AreEqual("Manual", lap.TriggerMethod); Assert.AreEqual(2, lap.TrackPoints.Count()); // track point 1 var point = lap.TrackPoints.First(); Assert.AreEqual("1", point.Cadence); Assert.AreEqual("3.3", point.DistanceMeters); Assert.AreEqual("4", point.HeartRateBpm); Assert.AreEqual("5", point.Watts); Assert.AreEqual("6.6", point.Speed); Assert.AreEqual("0007-08-09T10:11:12Z", point.Time); // track point 2 point = lap.TrackPoints.Last(); Assert.AreEqual("13", point.Cadence); Assert.AreEqual("15.15", point.DistanceMeters); Assert.AreEqual("16", point.HeartRateBpm); Assert.AreEqual("17", point.Watts); Assert.AreEqual("18.18", point.Speed); Assert.AreEqual("0019-12-21T22:23:24Z", point.Time); }