public Alert(Radar radar, string Pluginname, AirplaneBasic airplane, IconType iconType, MessageType messageType = MessageType.General, RatificationType ratificationType = RatificationType.NoRatification) { this.Airplane = airplane; this.PluginName = Pluginname; ID = radar.Name + Pluginname + Airplane.ID; ID = ID.Replace(" ", "").Replace("-", ""); ID = (ID.Length > 25) ? ID.Substring(0, 24) : ID; if (ratificationType != RatificationType.NoRatification) { RatificationType = ratificationType; ID += "Ratification" + ratificationType.ToString(); } this.Radar = radar; TimeCreated = DateTime.Now; TimeToBeRemoved = DateTime.Now.AddHours(1); this.Icon = iconType; TimeCreated = new DateTime( TimeCreated.Ticks - (TimeCreated.Ticks % TimeSpan.TicksPerSecond), TimeCreated.Kind );; AirplaneID = airplane.ID; this.AirplaneHexa = airplane.ID; this.AirplaneFlight = airplane.FlightName; this.AirplaneReg = airplane.Registration.Name; this.AirplaneFrom = airplane.From.ICAO; this.AirplaneTo = airplane.To.ICAO; SetMessage(messageType); }
static Alert() { try { string strJSONPath = String.Empty; var lastAlertsRaw = LoadFile(strJSONPath, "lastAlerts.json"); Alert.ListOfAlerts = JsonConvert.DeserializeObject <List <Alert> >(lastAlertsRaw); //var teste = JsonConvert.DeserializeObject<List<Alert>>(lastAlertsRaw); if (Alert.ListOfAlerts == null) { Alert.ListOfAlerts = new List <Alert>(); } foreach (var item in Alert.ListOfAlerts) { if (item.TimeToBeRemoved.Year < 2000) { item.TimeToBeRemoved = item.TimeCreated.AddDays(3); } item.Radar = Radar.GetRadar(item.Radar.Name); if (item.Icon == IconType.Landing || item.Icon == IconType.TakingOff || item.Icon == IconType.Cruise) { // irplane.ID + "|" + airplane.Registration.Name + "|" + airplane.AircraftType.ICAO + "|" + ((int)airplane.Weight); var objs = item.Message.Split('|'); if (objs.Length == 4) { var airplane = new AirplaneBasic(); airplane.ID = objs[0]; airplane.Registration = new AircraftRegistration(objs[1]); airplane.AircraftType = AircraftType.GetAircraftType(objs[2]); airplane.Weight = (AirplaneWeight)Convert.ToInt32(objs[3]); item.Airplane = airplane; } } } if (Alert.ListOfAlerts != null) { Console.WriteLine("Messages rescued: {0}", Alert.ListOfAlerts.Count); } } catch (Exception e) { throw new ArgumentException(@"lastAlerts.json"); } }
public static AirplaneBasic ConvertToAirplane(Radar radar, string hexCode, string flightName, string altitude, string latitude, string longitude, string speed, string verticalSpeed, string direction, string from, string to, string model, string registration) { try { AirplaneBasic airplane = new AirplaneBasic() { ID = hexCode, AircraftType = (AircraftType)(model), Altitude = String.IsNullOrEmpty(altitude) ? 0 : Math.Round(Convert.ToDouble(altitude)), Direction = String.IsNullOrEmpty(direction) ? 0 : Convert.ToDouble(direction), From = Airport.GetAirportByIata(from), FlightName = flightName, Airline = Airline.GetAirlineByFlight(flightName), Latitude = String.IsNullOrEmpty(latitude) ? 0 : Convert.ToDouble(latitude), Longitude = String.IsNullOrEmpty(longitude) ? 0 : Convert.ToDouble(longitude), Registration = new AircraftRegistration(registration), Speed = String.IsNullOrEmpty(speed) ? 0 : Math.Round(Convert.ToDouble(speed)), To = Airport.GetAirportByIata(to), VerticalSpeed = String.IsNullOrEmpty(verticalSpeed) ? 0 : Convert.ToDouble(verticalSpeed), DateCreation = DateTime.Now, }; airplane.Radars.Add(radar); airplane.FinalConvertAirplaneRules(); airplane.UpdateAirplaneStatus(); return(airplane); } catch (Exception e) { ErrorManager.ThrowError(e, "Airplane Conversion from JSON"); return(null); } }
public static AirplaneBasic ConvertToAirplane(Radar radar, object[] jsonData, string keyName) { try { AirplaneBasic airplane = new AirplaneBasic() { ID = !String.IsNullOrEmpty(jsonData[0].ToString()) ? jsonData[0].ToString() : keyName, AircraftType = (AircraftType)jsonData[8].ToString(), Altitude = Convert.ToInt32(jsonData[4]), Direction = Convert.ToInt32(jsonData[3]), From = Airport.GetAirportByIata(jsonData[11].ToString()), FlightName = jsonData[16].ToString(), Airline = Airline.GetAirlineByFlight(jsonData[16].ToString()), Latitude = Convert.ToDouble(jsonData[1]), Longitude = Convert.ToDouble(jsonData[2]), Registration = new AircraftRegistration(jsonData[9].ToString()), Speed = Convert.ToInt32(jsonData[5]), To = Airport.GetAirportByIata(jsonData[12].ToString()), VerticalSpeed = Convert.ToDouble(jsonData[15]), DateCreation = DateTime.Now, SpecialDescription = String.Empty }; airplane.Radars.Add(radar); airplane.FinalConvertAirplaneRules(); airplane.UpdateAirplaneStatus(); return(airplane); } catch (Exception e) { ErrorManager.ThrowError(e, String.Format("{0} - {1} - {2}", @"Airplane Conversion from JSON\r", jsonData, e)); return(null); } }
/// <summary> /// Will return the name of the runway /// </summary> /// <param name="airplane"></param> /// <returns></returns> public string IsAirplaneInFinalRunway(AirplaneBasic airplane, double direction = 0) { string name = String.Empty; double degreesAperture = 5; double finalOneDirection = MapMathHelper.GetAngle(LongitudeSideOne, LongitudeSideTwo, LatitudeSideOne, LatitudeSideTwo); double finalTwoDirection = MapMathHelper.GetAngle(LongitudeSideTwo, LongitudeSideOne, LatitudeSideTwo, LatitudeSideOne); double degreesOneFromPosition = MapMathHelper.GetAngle(LongitudeSideOne, airplane.Longitude, LatitudeSideOne, airplane.Latitude); double degreesTwoFromPosition = MapMathHelper.GetAngle(LongitudeSideTwo, airplane.Longitude, LatitudeSideTwo, airplane.Latitude); bool isTargetInAngleFromOne = finalOneDirection - degreesAperture <degreesOneFromPosition && finalOneDirection + degreesAperture> degreesOneFromPosition; bool isTargetInAngleFromTwo = finalTwoDirection - degreesAperture <degreesTwoFromPosition && finalTwoDirection + degreesAperture> degreesTwoFromPosition; if (isTargetInAngleFromOne && airplane.State == AirplaneStatus.Landing || isTargetInAngleFromTwo && airplane.State == AirplaneStatus.TakingOff) { name = this.NameSideTwo; } else if (isTargetInAngleFromOne && airplane.State == AirplaneStatus.TakingOff || isTargetInAngleFromTwo && airplane.State == AirplaneStatus.Landing) { name = this.NameSideOne; } return(name); }
private void MakeCurrentMessage(AirplaneBasic airplane, Radar radar, RatificationType ratificationType = RatificationType.NoRatification, int seed = 0) { try { this.Airplane = airplane; this.Message = String.Empty; this.Radar = radar; this.article = RandomListPhrases(listOfArticles); this.indefinitiveArticle = RandomListPhrases(listOfIndefinitiveArticles); #region Setting the airplane name and/or model if (airplane.AircraftType.IsValid || !String.IsNullOrEmpty(airplane.AircraftType.Name)) { airplaneTypeLongPhrase = String.Format(", {0}", airplane.AircraftType.Name); } if (!String.IsNullOrEmpty(this.Airplane.SpecialDescription)) { if (this.Airplane.IsSpecial) { airplaneRegistrationOrModel = String.Format("{0}, {1} {2}", airplane.SpecialDescription, this.article.ToLower(), this.Airplane.Registration.Name); } else { airplaneRegistrationOrModel = String.Format("{0}, ({1})", airplane.SpecialDescription, this.Airplane.Registration.Name); } if (!String.IsNullOrEmpty(this.Airplane.FlightName)) { airplaneRegistrationOrModel += String.Format(", {0}", this.Airplane.FlightName); } article = String.Empty; } else if (this.Airplane.Registration.IsValid && this.Airplane.AircraftType.Type == AircraftModel.AirplaneHeavy) { if (!String.IsNullOrEmpty(this.Airplane.FlightName)) { airplaneRegistrationOrModel = String.Format("{0}, {1} ({2})", airplane.AircraftType.Name, this.Airplane.FlightName, this.Airplane.Registration.Name); } //airplaneRegistrationOrModel = airplane.AircraftType.Name + ", o " + this.Airplane.FlightName + " (" + this.Airplane.Registration.Name + ")"; else { airplaneRegistrationOrModel = String.Format("{0}, ({1})", airplane.AircraftType.Name, this.Airplane.Registration.Name); } //airplaneRegistrationOrModel = airplane.AircraftType.Name + " (" + this.Airplane.Registration.Name + ")"; airplaneTypeLongPhrase = String.Empty; if (ratificationType == RatificationType.NoRatification) { article = this.indefinitiveArticle; } } else if (!string.IsNullOrEmpty(this.Airplane.FlightName) && this.Airplane.Registration.IsValid && this.Airplane.AircraftType.Type == AircraftModel.Helicopter) { airplaneRegistrationOrModel = String.Format("{0}, {1} {2} ({3})", airplane.AircraftType.Name, this.article.ToLower(), this.Airplane.FlightName, this.Airplane.Registration.Name); if (ratificationType == RatificationType.NoRatification) { article = this.indefinitiveArticle; } } else if (!string.IsNullOrEmpty(this.Airplane.FlightName) && this.Airplane.Registration.IsValid) { airplaneRegistrationOrModel = String.Format("{0} ({1})", this.Airplane.FlightName, this.Airplane.Registration.Name); } else if (!string.IsNullOrEmpty(this.Airplane.Registration.Name)) { airplaneRegistrationOrModel = this.Airplane.Registration.Name; } else if (this.Airplane.AircraftType.IsValid) { airplaneRegistrationOrModel = this.Airplane.AircraftType.Name; article = this.indefinitiveArticle; airplaneTypeLongPhrase = String.Empty; } else if (!String.IsNullOrEmpty(this.Airplane.FlightName)) { airplaneRegistrationOrModel = String.Format("{1} {2} (?)", airplane.AircraftType.Name, this.article, this.Airplane.FlightName); if (ratificationType == RatificationType.NoRatification) { article = this.indefinitiveArticle; } } else { airplaneRegistrationOrModel = String.Format("{0} (Hex: {1})", notIdentifiedMessage, this.Airplane.ID); article = String.Empty; } if (!String.IsNullOrEmpty(article)) { phraseBeginningWithAirplaneRegistration = article + " " + airplaneRegistrationOrModel; phraseEndingWithAirplaneRegistration = article.ToLower() + " " + airplaneRegistrationOrModel; } else { phraseBeginningWithAirplaneRegistration = airplaneRegistrationOrModel; phraseEndingWithAirplaneRegistration = airplaneRegistrationOrModel[0].ToString().ToLower() + airplaneRegistrationOrModel.Substring(1); } if (ratificationType == RatificationType.NoRatification) { #region This code was commented for a while, the system is not giving enough support to these features // if (!this.Airplane.IsKnowCountry) // { // phraseBeginningWithAirplaneRegistration += " - " + this.Airplane.Registration.Country + " - "; // phraseEndingWithAirplaneRegistration += " - " + this.Airplane.Registration.Country + " - "; // } // if (this.Airplane.FollowingChart != null) // { // phraseBeginningWithAirplaneRegistration += ", seguindo " + this.Airplane.FollowingChart.ChartType + " " + this.Airplane.FollowingChart.Name + ","; // phraseEndingWithAirplaneRegistration += ", seguindo " + this.Airplane.FollowingChart.ChartType + " " + this.Airplane.FollowingChart.Name + ","; // } // if (!String.IsNullOrEmpty(this.Airplane.RunwayName) && (this.Airplane.State == AirplaneStatus.Landing || this.Airplane.State == AirplaneStatus.TakingOff)) // { // phraseBeginningWithAirplaneRegistration += ", pista " + this.Airplane.RunwayName + ","; // phraseEndingWithAirplaneRegistration += ", pista " + this.Airplane.RunwayName + ","; // } #endregion #endregion #region Setting what is the route of the airplane if (airplane.From.City != airplane.To.City) { fromPlace = !String.IsNullOrEmpty(airplane.From.City) ? String.Format(" {0} {1}", RandomListPhrases(listOfFromMessages), airplane.From.City) : String.Empty; toPlace = !String.IsNullOrEmpty(airplane.To.City) ? String.Format(" {0} {1}", RandomListPhrases(listOfToMessages), airplane.To.City) : String.Empty; } #endregion if (this.Airplane != null) { if (airplane.State == AirplaneStatus.TakingOff) { Message = GetTakingOffPhrase(); } else if (airplane.State == AirplaneStatus.Landing) { Message = GetLandingPhrase(); } else if (airplane.State == AirplaneStatus.Cruise) { Message = GetCruisePhrase() + fromPlace + toPlace; } else if (airplane.State == AirplaneStatus.ParkingOrTaxing) { Message = GetParkingTaxiPhrase(); } Message += airplaneTypeLongPhrase; if (airplane.State == AirplaneStatus.Cruise || airplane.State == AirplaneStatus.Landing) { if (Message.Length <= 100) { Message += fromPlace; } } if (airplane.State == AirplaneStatus.Cruise || airplane.State == AirplaneStatus.TakingOff) { if (Message.Length <= 100) { Message += toPlace; } } if (Message.Length <= 110) { Message += RobotBumLibCore.Plugins.HelperPlugin.GetForwardLocationsPhrase(this.Airplane, true, 2); } else { Message += RobotBumLibCore.Plugins.HelperPlugin.GetForwardLocationsPhrase(this.Airplane, true); } } Message += "."; } else if (ratificationType == RatificationType.Chart) { this.Message += GetChartPhrase(); } else if (ratificationType == RatificationType.FinalRunway) { this.Message += GetRunwayPhrase(); } else if (ratificationType == RatificationType.Orbit) { this.Message += GetOrbitPhrase(); } if (Message.Length <= 125 && (airplane.State == AirplaneStatus.Landing || airplane.State == AirplaneStatus.TakingOff) && radar.MainAirport != null) { Message += " #Airport" + radar.MainAirport.ICAO; } if (Message.Length <= 130) { Message += " #RobotBum"; } Message = Regex.Replace(Message, @"\s+", " "); } catch (Exception e) { ErrorManager.ThrowError(e, "Message Maker " + e.Message); } }
public MessageMaker(AirplaneBasic airplane, Radar radar, int seed, RatificationType ratificationType = RatificationType.NoRatification) { MakeCurrentMessage(airplane, radar, ratificationType, seed); }
static async private Task <List <AirplaneBasic> > DesarializeAirplanes(Radar radar) { string responseBodyAsText = String.Empty; List <AirplaneBasic> listAirplanes = null; var credentials = new NetworkCredential(radar.User, radar.Password); var handler = new HttpClientHandler { Credentials = credentials }; HttpClient httpClient = new HttpClient(handler); HttpResponseMessage response = null; try { if (!String.IsNullOrEmpty(radar.EndpointUrl)) { try { response = httpClient.PostAsync(radar.EndpointUrl, new StringContent("{\"req\":\"getStats\",\"data\":{\"statsType\":\"flights\",\"id\":38209319}}", Encoding.UTF8, "application/x-www-form-urlencoded")).Result; } catch (Exception e) { Console.WriteLine("Radar " + radar.Name + " is out."); ErrorManager.ThrowError(e, "Radar " + radar.Name + " is out.", false); } responseBodyAsText = response.Content.ReadAsStringAsync().Result; PluginsManager.LastConnectionDate = DateTime.Now; } else if (radar.RadarParent != null) { listAirplanes = CallParentRadar(radar); } } catch (Exception e) { listAirplanes = CallParentRadar(radar); Console.WriteLine("Radar " + radar.Name + " is out."); ErrorManager.ThrowError(e, "Radar " + radar.Name + " is out.", false); } try { listAirplanes = new List <AirplaneBasic>(); ErrorManager.LastRowData = responseBodyAsText; if (response.IsSuccessStatusCode && !String.IsNullOrEmpty(responseBodyAsText)) { Dictionary <string, object> routes_list = JsonConvert.DeserializeObject <Dictionary <string, object> >(responseBodyAsText); routes_list = JsonConvert.DeserializeObject <Dictionary <string, object> >(routes_list["stats"].ToString()); string flights = routes_list["flights"].ToString();//.Replace("{[", "[").Replace("]}", "]"); var flightsJArray = JsonConvert.DeserializeObject <JArray>(routes_list["flights"].ToString()).ToList(); for (int i = 0; i < flightsJArray.Count; i++) { var flightDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(flightsJArray[i].ToString()); string hexcode = !flightDictionary.ContainsKey("I") ? String.Empty : flightDictionary["I"];; string flight = !flightDictionary.ContainsKey("CS") ? String.Empty : flightDictionary["CS"]; string altitude = !flightDictionary.ContainsKey("A") ? String.Empty : flightDictionary["A"]; string longitude = !flightDictionary.ContainsKey("LO") ? String.Empty : flightDictionary["LO"]; string latitudade = !flightDictionary.ContainsKey("LA") ? String.Empty : flightDictionary["LA"]; string speed = !flightDictionary.ContainsKey("S") ? String.Empty : flightDictionary["S"]; string direction = !flightDictionary.ContainsKey("D") ? String.Empty : flightDictionary["D"]; string verticalSpeed = !flightDictionary.ContainsKey("V") ? String.Empty : flightDictionary["V"]; string fromToPhrase = !flightDictionary.ContainsKey("FR") ? String.Empty : flightDictionary["FR"]; string[] fromToArray = String.IsNullOrEmpty(fromToPhrase) && !fromToPhrase.Contains('-') ? null : fromToPhrase.Split('-'); string from = fromToArray == null ? String.Empty : fromToArray[0]; string to = fromToArray == null ? String.Empty : fromToArray.Length <= 0 ? String.Empty : fromToArray[1]; string model = !flightDictionary.ContainsKey("ITC") ? String.Empty : flightDictionary["ITC"]; string registration = !flightDictionary.ContainsKey("RG") ? String.Empty : flightDictionary["RG"]; if (!String.IsNullOrEmpty(altitude)) { AirplaneBasic airplane = AirplaneBasic.ConvertToAirplane(radar, hexcode, flight, altitude, latitudade, longitude, speed, verticalSpeed, direction, from, to, model, registration); listAirplanes.Add(airplane); } } } } catch (Exception e) { Console.WriteLine("Deserialize Radar " + radar.Name + " is out."); ErrorManager.ThrowError(e, "Deserialize Radar " + radar.Name + " is out."); } radar.CurrentAirplanes = listAirplanes; radar.LastAirplanes = listAirplanes; return(listAirplanes); }
public void FinalConvertAirplaneRules() { try { this.ID = String.IsNullOrEmpty(this.ID) ? this.Registration.Name : this.ID; var lastAirplanesFromRadars = new List <AirplaneBasic>(); this.Radars.ForEach(radar => { if (radar.LastAirplanes != null && radar.LastAirplanes.Count > 0) { lastAirplanesFromRadars.AddRange(radar.LastAirplanes); } }); this.PreviousAirplane = lastAirplanesFromRadars.Where(s => s.ID == this.ID).FirstOrDefault(); this.Weight = RobotBumLibCore.Plugins.HelperPlugin.ListWideAirplanes.Where(s => this.AircraftType.ICAO.StartsWith(s)).Count() > 0 ? AirplaneWeight.Heavy : AirplaneWeight.NotSet; if (this.Weight == AirplaneWeight.NotSet) { this.Weight = RobotBumLibCore.Plugins.HelperPlugin.ListCommonAirplanes.Where(s => this.AircraftType.ICAO.StartsWith(s)).Count() > 0 ? AirplaneWeight.Medium : AirplaneWeight.Light; } } catch (Exception e) { ErrorManager.ThrowError(e, "Error on ID, PreviousAirplane or Weight"); } try { this.DateExpiration = DateTime.Now.AddHours(1); if (this.From != null || this.To != null) { this.FlightDistance = (!string.IsNullOrEmpty(this.From.City) && !string.IsNullOrEmpty(this.To.City)) ? MathHelper.GetGPSDistance(this.From.Latitude, this.To.Latitude, this.To.Longitude, this.To.Longitude) : 0; } if (!this.AircraftType.IsValid || !this.Registration.IsValid) { var dataByHexCode = new HexCodeAirplane(this.ID); if (dataByHexCode.IsValid) { if (!this.AircraftType.IsValid && dataByHexCode.AircraftType.IsValid && dataByHexCode.AircraftType.Name != ".NO-REG") { this.AircraftType = dataByHexCode.AircraftType; } if (!this.Registration.IsValid && dataByHexCode.Registration.IsValid) { this.Registration = dataByHexCode.Registration; } if (!String.IsNullOrEmpty(dataByHexCode.Description)) { this.SpecialDescription = dataByHexCode.Description; } } } } catch (Exception e) { ErrorManager.ThrowError(e, "Error on DateExpiration, FlightDistance, dataByHexCode or Registration"); } #region Special paintings try { if (ListSpecialPainitngs.Count <= 0) { StreamReader file = File.OpenText(MultiOSFileSupport.ResourcesFolder + "specialpaintings.json"); string jsonstring = file.ReadToEnd();//file.ReadToEnd(); var listNames = JsonConvert.DeserializeObject <IList <IDictionary <string, string> > >(jsonstring); for (int i = 0; i < listNames.Count; i++) { var valuestring = listNames[i]; ListSpecialPainitngs.Add(valuestring["HexCode"], valuestring["Message"]); } } if (ListSpecialPainitngs.ContainsKey(this.ID)) { this.IsSpecial = true; this.SpecialDescription = ListSpecialPainitngs[this.ID]; } } catch (Exception e) { ErrorManager.ThrowError(e, "Error on Special Painting " + e.Message); } #endregion #region Mode S data detection try { bool isModeS = this.Latitude == 0 && this.Longitude == 0 && this.VerticalSpeed == 0 && this.Altitude > 0; if (isModeS && this.PreviousAirplane != null) { double currentUpdateTimeInSeconds = (this.DateCreation - this.PreviousAirplane.DateCreation).TotalSeconds; double percentage = currentUpdateTimeInSeconds / 60; this.VerticalSpeed = (this.Altitude - this.PreviousAirplane.Altitude) * percentage; } } catch (Exception e) { ErrorManager.ThrowError(e, "Erro on Mode S detection"); } #endregion #region Verify if the airplane is from a know country try { string[] listKnownCountries = new string[] { "Brasil", "EUA", "Inglaterra", "Canadá", "Uruguai", "Bolivia", "Argentina", "Chile", "Espanha", "Portugal", "França", "Panama", "Colômbia", "Países Baixos", "México", "Reino Unido", "Coreia do Sul" }; this.IsKnowCountry = listKnownCountries.Where(s => s == this.Registration.Country).Count() > 0 || !this.Registration.IsValid; // Ou se não tiver registro, deixar como conhecido } catch (Exception e) { ErrorManager.ThrowError(e, "Error on listKnownCountries"); } #endregion UpdateAirplaneStatus(); if (this.PreviousAirplane != null) { #region Verificar se esta seguindo algum chart try { if (this.PreviousAirplane.FollowingChart == null) { foreach (var radar in this.Radars) { var regionChart = Chart.ListCharts.Where(s => s.Region == radar.Name).ToList(); double direction = MapMathHelper.GetAngle(this.PreviousAirplane.Longitude, this.Longitude, this.PreviousAirplane.Latitude, this.Latitude); for (int i = 0; i < regionChart.Count; i++) { if (regionChart[i].IsFollowingChart(this.Longitude, this.Latitude, direction)) { if (regionChart[i].ChartType == ChartType.Star && this.PreviousAirplane.State == AirplaneStatus.Landing && this.State == AirplaneStatus.Landing || regionChart[i].ChartType == ChartType.SID && this.PreviousAirplane.State == AirplaneStatus.TakingOff && this.State == AirplaneStatus.TakingOff) { this.FollowingChart = regionChart[i]; } break; } } if (this.FollowingChart != null) { break; } } } else { this.FollowingChart = this.PreviousAirplane.FollowingChart; } } catch (Exception e) { ErrorManager.ThrowError(e, "Error on Charts"); } #endregion #region Verificar se esta na final de alguma runway try { foreach (var radar in this.Radars) { for (int i = 0; i < radar.ListRunways.Count; i++) { double direction = MapMathHelper.GetAngle(this.PreviousAirplane.Longitude, this.Longitude, this.PreviousAirplane.Latitude, this.Latitude); string runwayName = radar.ListRunways[i].IsAirplaneInFinalRunway(this, direction); if (!String.IsNullOrEmpty(runwayName)) { this.RunwayName = runwayName; break; } } } } catch (Exception e) { ErrorManager.ThrowError(e, "Error on runway detection"); } #endregion #region Side difference detection if (this.PreviousAirplane.PreviousAirplane != null) { double directionFirst = MapMathHelper.GetAngle(this.PreviousAirplane.PreviousAirplane.Longitude, this.PreviousAirplane.Longitude, this.PreviousAirplane.PreviousAirplane.Latitude, this.PreviousAirplane.Latitude); double directionSecond = MapMathHelper.GetAngle(this.PreviousAirplane.Longitude, this.Longitude, this.PreviousAirplane.Latitude, this.Latitude); var diffrenceDegrees = directionFirst - directionSecond; if (diffrenceDegrees > 180) { directionFirst -= 360; } else if (diffrenceDegrees < -180) { directionSecond -= 360; } this.DirectionChange = directionSecond - directionFirst; } #endregion #region Orbit detection if (this.State != AirplaneStatus.ParkingOrTaxing) { int maxReq = 18; int minReq = 8; int numReq = 0; AirplaneBasic currentAir = this; double directionSum = 0; string log = ""; string gps = ""; while (true) { numReq++; if (currentAir.PreviousAirplane == null || numReq >= maxReq) { break; } else if (currentAir.PreviousAirplane.Altitude == 0) { break; } decimal distanceLatitude = Convert.ToDecimal(currentAir.Latitude) - Convert.ToDecimal(currentAir.PreviousAirplane.Latitude); decimal distanceLongitude = Convert.ToDecimal(currentAir.Longitude) - Convert.ToDecimal(currentAir.PreviousAirplane.Longitude); decimal distanceToCalculate = Convert.ToDecimal(0.00005); if (currentAir.Latitude == 0 || currentAir.Longitude == 0 || currentAir.Latitude == currentAir.PreviousAirplane.Latitude && currentAir.Longitude == currentAir.PreviousAirplane.Longitude || distanceLatitude < distanceToCalculate * -1 && distanceLatitude > distanceToCalculate && distanceLongitude < distanceToCalculate * -1 && distanceLongitude > distanceToCalculate || currentAir.DirectionChange < -90 || currentAir.DirectionChange > 90 ) { currentAir = currentAir.PreviousAirplane; continue; } directionSum += currentAir.DirectionChange; log += " " + currentAir.DirectionChange; gps += "new double[]{ " + currentAir.Latitude + ", " + currentAir.Longitude + " },"; currentAir = currentAir.PreviousAirplane; } if (numReq >= minReq && (directionSum < -300 || directionSum > 300)) { this.IsOrbiting = true; } } #endregion } }