Exemplo n.º 1
0
 public void CanParseAll()
 {
     var gpx10 = new Gpx10Serializer();
     var gpx11 = new Gpx11Serializer();
     var dir = GetReferenceFileDirectory("gpx").EnumerateFiles();
     foreach (var fileInfo in dir)
     {
         using (var stream = new FileStream(fileInfo.FullName, FileMode.Open))
         {
             var streamWrapper = new StreamWrapper(stream);
             if (gpx10.CanDeSerialize(streamWrapper))
             {
                 var data = gpx10.DeSerialize(streamWrapper);
                 data.ToGpx();
                 data.ToGpx(1);
             }
             else if (gpx11.CanDeSerialize(streamWrapper))
             {
                 var data = gpx11.DeSerialize(streamWrapper);
                 data.ToGpx();
                 data.ToGpx(1);
             }
             else
             {
                 Assert.True(false, fileInfo.Name);
             }
         }
     }
 }
Exemplo n.º 2
0
        public GpsData DeSerialize(StreamWrapper streamWrapper)
        {
            var data = new GpsData();
            DateTime date = default(DateTime);
            var trackSegment = new TrackSegment();

            streamWrapper.Position = 0;
            using (var reader = new StreamReader(streamWrapper))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (date == default(DateTime))
                    {
                        var match = Regex.Match(line, H_DATE_LINE_REGEX);
                        if (match.Success)
                        {
                            var d = int.Parse(match.Groups["d"].Value);
                            var m = int.Parse(match.Groups["m"].Value);
                            var y = int.Parse(match.Groups["y"].Value);
                            var yn = int.Parse(DateTime.UtcNow.ToString("yy"));
                            if (y > yn)
                                yn += 100;
                            var yd = yn - y;
                            date = new DateTime(DateTime.UtcNow.Year -yd, m, d);
                        continue;
                        }
                    }

                    if (ParseMetadata(data, x => x.Vehicle.Model, H_GLIDER_TYPE_REGEX, line))
                        continue;

                    if (ParseMetadata(data, x => x.Vehicle.Identifier, H_GLIDER_REG_REGEX, line))
                        continue;

                    if (ParseMetadata(data, x => x.Vehicle.Crew1, H_CREW1_REGEX, line))
                        continue;

                    if (ParseMetadata(data, x => x.Vehicle.Crew2, H_CREW2_REGEX, line))
                        continue;

                    if (ParseFix(line, trackSegment, date))
                        continue;
                }
            }

            if (!trackSegment.IsEmpty())
            {
                data.Tracks.Add(new Track());
                data.Tracks[0].Segments.Add(trackSegment);
            }

            return data;
        }
Exemplo n.º 3
0
 public bool CanDeSerialize(StreamWrapper streamWrapper)
 {
     streamWrapper.Position = 0;
     using (var reader = new StreamReader(streamWrapper))
     {
         string line;
         while ((line = reader.ReadLine()) != null)
             if (Regex.IsMatch(line, FIX_SENTENCE) || Regex.IsMatch(line, WPT_SENTENCE))
                 return true;
     }
     return false;
 }
Exemplo n.º 4
0
 public bool CanDeSerialize(StreamWrapper streamWrapper)
 {
     streamWrapper.Position = 0;
     using (var reader = new StreamReader(streamWrapper))
     {
         string line;
         while ((line = reader.ReadLine()) != null)
         {
             if (Regex.IsMatch(line, B_LINE_REGEX))
                 return true;
         }
     }
     return false;
 }
Exemplo n.º 5
0
        public void Stockholm_Walk()
        {
            var file = GetReferenceFileDirectory("nmea").GetFiles().First(x => x.Name == "Stockholm_Walk.nmea");
            using (var stream = new FileStream(file.FullName, FileMode.Open))
            {
                var streamWrapper = new StreamWrapper(stream);
                var parser = new NmeaDeSerializer();
                var canParse = parser.CanDeSerialize(streamWrapper);
                var result = parser.DeSerialize(streamWrapper);

                Assert.That(canParse, Is.EqualTo(true));
                Assert.That(result.Waypoints.Count, Is.EqualTo(0));
                Assert.That(result.Tracks.Count, Is.EqualTo(1));
                Assert.That(result.Tracks[0].Segments.Count, Is.EqualTo(1));
                Assert.That(result.Tracks[0].Segments[0].Fixes.Count, Is.EqualTo(674));
            }
        }
Exemplo n.º 6
0
        public GpsData DeSerialize(StreamWrapper streamWrapper)
        {
            var data = new GpsData();
            var trackSegment = new TrackSegment();
            streamWrapper.Position = 0;
            using (var reader = new StreamReader(streamWrapper))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (ParseFix(line, trackSegment))
                        continue;
                    if (ParseWaypoint(line, data))
                        continue;
                }
            }

            if (!trackSegment.IsEmpty())
            {
                data.Tracks.Add(new Track());
                data.Tracks[0].Segments.Add(trackSegment);
            }
            return data;
        }
Exemplo n.º 7
0
 public static GpsData Parse(Stream stream)
 {
     var gpsStream = new StreamWrapper(stream);
     var parser = FileParsers.FirstOrDefault(x => x.CanDeSerialize(gpsStream));
     return parser == null ? null : parser.DeSerialize(gpsStream);
 }