public ICollection <LapMesg> GetLaps(PreferredLapType preferredLapType, WorkoutSamples workoutSamples, Dynastream.Fit.DateTime startTime, Sport sport, SubSport subSport) { using var tracing = Tracing.Trace($"{nameof(FitConverter)}.{nameof(GetLaps)}") .WithTag(TagKey.Format, FileFormat.Fit.ToString()); if ((preferredLapType == PreferredLapType.Default || preferredLapType == PreferredLapType.Class_Segments) && workoutSamples.Segment_List.Any()) { return(GetLapsBasedOnSegments(workoutSamples, startTime, sport, subSport)); } return(GetLapsBasedOnDistance(workoutSamples, startTime, sport, subSport)); }
public void Fit_Converter_Creates_Valid_Fit(string filename, PreferredLapType lapType) { var workoutPath = Path.Join(DataDirectory, $"{filename}.json"); var settings = new Settings() { Format = new Format() { Running = new Running() { PreferredLapType = lapType }, Cycling = new Cycling() { PreferredLapType = lapType } } }; var converter = new ConverterInstance(settings); var convertedMesgs = converter.ConvertForTest(workoutPath); convertedMesgs.Should().NotBeNullOrEmpty(); var dest = Path.Join(DataDirectory, $"test_output_{filename}.fit"); try { using (FileStream fitDest = new FileStream(dest, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { var validator = new Encode(ProtocolVersion.V20); validator.Open(fitDest); validator.Write(convertedMesgs); // validates while writing validator.Close(); } } finally { System.IO.File.Delete(dest); } }