コード例 #1
0
        public void ParseAiracPeriodCrossYear()
        {
            var p = AiracTools.ParsePeriod("08DEC05JAN/16");
            var s = p.Start;
            var e = p.End;

            Assert.IsTrue(s.Year == 2016 && s.Month == 12 && s.Day == 8);
            Assert.IsTrue(e.Year == 2017 && e.Month == 1 && e.Day == 5);
        }
コード例 #2
0
        public void ParseAiracPeriodTest()
        {
            var p = AiracTools.ParsePeriod("26JUN23JUL/14");
            var s = p.Start;
            var e = p.End;

            Assert.IsTrue(s.Year == 2014 && s.Month == 6 && s.Day == 26);
            Assert.IsTrue(e.Year == 2014 && e.Month == 7 && e.Day == 23);
        }
コード例 #3
0
        private void DisplayNavDataStatus(string navDataPath)
        {
            // This section is to determine whether the database
            // files are found or not.
            string[] FilesToCheck =
            {
                "airports.txt",
                "ats.txt",
                "cycle.txt",
                "navaids.txt",
                "waypoints.txt"
            };

            bool navDataFound = FilesToCheck.All(i =>
                                                 File.Exists(Path.Combine(navDataPath, i)));

            navDataStatusLbl.Text = navDataFound ? "Found" : "Not Found";

            try
            {
                var t = AiracTools.AiracCyclePeriod(navDataPath);
                airacLbl.Text       = t.Cycle;
                airacPeriodLbl.Text = t.PeriodText;

                bool expired = !t.IsWithinValidPeriod;

                if (expired)
                {
                    airacPeriodLbl.Text     += "  (Expired)";
                    airacPeriodLbl.ForeColor = Color.Red;
                    airacLbl.ForeColor       = Color.Red;
                }
                else
                {
                    airacPeriodLbl.Text     += "  (Within Valid Period)";
                    airacPeriodLbl.ForeColor = Color.Green;
                    airacLbl.ForeColor       = Color.Green;
                }
            }
            catch (Exception ex)
            {
                Log(ex);

                navDataStatusLbl.Text = "Failed to load";
                airacLbl.Text         = "N/A";
                airacPeriodLbl.Text   = "N/A";
                airacPeriodLbl.Text   = "";
            }
        }
コード例 #4
0
        /// <summary>
        /// If no valid AIRAC is detected, returns null. This method does not throw exception.
        /// </summary>
        public static AiracInfo DetectNavDataPath()
        {
            var paths = SimulatorPaths()
                        .Where(p => p != null)
                        .SelectMany(p => new[] { GetNavDataProPath(p), GetNavigraphPath(p) });

            var airacs = paths.Select(d => new AiracInfo()
            {
                Directory = d,
                Period    = AiracTools.TryGetAiracCyclePeriod(d)
            }).Where(a => a.Period != null).ToList();

            if (!airacs.Any())
            {
                return(null);
            }

            // Choose the latest airac cycle.
            return(airacs.MaxBy(a => a.Period.Period.End));
        }
コード例 #5
0
        /// <summary>
        /// Get string of the flight plan to export.
        /// </summary>
        /// <exception cref="Exception"></exception>
        public static string GetExportText(ExportInput input)
        {
            var(route, navaids, wptList) = (input.Route, input.Navaids, input.Waypoints);
            if (route.Count < 2)
            {
                throw new ArgumentException();
            }
            var from        = route.FirstWaypoint;
            var navdatapath = OptionManager.ReadFromFile().NavDataLocation;
            var cycle       = AiracTools.AiracCyclePeriod(navdatapath);
            var to          = route.LastWaypoint;
            var s           = @"I
1100 Version
CYCLE " + cycle.Cycle;

            s += "\r\nADEP " + from.ID.Substring(0, 4);
            s += "\r\nDEPRWY RW" + from.ID.Substring(4);
            var sid = route.First.Value.AirwayToNext.Airway;

            if (sid != "DCT")
            {
                var sidtrans = sid.Split('.');

                s += "\r\nSID " + sidtrans[0];

                if (sidtrans.Length > 1)
                {
                    s += "\r\nSIDTRANS " + sidtrans[1];
                }
            }

            s += "\r\nADES " + to.ID.Substring(0, 4);
            s += "\r\nDESRWY RW" + to.ID.Substring(4);
            var star = route.Last.Previous.Value.AirwayToNext.Airway;

            if (star != "DCT")
            {
                var startrans = star.Split('.');

                s += "\r\nSTAR " + startrans[0];

                if (startrans.Length > 1)
                {
                    s += "\r\nSTARTRANS " + startrans[1];
                }
            }

            s += "\r\nNUMENR " + (route.Count);


            var firstLine   = GetLine(from.ID.Substring(0, 4), "ADEP", from, 1);
            var lastLine    = GetLine(to.ID.Substring(0, 4), "ADES", to, 1);
            var middleLines = route.WithoutFirstAndLast().Select(n =>
            {
                var w      = n.Waypoint;
                var a      = n.AirwayToNext.Airway;
                var id     = w.ID;
                var navaid = navaids.Find(id, w);
                if (navaid != null && navaid.IsVOR)
                {
                    return(GetLine(id, a, w, 3));
                }
                if (navaid != null && navaid.IsNDB)
                {
                    return(GetLine(id, a, w, 2));
                }

                var coordinate = id.ParseLatLon();
                if (coordinate == null || Format5Letter.Parse(w.ID) != null)
                {
                    return(GetLine(id, a, w, 11));
                }

                return(GetLine(coordinate.FormatLatLon(), a, w, 28));
            });

            var lines = List(s, firstLine)
                        .Concat(middleLines)
                        .Concat(lastLine)
                        .Concat("");

            return(string.Join("\n", lines));
        }
コード例 #6
0
 public void IncorrectAiracFormatShouldThrowException()
 {
     Assert.Throws <ArgumentException>(() => AiracTools.ParsePeriod("6JUN23JUL/14"));
 }