//Get's the number of flight's currently tracked by the REST API. public int getNumOfFlights() { RESTAPIHandlerer RAH = new RESTAPIHandlerer(); var flights = RAH.GetAllFlightsFromAPI(); return(flights.Count()); }
//Returns a list of all unique origin country's of all flights. public List <Country> GetCountriesFromAPI() { RESTAPIHandlerer RAH = new RESTAPIHandlerer(); var flights = RAH.GetAllFlightsFromAPI(); var countryName = "/"; List <String> sCountriesAPI = new List <String>(); List <Country> objCountriesAPI = new List <Country>(); for (int i = 0; i < flights.Count; i++) { if (!string.IsNullOrWhiteSpace((string)flights[i][2])) { countryName = (string)flights[i][2]; } sCountriesAPI.Add(countryName); } sCountriesAPI = sCountriesAPI.Distinct().ToList(); foreach (var country in sCountriesAPI) { objCountriesAPI.Add(new Country { CountryId = 0, CountryName = country }); } return(objCountriesAPI); }
//Returns a list of flight objects in a list and also a bool variable that defines the success of the function (If successful returns true if not false.) public (List <Flight>, bool) GetFlightsFromAPI(List <Country> selectedCountries) { RESTAPIHandlerer RAH = new RESTAPIHandlerer(); var flights = RAH.GetAllFlightsFromAPI(); ArgumentException thrownError; string callSign = "", squawk = ""; decimal velocity, verticalRate, longitude, latitude, trueTrack, baroAltitude, geoAltitude; velocity = verticalRate = longitude = latitude = trueTrack = baroAltitude = geoAltitude = (decimal)0.0; List <Flight> flightsFromSelectedCountries = new List <Flight>(); List <Position> flightPositions = new List <Position>(); foreach (var country in selectedCountries) { for (int i = 0; i < flights.Count; i++) { if (country.CountryName == (string)flights[i][2]) { //Validate all data that can be null. //Callsign try { callSign = (string)flights[i][1]; if (string.IsNullOrWhiteSpace(callSign)) { callSign = "Unidentified"; } } catch (ArgumentException e) { callSign = "Unidentified"; thrownError = e; } //Velocity try { velocity = Convert.ToDecimal(flights[i][9]); } catch (ArgumentException e) { thrownError = e; } //VerticalRate try { verticalRate = Convert.ToDecimal(flights[i][11]); } catch (ArgumentException e) { thrownError = e; } //Squawk try { squawk = (string)flights[i][14]; if (string.IsNullOrWhiteSpace(squawk)) { squawk = "Unidentified"; } } catch (ArgumentException e) { squawk = "Unidentified"; thrownError = e; } //Longitude try { longitude = Convert.ToDecimal(flights[i][5]); } catch (ArgumentException e) { thrownError = e; } //Latitude try { latitude = Convert.ToDecimal(flights[i][6]); } catch (ArgumentException e) { thrownError = e; } //TrueTrack try { trueTrack = Convert.ToDecimal(flights[i][10]); } catch (ArgumentException e) { thrownError = e; } //BaroAltitude try { baroAltitude = Convert.ToDecimal(flights[i][7]); } catch (ArgumentException e) { thrownError = e; } //GeoAltitude try { geoAltitude = Convert.ToDecimal(flights[i][13]); } catch (ArgumentException e) { thrownError = e; } //Validation of possible null values complete. flightPositions.Add(new Position { positionId = 0, longitude = longitude, latitude = latitude, baroAltitude = baroAltitude, onGround = (bool)flights[i][8], trueTrack = trueTrack, geoAltitude = geoAltitude, positionSource = (int)flights[i][16] }); flightsFromSelectedCountries.Add(new Flight { flightId = 0, icao24 = (string)flights[i][0], callSign = callSign, flightCountryId = country.CountryId, velocity = velocity, verticalRate = verticalRate, squawk = squawk, spi = (bool)flights[i][15] }); } } } bool success = pR.WritePositionsToDB(flightPositions); return(flightsFromSelectedCountries, success); }