Ejemplo n.º 1
0
        public static IRunway CreateFromString(string s)
        {
            int    id, airportId, length, width, threshold;
            double lat, lng, alt;

            var fields = s.Split(',');

            int.TryParse(fields[0], out id);
            int.TryParse(fields[1], out airportId);
            int.TryParse(fields[3], out length);
            int.TryParse(fields[4], out width);

            var result = new Runway()
            {
                Id        = id,
                AirportId = airportId,
                Length    = length,
                Width     = width,
                Surface   = fields[5].Trim('"'),
                Lighted   = parseBool(fields[6]),
                Closed    = parseBool(fields[7]),
            };

            int.TryParse(fields[12].Trim('"'), out threshold);
            double.TryParse(fields[9].Trim('"'), out lat);
            double.TryParse(fields[10].Trim('"'), out lng);
            double.TryParse(fields[11].Trim('"'), out alt);

            result.End1 = new RunwayEnd()
            {
                Identifier         = fields[8].Trim('"'),
                DisplacedThreshold = threshold,
                Position           = new BasicGeoposition()
                {
                    Altitude  = UnitConverter.FeetToMeters(alt),
                    Latitude  = lat,
                    Longitude = lng
                }
            };

            int.TryParse(fields[18].Trim('"'), out threshold);
            double.TryParse(fields[15].Trim('"'), out lat);
            double.TryParse(fields[16].Trim('"'), out lng);
            double.TryParse(fields[17].Trim('"'), out alt);

            result.End2 = new RunwayEnd()
            {
                Identifier         = fields[14].Trim('"'),
                DisplacedThreshold = threshold,
                Position           = new BasicGeoposition()
                {
                    Altitude  = UnitConverter.FeetToMeters(alt),
                    Latitude  = lat,
                    Longitude = lng
                }
            };

            return(result);
        }
Ejemplo n.º 2
0
        public void TestCreateFromString()
        {
            string testString = "244585,20947,\"KRNT\",5382,200,\"ASPH-CONC-G\",1,0,\"16\",47.5005,-122.217,24,174,300,\"34\",47.4858,-122.215,32,354,340";
            var expected = new Runway();

            expected.Id = 244585;
            expected.AirportId = 20947;
            expected.Length = 5382;
            expected.Width = 200;
            expected.Surface = "ASPH-CONC-G";
            expected.Lighted = true;
            expected.Closed = false;

            expected.End1 = new RunwayEnd();
            expected.End1.Identifier = 16;
            expected.End1.Latitude = 47.5005;
            expected.End1.Longitude = -122.217;
            expected.End1.Elevation = 24;
            expected.End1.DisplacedThreshold = 300;

            expected.End2 = new RunwayEnd();
            expected.End2.Identifier = 34;
            expected.End2.Latitude = 47.4858;
            expected.End2.Longitude = -122.215;
            expected.End2.Elevation = 32;
            expected.End2.DisplacedThreshold = 340;

            var actual = Runway.CreateFromString(testString);

            if (expected.Id != actual.Id
                || expected.AirportId != actual.AirportId
                || expected.Length != actual.Length
                || expected.Width != actual.Width
                || expected.Surface != actual.Surface
                || expected.Lighted != actual.Lighted
                || expected.Closed != actual.Closed
                || expected.End1.Identifier != actual.End1.Identifier
                || expected.End1.Latitude != actual.End1.Latitude
                || expected.End1.Longitude != actual.End1.Longitude
                || expected.End1.Elevation != actual.End1.Elevation
                || expected.End1.DisplacedThreshold != actual.End1.DisplacedThreshold
                || expected.End2.Identifier != actual.End2.Identifier
                || expected.End2.Latitude != actual.End2.Latitude
                || expected.End2.Longitude != actual.End2.Longitude
                || expected.End2.Elevation != actual.End2.Elevation
                || expected.End2.DisplacedThreshold != actual.End2.DisplacedThreshold)
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 3
0
        private IEnumerable <IRunway> ParseRunwayData(Stream data)
        {
            var newRunways = new List <IRunway>(50000);

            using (var sr = new StreamReader(data))
            {
                while (!sr.EndOfStream)
                {
                    try
                    {
                        newRunways.Add(Runway.CreateFromString(sr.ReadLine()));
                    }
                    catch (FormatException)
                    {
                        throw new AirportDirectoryException("Impossible to parse a runway from the database");
                    }
                }
            }

            return(newRunways);
        }
Ejemplo n.º 4
0
        public static IRunway CreateFromString(string s)
        {
            int id, airportId, length, width, threshold;
            double lat, lng, alt;

            var fields = s.Split(',');
            int.TryParse(fields[0], out id);
            int.TryParse(fields[1], out airportId);
            int.TryParse(fields[3], out length);
            int.TryParse(fields[4], out width);

            var result = new Runway()
                {
                    Id = id,
                    AirportId = airportId,
                    Length = length,
                    Width = width,
                    Surface = fields[5].Trim('"'),
                    Lighted = parseBool(fields[6]),
                    Closed = parseBool(fields[7]),
                };

            int.TryParse(fields[12].Trim('"'), out threshold);
            double.TryParse(fields[9].Trim('"'), out lat);
            double.TryParse(fields[10].Trim('"'), out lng);
            double.TryParse(fields[11].Trim('"'), out alt);

            result.End1 = new RunwayEnd()
            {
                Identifier = fields[8].Trim('"'),
                DisplacedThreshold = threshold,
                Position = new BasicGeoposition()
                {
                    Altitude = UnitConverter.FeetToMeters(alt),
                    Latitude = lat,
                    Longitude = lng
                }
            };

            int.TryParse(fields[18].Trim('"'), out threshold);
            double.TryParse(fields[15].Trim('"'), out lat);
            double.TryParse(fields[16].Trim('"'), out lng);
            double.TryParse(fields[17].Trim('"'), out alt);

            result.End2 = new RunwayEnd()
            {
                Identifier = fields[14].Trim('"'),
                DisplacedThreshold = threshold,
                Position = new BasicGeoposition()
                {
                    Altitude = UnitConverter.FeetToMeters(alt),
                    Latitude = lat,
                    Longitude = lng
                }
            };

            return result;
        }