public override FileInformation ExtractInformation(FilePath file) { var information = new FileInformation(); var gpxFiles = _gpxDataAccess.Read(File.ReadAllText(file.FullPath)); var date = (from t in gpxFiles.Tracks from s in t.Segments from p in s.TrackPoints where p.TimeSpecified select p.Time).ToArray(); if (date.Any()) { information.AddInformation(FileInformationNames.GpxDate, date.Min()); } return(information); }
public override void ChangeContent(FilePath newFile) { var file = new FileInfo(newFile.FullPath); if (file.Exists) { var reader = file.OpenText(); var content = reader.ReadToEnd(); var gpxFile = _gpxDataAccess.Read(content); var newTracks = new List <GpxTrack>(); foreach (var currentTrack in gpxFile.Tracks) { var points = currentTrack.Segments.SelectMany(x => x.TrackPoints).ToArray(); var distance = new double[points.Length - 1]; var time = new TimeSpan[points.Length - 1]; var speed = new double[points.Length - 1]; var newTrack = CreateNewTrack(currentTrack); for (int i = 0; i < points.Length - 1; i++) { distance[i] = points[i].Coordinate.DistanceTo(points[i + 1].Coordinate); time[i] = points[i + 1].Time.Subtract(points[i].Time); speed[i] = (distance[i] / 1000) / time[i].TotalHours; var conditionCounter = 0; if (distance[i] > 500) { conditionCounter++; } if (time[i] > TimeSpan.FromMinutes(5)) { conditionCounter++; } if (speed[i] > 1500) { conditionCounter++; } newTrack.Segments[0].TrackPoints.Add(points[i]); if (conditionCounter >= 2) { newTracks.Add(newTrack); newTrack = CreateNewTrack(currentTrack); } } newTracks.Add(newTrack); } gpxFile.Tracks.Clear(); foreach (var track in newTracks) { var pointCountArray = track.Segments.SelectMany(x => x.TrackPoints).ToArray(); var pointCount = pointCountArray.Length; if (pointCount < 10) { continue; } if (pointCount < 100 && !ReachedDistance(pointCountArray)) { continue; } gpxFile.Tracks.Add(track); } var newContent = _gpxDataAccess.Write(gpxFile); reader.Close(); reader.Dispose(); File.WriteAllText(newFile.FullPath, newContent); return; } throw new InvalidOperationException("File during operation of service was removed from original location"); }