protected override IEnumerable <IAircraft> Conversor(string data) { var jsonData = JsonConvert.DeserializeObject <Dictionary <string, object> >(data); var lastAirplanesRaw = JsonConvert.DeserializeObject <List <string[]> >(jsonData["states"].ToString()); var raw = lastAirplanesRaw.FirstOrDefault(); var lastAirplanes = lastAirplanesRaw.Select(s => new Airplane( hexCode: s[0], flightName: s[1], // flightname altitude: AltitudeMetric.FromMeter(String.IsNullOrEmpty(s[7]) ? 0 : Convert.ToDouble(s[7], CultureInfo.InvariantCulture)), latitude: String.IsNullOrEmpty(s[6]) ? 0 : Convert.ToDouble(s[6], CultureInfo.InvariantCulture), longitude: String.IsNullOrEmpty(s[5]) ? 0 : Convert.ToDouble(s[5], CultureInfo.InvariantCulture), speed: SpeedMetric.FromKilometerPerHour(String.IsNullOrEmpty(s[9]) ? 0 : Convert.ToDouble(s[9], CultureInfo.InvariantCulture) * 3.6), verticalSpeed: String.IsNullOrEmpty(s[11]) ? 0 : Convert.ToDouble(s[11], CultureInfo.InvariantCulture), direction: String.IsNullOrEmpty(s[10]) ? 0 : Convert.ToDouble(s[10], CultureInfo.InvariantCulture), registration: s[2], isOnGround: Boolean.Parse(s[8]), from: String.Empty, to: String.Empty, model: String.Empty )).ToList(); return(lastAirplanes); }
protected override IEnumerable <IAircraft> Conversor(string data) { var aircraftList = new List <IAircraft>(); IDictionary <string, object> routes_list = JsonConvert.DeserializeObject <Dictionary <string, object> >(data); routes_list = JsonConvert.DeserializeObject <Dictionary <string, object> >(routes_list["stats"].ToString()); string flights = routes_list["flights"].ToString(); 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 latitude = !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)) { var newAircraft = new Airplane( hexCode: hexcode, flightName: flight, altitude: AltitudeMetric.FromFoot(String.IsNullOrEmpty(altitude) ? 0 : Convert.ToDouble(altitude, CultureInfo.InvariantCulture)), latitude: String.IsNullOrEmpty(latitude) ? 0 : Convert.ToDouble(latitude, CultureInfo.InvariantCulture), longitude: String.IsNullOrEmpty(longitude) ? 0 : Convert.ToDouble(longitude, CultureInfo.InvariantCulture), speed: SpeedMetric.FromKilometerPerHour(String.IsNullOrEmpty(speed) ? 0 : Convert.ToDouble(speed, CultureInfo.InvariantCulture)), verticalSpeed: String.IsNullOrEmpty(verticalSpeed) ? 0 : Convert.ToDouble(verticalSpeed, CultureInfo.InvariantCulture), direction: String.IsNullOrEmpty(direction) ? 0 : Convert.ToDouble(direction, CultureInfo.InvariantCulture), registration: registration, isOnGround: false, from: from, to: to, model: model ); aircraftList.Add(newAircraft); } } return(aircraftList); }