Exemple #1
0
        public override Task <object> FulfillAsync()
        {
            using (var stream = UnZipCatalog())
            {
                var result = default(AirportInfo);
                var msg    = "Airport CODE not found, please try another query!";

                var geoCatalog = XElement.Load(stream);
                var airport    = geoCatalog.XPathSelectElement($"//Airport[@Id=\"{this.Code.ToUpperInvariant()}\"]");
                if (airport != null)
                {
                    var city    = airport.Parent.Parent;
                    var country = city.Parent.Parent;

                    result = new AirportInfo
                    {
                        City     = city.Attribute("Name").Value,
                        Code     = this.Code.ToUpperInvariant(),
                        Country  = country.Attribute("Name").Value,
                        Location = airport.Attribute("Location").Value,
                        Name     = airport.Attribute("Name").Value
                    };
                    msg = $"{this.Code.ToUpperInvariant()} corresponds to \"{airport.Attribute("Name").Value}\" which is located in {city.Attribute("Name").Value}, {country.Attribute("Name").Value} [{airport.Attribute("Location").Value}]";
                }

                return(Task.FromResult((object)result));
            }
        }
        private Vector2 GetTakeoffDirection(AirportInfo airportInfo)
        {
            var hashCode = airportInfo.IATA.GetHashCode();

            var angle = (hashCode % 360) * Mathf.Deg2Rad;

            return(new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)));
        }
 public void Delete(string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         AirportInfo airportInfo = new AirportInfo();
         airportInfo.Id          = keyValue;
         airportInfo.DeletedFlag = true;
         _dal.Update(airportInfo, true, "DeletedFlag");
     }
 }
        /// <summary>
        /// 机场起降点基础数据维护
        /// </summary>
        /// <param name="airportArray"></param>
        /// <param name="userID"></param>
        /// <returns></returns>
        public List <string> AddOrUpdateAirport(List <AirportFillText> airportArray, int userID, ref string airportText)
        {
            List <string> airportIDs = new List <string>();
            StringBuilder sb         = new StringBuilder("");

            foreach (var item in airportArray)
            {
                var airportid  = string.Empty;
                var data       = GetAirport(item.AirportName);
                var splitmodel = SpecialFunctions.latLongSplit(item.LatLong);
                if (data == null)
                {
                    airportid = Guid.NewGuid().ToString();
                    data      = new AirportInfo()
                    {
                        Id             = airportid,
                        Name           = item.AirportName,
                        Type           = "TH",
                        Code4          = item.CodeF,
                        Longitude      = splitmodel.Longitude ?? "",
                        Latitude       = splitmodel.Latitude ?? "",
                        FrameOfAxes    = "",
                        RunwayLength   = "",
                        AreaParentCode = "",
                        AreaCode       = "",
                        DeletedFlag    = false,
                        CreateTime     = DateTime.Now,
                        ModifiedTime   = DateTime.Now,
                        ModifiedUserId = userID,
                        CreateUserId   = userID,
                        CreateSource   = ""
                    };
                    this.Add(data);
                }
                else
                {
                    airportid = data.Id;
                    data.Name = item.AirportName;
                    if (!string.IsNullOrEmpty(splitmodel.Latitude))
                    {
                        data.Latitude = splitmodel.Latitude;
                    }
                    if (!string.IsNullOrEmpty(splitmodel.Longitude))
                    {
                        data.Longitude = splitmodel.Longitude;
                    }
                    _dal.Update(data, "Id", "Name", "Longitude", "Latitude");
                }
                sb.AppendLine(item.AirportName + ";");
                airportIDs.Add(airportid);
            }
            airportText = sb.ToString();
            return(airportIDs);
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="System.IO.InvalidDataException"> Thrown when requested Code is invalid format for requested code type</exception>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Search_Click(object sender, EventArgs e)
        {
            bool        valid       = true;
            AirportInfo airportInfo = new AirportInfo(ICAO_API_KEY);
            Airport     airportData;
            string      JsonData = "";

            //Disable alternate inputs as it would throw a NotImplementedException otherwize
            if (this.TxtBox_CodeType.SelectedIndex != 0)
            {
                return;
            }

            switch (this.TxtBox_CodeType.SelectedIndex)
            {
            case 0:
            {
                JsonData = airportInfo.Find_By_ICAO(TxtBox_AirportCode.Text);
                break;
            }

            case 1:
            {
                JsonData = airportInfo.Find_By_IATA(TxtBox_AirportCode.Text);
                break;
            }

            case 2:
            {
                JsonData = airportInfo.Find_By_Lid(TxtBox_AirportCode.Text, "TC");
                break;
            }

            case 3:
            {
                JsonData = airportInfo.Find_By_Lid(TxtBox_AirportCode.Text, "FAA");
                break;
            }

            default:
            {
                MessageBox.Show("Invalid Code Type Selected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                valid = false;
                break;
            }
            }

            if (valid)
            {
                airportData = new Airport(JsonData);

                PopulateResults(airportData);
            }
        }
        public AirportInfo Add(AirportInfo entity)
        {
            entity.DeletedFlag    = false;
            entity.CreateTime     = DateTime.Now;
            entity.CreateUserId   = 0;
            entity.ModifiedTime   = DateTime.Now;
            entity.ModifiedUserId = 0;

            _dal.Add(entity);

            return(entity);
        }
Exemple #7
0
        public async Task <Coordinate> GetCoordinate(string airportIataCode)
        {
            AirportInfo airportInfo = await this.GetAirportInfo(airportIataCode);;

            if (airportInfo?.Location == null)
            {
                throw new Exception("Airport Information does not contain Location info");
            }

            return(new Coordinate()
            {
                Latitude = airportInfo.Location.Lat, Longitude = airportInfo.Location.Lon
            });
        }
Exemple #8
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            AirportInfo airport      = (AirportInfo)value;
            string      strParameter = parameter as string;

            if (strParameter == "code")
            {
                return($"{airport.Name} ({airport.IataAirportCode})");
            }
            else
            {
                return(airport.Name);
            }
        }
Exemple #9
0
        public async Task <AirportInfo> GetAirportInfo(string airportIataCode)
        {
            SimpleHttpCommunicator httpCommunicator = new SimpleHttpCommunicator();
            string airportInfoString = await httpCommunicator.SendGetRequest(String.Format("{0}/{1}", CTELEPORT_ENDPOINT_URL, airportIataCode));

            AirportInfo airportInfo = null;

            try
            {
                airportInfo = JsonConvert.DeserializeObject <AirportInfo>(airportInfoString);
            }
            catch
            {
                throw new Exception("Unable to retreive Airport Information from CTeleport endpoint. Response is corrupted");
            }
            return(airportInfo);
        }
Exemple #10
0
        public void PopulateAirports()
        {
            _client.DefaultRequestHeaders.Clear();
            string address      = "https://raw.githubusercontent.com/ecalder6/Surf/master/data/airports.json";
            string response     = _client.GetStringAsync(address).Result;
            var    airprotsInfo = AirportInfo.FromJson(response);

            Console.WriteLine(airprotsInfo.Keys.Count);
            foreach (AirportInfo info in airprotsInfo.Values)
            {
                if (!CityToAirports.TryGetValue(info.City, out List <AirportInfo> airportList))
                {
                    airportList = new List <AirportInfo>();
                    CityToAirports.Add(info.City, airportList);
                }
                airportList.Add(info);
                AirportCodes.Add(info.Iata);
            }
        }
 public void Update(AirportInfo entity)
 {
     _dal.Update(entity, false, "DeletedFlag");
 }