Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length == 4)
            {
                defargs = args;
            }
            else
            {
                if (args.Length != 0)
                {
                    Console.WriteLine("Incorrect number of arguments.");
                }

                Console.WriteLine("To run quickly from command prompt, give your arguments like this:\n<airports file path> <.sct file path> <.ese file path> <fir code>\n");

                defargs = new string[4];

                Console.WriteLine("Enter airports file path:");
                defargs[0] = Console.ReadLine();

                Console.WriteLine("Enter .sct file path:");
                defargs[1] = Console.ReadLine();

                Console.WriteLine("Enter .ese file path:");
                defargs[2] = Console.ReadLine();

                Console.WriteLine("Enter fir code:");
                defargs[3] = Console.ReadLine();
            }


            bool isValid = true;

            if (isValid)
            {
                try
                {
                    Airport.Load(defargs[0]);

                    Runway.list     = new List <Runway>();
                    SectorLine.list = new List <SectorLine>();
                    Sector.list     = new List <Sector>();
                    Airspace.list   = new List <Airspace>();
                    Controller.list = new List <Controller>();
                }
                catch (Exception ex)
                {
                    isValid = false;
                    Console.WriteLine("Error in airports file:\n" + ex);
                    Console.ReadLine();
                }
            }

            if (isValid)
            {
                try
                {
                    ReadSCT(defargs[1]);
                }
                catch (Exception ex)
                {
                    isValid = false;
                    Console.WriteLine("Error in .sct file:\n" + ex);
                    Console.ReadLine();
                }
            }

            if (isValid)
            {
                try
                {
                    ReadESE(defargs[2]);
                }
                catch (Exception ex)
                {
                    isValid = false;
                    Console.WriteLine("Error in .ese file:\n" + ex);
                    Console.ReadLine();
                }
            }

            if (isValid)
            {
                try
                {
                    ParseAirspaces();
                }
                catch (Exception ex)
                {
                    isValid = false;
                    Console.WriteLine("Error while parsing airspace layouts:\n" + ex);
                    Console.ReadLine();
                }
            }

            if (isValid)
            {
                try
                {
                    Write(defargs[3]);
                }
                catch (Exception ex)
                {
                    isValid = false;
                    Console.WriteLine("Error while writing to output files:\n" + ex);
                    Console.ReadLine();
                }
            }
        }
Ejemplo n.º 2
0
        static void ReadESE(string _file)
        {
            List <PolyLine> deferred    = new List <PolyLine>();
            bool            isPositions = false;
            bool            isAirspace  = false;
            bool            isPolyLine  = false;
            bool            isSector    = false;

            using (FileStream fs = File.Open(_file, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (BufferedStream bs = new BufferedStream(fs))
                    using (StreamReader sr = new StreamReader(bs))
                    {
                        string raw;
                        while ((raw = sr.ReadLine()) != null)
                        {
                            string live = raw.Split(';')[0];
                            live = live.Replace('\t', ' ');

                            if (raw.Length != 0 && raw.First() != ';')
                            {
                                if (raw.First() == '[')
                                {
                                    isPositions = false;
                                    isAirspace  = false;

                                    if (raw.ToUpper() == @"[POSITIONS]")
                                    {
                                        isPositions = true;
                                    }
                                    else if (raw.ToUpper() == @"[AIRSPACE]")
                                    {
                                        isAirspace = true;
                                    }
                                }
                                else if (isPositions)
                                {
                                    Controller.Add(live.Split(':'));
                                }
                                else if (isAirspace)
                                {
                                    if (raw.StartsWith("CIRCLE_SECTORLINE:"))
                                    {
                                        isPolyLine = false;
                                        isSector   = false;

                                        SectorLine.list.Add(new CircleLine(live.Split(':')));
                                    }
                                    else if (raw.StartsWith("SECTORLINE:"))
                                    {
                                        isPolyLine = true;
                                        isSector   = false;

                                        SectorLine.list.Add(new PolyLine(live.Split(':')));
                                    }
                                    else if (raw.StartsWith("SECTOR:"))
                                    {
                                        isPolyLine = false;
                                        isSector   = true;
                                        deferred   = new List <PolyLine>();

                                        if (Controller.listSorted == null)
                                        {
                                            Controller.listSorted = Controller.Sort(Controller.list);
                                        }

                                        string[] liveparts = live.Split(':');

                                        Sector.list.Add(new Sector(liveparts));
                                    }
                                    //else if (isCircleLine)
                                    //{

                                    //}
                                    else if (isPolyLine)
                                    {
                                        if (raw.StartsWith("COORD:"))
                                        {
                                            ((PolyLine)SectorLine.list.Last()).AddPoint(live.Split(':'));
                                        }
                                    }
                                    else if (isSector)
                                    {
                                        if (raw.StartsWith("OWNER:"))
                                        {
                                            string[] split = live.Split(':');

                                            for (int i = 1; i < split.Length; i++)
                                            {
                                                string part = split[i];

                                                if (part != "")
                                                {
                                                    foreach (Controller ctl in Controller.Find(part))
                                                    {
                                                        Sector.list.Last().owners.Add(ctl);
                                                    }
                                                }
                                            }
                                        }
                                        else if (raw.StartsWith("ACTIVE:"))
                                        {
                                            string[] split = live.Split(':');

                                            Airport apTemp = Airport.Find(split[1]);

                                            if (apTemp != null)
                                            {
                                                Sector.list.Last().runways.Add(Runway.Find(apTemp.ID, split[2]));
                                            }
                                        }
                                        else if (raw.StartsWith("BORDER:"))
                                        {
                                            string[] split = live.Split(':');

                                            for (int i = 1; i < split.Length; i++)
                                            {
                                                string     part = split[i];
                                                SectorLine line = SectorLine.Find(part);
                                                Sector     last = Sector.list.Last();

                                                if (line != null && line is PolyLine)
                                                {
                                                    PolyLine poly = new PolyLine((PolyLine)line);

                                                    if (last.lines.Count == 0)
                                                    {
                                                        last.lines.Add(poly);
                                                    }
                                                    else
                                                    {
                                                        if (poly.points[0].SequenceEqual(((PolyLine)last.lines.Last()).points.Last()))
                                                        {
                                                            last.lines.Add(poly);
                                                        }
                                                        else if (poly.points.Last().SequenceEqual(((PolyLine)last.lines.Last()).points.Last()))
                                                        {
                                                            poly.points.Reverse();
                                                            last.lines.Add(poly);
                                                        }
                                                        else if (poly.points[0].SequenceEqual(((PolyLine)last.lines[0]).points[0]))
                                                        {
                                                            poly.points.Reverse();
                                                            last.lines.Insert(0, poly);
                                                        }
                                                        else if (poly.points.Last().SequenceEqual(((PolyLine)last.lines[0]).points[0]))
                                                        {
                                                            last.lines.Insert(0, poly);
                                                        }
                                                        else
                                                        {
                                                            deferred.Add(poly);
                                                        }
                                                    }

                                                    bool isChanged = true;
                                                    while (deferred.Count > 0 && isChanged)
                                                    {
                                                        isChanged = false;

                                                        for (int j = deferred.Count - 1; j >= 0; j--)
                                                        {
                                                            PolyLine plyPly = deferred[j];

                                                            if (plyPly.points[0].SequenceEqual(((PolyLine)last.lines.Last()).points.Last()))
                                                            {
                                                                last.lines.Add(plyPly);
                                                                deferred.RemoveAt(j);
                                                                isChanged = true;
                                                            }
                                                            else if (plyPly.points.Last().SequenceEqual(((PolyLine)last.lines.Last()).points.Last()))
                                                            {
                                                                plyPly.points.Reverse();
                                                                last.lines.Add(plyPly);
                                                                deferred.RemoveAt(j);
                                                                isChanged = true;
                                                            }
                                                            else if (plyPly.points[0].SequenceEqual(((PolyLine)last.lines[0]).points[0]))
                                                            {
                                                                plyPly.points.Reverse();
                                                                last.lines.Insert(0, plyPly);
                                                                deferred.RemoveAt(j);
                                                                isChanged = true;
                                                            }
                                                            else if (plyPly.points.Last().SequenceEqual(((PolyLine)last.lines[0]).points[0]))
                                                            {
                                                                last.lines.Insert(0, plyPly);
                                                                deferred.RemoveAt(j);
                                                                isChanged = true;
                                                            }
                                                        }
                                                    }
                                                }
                                                else if (line is CircleLine)
                                                {
                                                    Sector.list.Last().lines.Add(line);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
        }
Ejemplo n.º 3
0
        static void ReadSCT(string _file)
        {
            //bool isAirport = false;
            bool isRunway = false;

            using (FileStream fs = File.Open(_file, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (BufferedStream bs = new BufferedStream(fs))
                    using (StreamReader sr = new StreamReader(bs))
                    {
                        string raw;
                        while ((raw = sr.ReadLine()) != null)
                        {
                            if (raw.Length != 0 && raw.First() != ';')
                            {
                                if (raw.First() == '[')
                                {
                                    //isAirport = false;
                                    isRunway = false;

                                    //if (raw.ToUpper() == @"[AIRPORT]")
                                    //{
                                    //    isAirport = true;
                                    //}
                                    if (raw.ToUpper() == @"[RUNWAY]")
                                    {
                                        isRunway = true;
                                    }
                                }
                                //else if (isAirport)
                                //{
                                //    string live = raw.Split(';')[0];
                                //    string[] split = live.Split(' ');
                                //    string sanitised = "";

                                //    foreach (string part in split)
                                //    {
                                //        if (part != "")
                                //        {
                                //            sanitised += part + ",";
                                //        }
                                //    }

                                //    if (sanitised.Length > 0)
                                //    {
                                //        sanitised = sanitised.Substring(0, sanitised.Length - 2);
                                //    }

                                //    string[] result = sanitised.Split(',');
                                //}
                                else if (isRunway)
                                {
                                    string live = raw.Split(';')[0];
                                    live = live.Replace('\t', ' ');
                                    string[] split     = live.Split(' ');
                                    string   sanitised = "";

                                    foreach (string part in split)
                                    {
                                        if (part != "")
                                        {
                                            sanitised += part + ",";
                                        }
                                    }

                                    if (sanitised.Length > 0)
                                    {
                                        sanitised = sanitised.Substring(0, sanitised.Length - 1);
                                    }

                                    string[] result = sanitised.Split(',');

                                    Airport location = Airport.Find(result[8]);
                                    if (location != null)
                                    {
                                        Runway.list.Add(new Runway(location.ID, result[0]));
                                        Runway.list.Add(new Runway(location.ID, result[1]));
                                    }
                                }
                            }
                        }
                    }
        }