Exemplo n.º 1
0
        private void BtnSearch_Click(object sender, EventArgs e)
        {
            tlpRunways.Controls.Clear();
            tlpRunways.RowCount = 0;

            if (TxtSearch.Text != "")
            {
                apCurrent = Airport.FindICAO(TxtSearch.Text);
                if (apCurrent == null)
                {
                    MessageBox.Show("Airport not found.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    int intSize = tlpRunways.Height;
                    listActive = new List <Runway>(apCurrent.listRunways);

                    foreach (Runway rwyRwy in apCurrent.listRunways)
                    {
                        if (rwyRwy != null)
                        {
                            tlpRunways.RowStyles.Add(new RowStyle(SizeType.Absolute, 23));

                            //
                            // LblRunway
                            //
                            Label LblRunway = new Label();
                            LblRunway.ForeColor = cp.Text;
                            tlpRunways.Controls.Add(LblRunway, 0, tlpRunways.RowCount - 1);
                            LblRunway.AutoSize  = true;
                            LblRunway.Dock      = DockStyle.Fill;
                            LblRunway.Location  = new Point(3, 0);
                            LblRunway.Name      = "LblRunway";
                            LblRunway.Size      = new Size(35, 23);
                            LblRunway.Text      = rwyRwy.strRunway;
                            LblRunway.TextAlign = ContentAlignment.MiddleRight;

                            //
                            // chkActive
                            //
                            CheckBox chkActive = new CheckBox();
                            chkActive.BackColor = cp.Window;
                            chkActive.ForeColor = cp.Text;
                            tlpRunways.Controls.Add(chkActive, 1, tlpRunways.RowCount - 1);
                            chkActive.AutoSize = true;
                            chkActive.Dock     = DockStyle.Fill;
                            chkActive.Location = new Point(201, 3);
                            chkActive.Name     = "chkActive";
                            chkActive.Size     = new Size(15, 13);
                            chkActive.UseVisualStyleBackColor = true;
                            chkActive.Tag = rwyRwy;

                            if (apCurrent.listActive.Contains(rwyRwy))
                            {
                                chkActive.Checked = true;
                            }

                            tlpRunways.RowCount++;
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Please enter an ICAO airport code.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 2
0
        public void Pull()
        {
            foreach (Airport apAp in Airport.listSorted)
            {
                apAp.Reset();
            }

            Client.Reset();
            Pilot.Reset();
            FPlan.ResetPrefiles();
            ATC.Reset();
            ATC.ResetOBS();
            Server.Reset();

            int intCurrent = 0;

            Random rndTemp  = new Random();
            int    intIndex = rndTemp.Next(0, listFull.Count - 1);

            WebClient wcTemp = new WebClient();
            string    strRaw = wcTemp.DownloadString(listFull[intIndex]);

            foreach (string strStr in strRaw.Split(new string[] { "\n" }, StringSplitOptions.None))
            {
                if (strStr.Length != 0 && strStr[0] != ';')
                {
                    if (strStr[0] == '!')
                    {
                        switch (strStr.Substring(1, 7))
                        {
                        case "GENERAL":
                            intCurrent = 1;
                            break;

                        case "CLIENTS":
                            intCurrent = 2;
                            break;

                        case "SERVERS":
                            intCurrent = 3;
                            break;

                        case "PREFILE":
                            intCurrent = 4;
                            break;
                        }
                    }
                    else
                    {
                        string[] strarrTemp;
                        switch (intCurrent)
                        {
                        case 1:
                            strarrTemp = Regex.Replace(strStr, @"\s+", "").Split('=');
                            switch (strarrTemp[0])
                            {
                            case "VERSION":
                                intVersion = int.Parse(strarrTemp[1], DataCulture);

                                //if (intVersion != Properties.Settings.Default.DataVersion)
                                //{
                                //MessageBox.Show("This version of VATGlasses was designed for an old version of the VATSIM.net Status API. Please update to the latest version. If this is currently the latest version, please submit a bug report at our website.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                //Environment.Exit(0);
                                //}

                                break;

                            case "RELOAD":
                                decReload = decimal.Parse(strarrTemp[1], DataCulture);
                                break;

                            case "UPDATE":
                                dtUpdate = new DateTime(int.Parse(strarrTemp[1].Substring(0, 4), DataCulture), int.Parse(strarrTemp[1].Substring(4, 2), DataCulture), int.Parse(strarrTemp[1].Substring(6, 2), DataCulture), int.Parse(strarrTemp[1].Substring(8, 2), DataCulture), int.Parse(strarrTemp[1].Substring(10, 2), DataCulture), int.Parse(strarrTemp[1].Substring(12, 2), DataCulture));
                                break;

                            case "CONNECTEDCLIENTS":
                                intConnected = int.Parse(strarrTemp[1], DataCulture);
                                break;

                            default:
                                break;
                            }
                            break;

                        case 2:
                            strarrTemp = strStr.Split(':');
                            Client cltTemp = null;

                            if (strarrTemp[3] == "PILOT")
                            {
                                cltTemp = new Pilot(strarrTemp);
                                Pilot.Add((Pilot)cltTemp);
                            }
                            else if (strarrTemp[3] == "ATC")
                            {
                                if (isATC(strarrTemp[0], strarrTemp[18]))
                                {
                                    cltTemp = ATC.Add(strarrTemp, false);
                                }
                                else
                                {
                                    cltTemp = ATC.Add(strarrTemp, true);
                                }
                            }

                            int intCID = -1;
                            int.TryParse(strarrTemp[1], NumberStyles.None, DataCulture, out intCID);

                            //if (Client.listFavCSs.Contains(strarrTemp[0]) && Client.listFavCIDs.Contains(intCID))
                            //{
                            //    Client.listFavs.Add(new FavClient(cltTemp, cltTemp.strCallsign, intCID));
                            //}
                            //else if (Client.listFavCSs.Contains(strarrTemp[0]))
                            //{
                            //    Client.listFavs.Add(new FavClient(cltTemp, cltTemp.strCallsign, null));
                            //}
                            //else if (Client.listFavCIDs.Contains(intCID))
                            //{
                            //    Client.listFavs.Add(new FavClient(cltTemp, null, intCID));
                            //}
                            break;

                        case 3:
                            Server.Add(new Server(strStr.Split(':')));
                            break;

                        case 4:
                            FPlan.AddPrefile(new FPlan(strStr.Split(':')));
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            Pilot.SortList();
            ATC.SortList();
            Controller.AssignAll();
            Airport.AssignTopDown();
            Client.UpdateFavs();
        }
Exemplo n.º 3
0
        public static void LoadFiles()
        {
            if (!Directory.Exists(strDataDirectory))
            {
                Directory.CreateDirectory(strDataDirectory);
            }

            if (!Directory.Exists(strPrefsDirectory))
            {
                Directory.CreateDirectory(strPrefsDirectory);
            }

            List <Task> listStandaloneTasks = new List <Task>();

            listStandaloneTasks.Add(Country.Load(Country.strDataFile));
            listStandaloneTasks.Add(FIR.Load(FIR.strDataFile));

            Task tskFavs = Client.LoadFavs();

            string[] strarrDirectories = Directory.GetDirectories(strDataDirectory);

            for (int i = 0; i < strarrDirectories.Length; i++)
            {
                strarrDirectories[i] = strarrDirectories[i].Split('\\').Last();
            }

            Controller.list = new List <Controller>();
            List <Task> listControllerTasks = new List <Task>();

            foreach (string strStr in strarrDirectories)
            {
                listControllerTasks.Add(Controller.Load(strStr));
            }

            Task.WaitAll(listControllerTasks.ToArray());
            Controller.SortAsync().Wait();

            Task.WaitAll(listStandaloneTasks.ToArray());

            Airport.Load(Airport.strDataFile, Airport.strFavFile).Wait();

            Runway.list = new List <Runway>();
            List <Task> listRunwayTasks = new List <Task>();

            foreach (string strStr in strarrDirectories)
            {
                listRunwayTasks.Add(Runway.Load(strStr));
            }

            Task.WaitAll(listRunwayTasks.ToArray());

            Runway.listSorted = Runway.Sort(Runway.list);
            Runway.LoadCurrents(Runway.strCurrentFile);

            Sector.list = new List <Sector>();
            List <Task> listSectorTasks = new List <Task>();

            foreach (string strStr in strarrDirectories)
            {
                listSectorTasks.Add(Sector.Load(strStr));
            }

            Task.WaitAll(listSectorTasks.ToArray());
            Sector.SortAsync().Wait();

            Airspace.list = new List <Airspace>();
            List <Task> listAirspaceTasks = new List <Task>();

            foreach (string strStr in strarrDirectories)
            {
                listAirspaceTasks.Add(Airspace.Load(strStr));
            }

            Task.WaitAll(listAirspaceTasks.ToArray());
            Airspace.listSorted = Airspace.Sort(Airspace.list);

            Task.WaitAll(tskFavs);
        }
Exemplo n.º 4
0
        public ATC(string[] _data, bool _obs) : base(_data)
        {
            if (decimal.TryParse(_data[4], NumberStyles.Float, DataLink.DataCulture, out decimal decTemp))
            {
                decFreq = decTemp;
            }
            else
            {
                decFreq = 0;
            }

            if (double.TryParse(_data[5], NumberStyles.Float, DataLink.DataCulture, out double dblTemp))
            {
                dblLat = dblTemp;
            }
            else
            {
                dblLat = 0;
            }

            if (double.TryParse(_data[6], NumberStyles.Float, DataLink.DataCulture, out dblTemp))
            {
                dblLon = dblTemp;
            }
            else
            {
                dblLon = 0;
            }

            strServer = _data[14];

            if (int.TryParse(_data[16], NumberStyles.Integer, DataLink.DataCulture, out int intTemp) && intTemp > 0 && intTemp < 13)
            {
                intRating = intTemp;
            }
            else
            {
                intRating = 1;
            }

            if (_data[0].Split('_').Last() == "ATIS")
            {
                intFacility = 7;
            }
            else
            {
                if (int.TryParse(_data[18], NumberStyles.Integer, DataLink.DataCulture, out intTemp))
                {
                    intFacility = intTemp;
                }
                else
                {
                    intFacility = 1;
                }
            }

            if (int.TryParse(_data[19], NumberStyles.Integer, DataLink.DataCulture, out intTemp))
            {
                intVisibility = intTemp;
            }
            else
            {
                intVisibility = 0;
            }

            strATIS = FormatATIS(_data[35]);

            try
            {
                dtLogon = new DateTime(int.Parse(_data[37].Substring(0, 4), DataLink.DataCulture), int.Parse(_data[37].Substring(4, 2), DataLink.DataCulture), int.Parse(_data[37].Substring(6, 2), DataLink.DataCulture), int.Parse(_data[37].Substring(8, 2), DataLink.DataCulture), int.Parse(_data[37].Substring(10, 2), DataLink.DataCulture), int.Parse(_data[37].Substring(12, 2), DataLink.DataCulture));
            }
            catch
            {
                dtLogon = new DateTime(1918, 4, 1);
            }

            if (intFacility == 7 || (intFacility >= 2 && intFacility <= 4))
            {
                Airport apTemp = Airport.FindWithAlias(strCallsign.Split('_')[0]);

                if (apTemp != null && decFreq != (decimal)199.998)
                {
                    if (intFacility == 2)
                    {
                        apTemp.AddDelivery(this);
                    }
                    else if (intFacility == 3)
                    {
                        apTemp.AddGround(this);
                    }
                    else if (intFacility == 4)
                    {
                        apTemp.AddTower(this);
                    }
                    else if (intFacility == 7)
                    {
                        apTemp.AddATIS(this);
                    }
                }
            }

            isObs = _obs;
        }
Exemplo n.º 5
0
        public static async Task Load(string _filename, string _favourites)
        {
            list       = new List <Airport>();
            listAlias  = new List <Airport>();
            listSorted = new List <Airport>();
            listFavs   = new List <Airport>();

            using (FileStream fs = File.Open(_filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (BufferedStream bs = new BufferedStream(fs))
                    using (StreamReader sr = new StreamReader(bs))
                    {
                        string strRaw;
                        while ((strRaw = sr.ReadLine()) != null)
                        {
                            if (strRaw.First() != ';')
                            {
                                string[] strarrCommented = strRaw.Split(';');
                                strRaw = strarrCommented[0];

                                string[] strarrSplit = strRaw.Split('|');

                                if (strarrSplit.Length >= 9)
                                {
                                    Airport apTemp = new Airport(strarrSplit);
                                    list.Add(apTemp);

                                    if (apTemp.strarrAlias.Length != 0)
                                    {
                                        listAlias.Add(apTemp);
                                    }
                                }
                                else
                                {
                                    Console.WriteLine(strRaw);
                                    throw new ArgumentOutOfRangeException("Each line in the file must contain at least nine entries, separated by a '|'");
                                }
                            }
                        }
                    }

            FileStream fsfav;

            if (!Directory.Exists(DataLink.strPrefsDirectory))
            {
                Directory.CreateDirectory(DataLink.strPrefsDirectory);
            }

            if (!File.Exists(_favourites))
            {
                fsfav = File.Create(_favourites);
            }
            else
            {
                fsfav = File.Open(_favourites, FileMode.Open, FileAccess.Read, FileShare.Read);
            }

            using (BufferedStream bs = new BufferedStream(fsfav))
                using (StreamReader sr = new StreamReader(bs))
                {
                    string strRaw;
                    while ((strRaw = sr.ReadLine()) != null)
                    {
                        if (strRaw.Length > 0 && strRaw.First() != ';')
                        {
                            string[] strarrCommented = strRaw.Split(';');
                            strRaw = strarrCommented[0];

                            int intIndex = -1;

                            int.TryParse(strRaw, NumberStyles.None, DataLink.DataCulture, out intIndex);

                            if (intIndex != -1)
                            {
                                listFavs.Add(FindID(intIndex));
                            }
                        }
                    }
                }

            fsfav.Close();

            listSorted = Sort(list);
        }
Exemplo n.º 6
0
        public FPlan(string[] _data) : base(_data)
        {
            strAircraft = _data[9];

            if (decimal.TryParse(_data[10], NumberStyles.Float, DataLink.DataCulture, out decimal decTemp))
            {
                decTASCruise = decTemp;
            }
            else
            {
                decTASCruise = 0;
            }

            apDep = Airport.FindICAO(_data[11]);
            apArr = Airport.FindICAO(_data[13]);
            apAlt = Airport.FindICAO(_data[28]);

            if (int.TryParse(_data[12], NumberStyles.Integer, DataLink.DataCulture, out int intTemp))
            {
                intPlanAlt = intTemp;
            }
            else
            {
                try
                {
                    _data[12] = _data[12].Substring(1);
                    if (int.TryParse(_data[12], NumberStyles.Integer, DataLink.DataCulture, out intTemp))
                    {
                        intPlanAlt = intTemp;
                    }
                    else
                    {
                        intPlanAlt = 0;
                    }
                }
                catch
                {
                    intPlanAlt = 0;
                }
            }

            if (intPlanAlt.ToString().Length < 4)
            {
                intPlanAlt *= 100;
            }

            strRevision = _data[20];
            strRules    = _data[21];

            try
            {
                dtDep = new DateTime(1, 1, 1, int.Parse(_data[22].Substring(0, 2), DataLink.DataCulture), int.Parse(_data[22].Substring(2, 2), DataLink.DataCulture), 0);
            }
            catch
            {
                dtDep = default(DateTime);
            }

            try
            {
                tspEnroute = new TimeSpan(int.Parse(_data[24], DataLink.DataCulture), int.Parse(_data[25], DataLink.DataCulture), 0);
            }
            catch
            {
                tspEnroute = default(TimeSpan);
            }

            try
            {
                tspFuel = new TimeSpan(int.Parse(_data[26], DataLink.DataCulture), int.Parse(_data[27], DataLink.DataCulture), 0);
            }
            catch
            {
                tspFuel = default(TimeSpan);
            }

            strRoute   = _data[30];
            strRemarks = _data[29];
        }