Example #1
0
        public void ParseData(AbstractSectorDataFile data)
        {
            // Loop the lines to get the data out
            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count != 4)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid number of ACTIVE_RUNWAY segments", line)
                        );
                    return;
                }

                if (line.dataSegments[0] != "ACTIVE_RUNWAY")
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Active runway declarations must begin with ACTIVE_RUNWAY", line)
                        );
                    return;
                }

                if (!AirportValidator.IcaoValid(line.dataSegments[1]))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid airport ICAO for Active runway declaration", line)
                        );
                    return;
                }

                if (!RunwayValidator.RunwayValid(line.dataSegments[2]))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid runway designator for Active runway declaration", line)
                        );
                    return;
                }

                if (!int.TryParse(line.dataSegments[3], out int mode) || (mode != 0 && mode != 1))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid mode for Active runway declaration", line)
                        );
                    this.eventLogger.AddEvent(
                        new ParserSuggestion("Valid modes for Active runways are 0 and 1")
                        );
                    return;
                }

                this.elements.Add(
                    new ActiveRunway(
                        line.dataSegments[2],
                        line.dataSegments[1],
                        mode,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }
        /*
         * Parse and valdiate a DEPAPT line
         */
        private SectorArrivalAirports ParseArrivalAirport(SectorData line)
        {
            if (line.dataSegments.Count < 2)
            {
                throw new ArgumentException("Invalid number of ARRAPT segments ");
            }

            List <string> airports = new List <string>();

            for (int i = 1; i < line.dataSegments.Count; i++)
            {
                if (!AirportValidator.IcaoValid(line.dataSegments[i]))
                {
                    throw new ArgumentException("Invalid ICAO code in ARRAPT ");
                }

                airports.Add(line.dataSegments[i]);
            }

            return(new SectorArrivalAirports(
                       airports,
                       line.definition,
                       line.docblock,
                       line.inlineComment
                       ));
        }
        /*
         * Parse and valdiate a GUEST line
         */
        private SectorGuest ParseGuest(SectorData line)
        {
            if (line.dataSegments.Count != 4)
            {
                throw new ArgumentException("Invalid number of GUEST segements ");
            }

            if (!AirportValidator.ValidSectorGuestAirport(line.dataSegments[2]))
            {
                throw new ArgumentException("Invalid departure airport designator in GUEST segement");
            }

            if (!AirportValidator.ValidSectorGuestAirport(line.dataSegments[3]))
            {
                throw new ArgumentException("Invalid arrival airport designator in GUEST segement ");
            }

            return(new SectorGuest(
                       line.dataSegments[1],
                       line.dataSegments[2],
                       line.dataSegments[3],
                       line.definition,
                       line.docblock,
                       line.inlineComment
                       ));
        }
        /*
         * Parse and valdiate a ACTIVE line
         */
        private SectorActive ParseActive(SectorData line)
        {
            if (line.dataSegments.Count != 3)
            {
                throw new ArgumentException("Invalid number of ACTIVE segements ");
            }

            if (!AirportValidator.ValidEuroscopeAirport(line.dataSegments[1]))
            {
                throw new ArgumentException("Invalid airport designator in ACTIVE segement ");
            }

            if (!RunwayValidator.RunwayValidIncludingAdjacent(line.dataSegments[2]))
            {
                throw new ArgumentException("Invalid runway designator in ACTIVE segement ");
            }

            return(new SectorActive(
                       line.dataSegments[1],
                       line.dataSegments[2],
                       line.definition,
                       line.docblock,
                       line.inlineComment
                       ));
        }
        private InfoAirport GetAirport(SectorData line)
        {
            if (!AirportValidator.IcaoValid(line.rawData))
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid INFO airport", line)
                    );
                throw new ArgumentNullException();
            }

            return(new InfoAirport(line.rawData, line.definition, line.docblock, line.inlineComment));
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            // Validate the folder name
            if (!AirportValidator.ValidEuroscopeAirport(data.GetParentDirectoryName()))
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid airport ICAO", data.FullPath)
                    );
                return;
            }

            int linesParsed = 0;

            SectorData nameLine       = new SectorData();
            SectorData coordinateLine = new SectorData();
            SectorData frequencyLine  = new SectorData();


            // Loop the lines to get the data out
            foreach (SectorData line in data)
            {
                if (linesParsed == 0)
                {
                    nameLine = line;
                    linesParsed++;
                    continue;
                }
                else if (linesParsed == 1)
                {
                    coordinateLine = line;
                    linesParsed++;
                    continue;
                }
                else if (linesParsed == 2)
                {
                    frequencyLine = line;
                    linesParsed++;
                    continue;
                }

                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid number of airport lines", line)
                    );
                return;
            }

            // Check the syntax
            if (linesParsed != 3)
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid number of airport lines", data.FullPath)
                    );
                return;
            }

            // Parse the coordinate
            if (coordinateLine.dataSegments.Count != 2)
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid coordinate format for airport: " + coordinateLine.rawData, coordinateLine)
                    );
                return;
            }

            Coordinate parsedCoordinate = CoordinateParser.Parse(coordinateLine.dataSegments[0], coordinateLine.dataSegments[1]);

            if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate))
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid coordinate format for airport: " + coordinateLine.rawData, coordinateLine)
                    );
                return;
            }

            this.elements.Add(
                new Airport(
                    nameLine.rawData,
                    data.GetParentDirectoryName(),
                    parsedCoordinate,
                    frequencyLine.rawData,
                    nameLine.definition,
                    nameLine.docblock,
                    nameLine.inlineComment
                    )
                );
        }
 public void TestValidationSuccessSectorGuest(string input)
 {
     Assert.True(AirportValidator.ValidSectorGuestAirport(input));
 }
 public void TestValidationFailureSectorGuest(string input)
 {
     Assert.False(AirportValidator.ValidSectorGuestAirport(input));
 }
 public void TestValidationSuccessEuroscope(string input)
 {
     Assert.True(AirportValidator.ValidEuroscopeAirport(input));
 }
 public void TestValidationFailureEuroscope(string input)
 {
     Assert.False(AirportValidator.ValidEuroscopeAirport(input));
 }
 public void TestValidationSuccessIcaoCode(string input)
 {
     Assert.True(AirportValidator.IcaoValid(input));
 }
 public void TestValidationFailureIcaoCode(string input)
 {
     Assert.False(AirportValidator.IcaoValid(input));
 }
 public AirportShould()
 {
     //Arrange
     _validator = new AirportValidator();
 }