/// <summary> /// Reads the file and return the contained activities. /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns></returns> public ICollection <TrackActivity> ReadFile(string fileName) { List <TrackActivity> activities = new List <TrackActivity>(); TcxTree tree = ParseFile(fileName); if (tree == null) { return(activities); } if (tree.CourseList != null && tree.CourseList.Courses != null) { foreach (TcxCourse tcxCourse in tree.CourseList.Courses) { TrackActivity track = ConvertCourse(tcxCourse); track.FileName = fileName; activities.Add(track); } } if (tree.ActivityList != null && tree.ActivityList.Activities != null) { foreach (TcxActivity tcxActivity in tree.ActivityList.Activities) { TrackActivity track = ConvertActivity(tcxActivity); track.FileName = fileName; activities.Add(track); } } return(activities); }
private TcxTree ParseFile(string file) { TcxTree tree = null; try { using (StreamReader reader = new StreamReader(file)) { tree = _xmlSerializer.Deserialize(reader) as TcxTree; } } catch (IOException) { // Error reading file } catch (InvalidOperationException) { // Serialization error } return(tree); }