コード例 #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
                        )
                    );
            }
        }
コード例 #2
0
        /*
         * 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
                       ));
        }
コード例 #3
0
        private GroundNetworkRunwayExit ProcessExit(AbstractSectorDataFile file, List <SectorData> lines)
        {
            SectorData declarationLine = lines[0];

            if (declarationLine.dataSegments.Count != 5)
            {
                errorLog.AddEvent(
                    new SyntaxError("Invalid number of EXIT declaration segments", declarationLine)
                    );
                throw new ArgumentException();
            }

            if (!RunwayValidator.RunwayValid(declarationLine.dataSegments[1]))
            {
                errorLog.AddEvent(
                    new SyntaxError("Invalid runway in EXIT declaration", declarationLine)
                    );
                throw new ArgumentException();
            }

            if (declarationLine.dataSegments[3] != "LEFT" && declarationLine.dataSegments[3] != "RIGHT")
            {
                errorLog.AddEvent(
                    new SyntaxError(
                        "Invalid exit direction in EXIT declaration, must be LEFT or RIGHT",
                        declarationLine
                        )
                    );
                throw new ArgumentException();
            }

            if (
                !int.TryParse(declarationLine.dataSegments[4], out int maximumSpeed) ||
                maximumSpeed < 1
                )
            {
                errorLog.AddEvent(
                    new SyntaxError("Invalid maximum speed in EXIT declaration", declarationLine)
                    );
                throw new ArgumentException();
            }

            return(new GroundNetworkRunwayExit(
                       declarationLine.dataSegments[1],
                       declarationLine.dataSegments[2],
                       declarationLine.dataSegments[3],
                       maximumSpeed,
                       ProcessCoordinates(file, lines.GetRange(1, lines.Count - 1), ExitDeclaration),
                       declarationLine.definition,
                       declarationLine.docblock,
                       declarationLine.inlineComment
                       ));
        }
コード例 #4
0
 public void TestValidationSuccessWithAdjacent(string input)
 {
     Assert.True(RunwayValidator.RunwayValidIncludingAdjacent(input));
 }
コード例 #5
0
 public void TestValidationFailureWithAdjacent(string input)
 {
     Assert.False(RunwayValidator.RunwayValidIncludingAdjacent(input));
 }
コード例 #6
0
 public void TestValidationSuccess(string input)
 {
     Assert.True(RunwayValidator.RunwayValid(input));
 }
コード例 #7
0
 public void TestValidationFailure(string input)
 {
     Assert.False(RunwayValidator.RunwayValid(input));
 }
コード例 #8
0
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                // Runways are weird and have double spaces randomly, so handle it.
                if (line.dataSegments.Count < 8)
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Too few RUNWAY segments", line)
                        );
                    continue;
                }

                // Check the two identifiers
                if (!RunwayValidator.RunwayValidIncludingAdjacent(line.dataSegments[0]))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid runway designator " + line.dataSegments[0], line)
                        );
                    continue;
                }

                if (!RunwayValidator.RunwayValidIncludingAdjacent(line.dataSegments[1]))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid runway designator " + line.dataSegments[1], line)
                        );
                    continue;
                }

                // Check the two headings
                if (!this.HeadingIsValid(line.dataSegments[2]))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid runway heading " + line.dataSegments[2], line)
                        );
                    continue;
                }

                if (!this.HeadingIsValid(line.dataSegments[3]))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid runway heading " + line.dataSegments[3], line)
                        );
                    continue;
                }

                // Check the two coordinates
                Coordinate firstThreshold = CoordinateParser.Parse(line.dataSegments[4], line.dataSegments[5]);
                if (firstThreshold.Equals(CoordinateParser.InvalidCoordinate))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid runway first threshold ", line)
                        );
                    continue;
                }

                Coordinate reverseThreshold = CoordinateParser.Parse(line.dataSegments[6], line.dataSegments[7]);
                if (reverseThreshold.Equals(CoordinateParser.InvalidCoordinate))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid runway reverse threshold ", line)
                        );
                    continue;
                }

                // Compile together the airfield description
                if (line.dataSegments.Count > 8)
                {
                    string.Join(
                        " ",
                        line.dataSegments
                        .Skip(8)
                        .Take(line.dataSegments.Count - 8)
                        .ToList()
                        );
                }


                // Add the element
                this.sectorElements.Add(
                    new Runway(
                        data.GetParentDirectoryName(),
                        line.dataSegments[0],
                        int.Parse(line.dataSegments[2]),
                        firstThreshold,
                        line.dataSegments[1],
                        int.Parse(line.dataSegments[3]),
                        reverseThreshold,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }