private List <FlightPosition> getFlightAware() { //Timeframe check. available from 6AM to 6 PM Dubai Time //2:00 to 14:00 GMT (24 Hour Clock) DateTime Now = DateTime.UtcNow; var FlightPositions = new List <FlightPosition>(); String Query = "{> alt 5} " + "{> speed 20} " + "{true inAir} " + "{range lat 23.85438 26.39335} " + "{range lon 52.99612 59.31375}"; String WebURL = "http://flightxml.flightaware.com/json/FlightXML2/" + "SearchBirdseyeInFlight" + "?query=" + System.Uri.EscapeDataString(Query) + "&howMany=30" + "&offset=0"; using (var webClient = new System.Net.WebClient()) { webClient.UseDefaultCredentials = true; webClient.Credentials = new NetworkCredential("catheythattil", "9f8b8719108bdaa973fe4a96fef5646cd3fd32ea"); webClient.Encoding = System.Text.Encoding.UTF8; String Json2 = isDemoMode ? System.IO.File.ReadAllText(getSampleData()) : webClient.DownloadString(WebURL); dynamic ADSBInfo = JsonConvert.DeserializeObject(Json2); var FlightPosition = ADSBInfo.SearchBirdseyeInFlightResult.aircraft; for (var i = 0; i < FlightPosition.Count; i++) { var thisPos = FlightPosition[i]; System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); int UnixTimeStamp = thisPos.timestamp; var ADSBDate = dtDateTime.AddSeconds(UnixTimeStamp); var thePos = new FlightPosition { FlightID = thisPos.ident, Heading = thisPos.heading, TailNumber = thisPos.faFlightID, CallSign = thisPos.faFlightID, Lon = thisPos.longitude, Lat = thisPos.latitude, Speed = thisPos.groundspeed, Altitude = thisPos.altitude, ADSBDate = ADSBDate, FlightSource = "flightaware" }; FlightPositions.Add(thePos); } //for } //using return(FlightPositions); }
public List <FlightPosition> ADSBHistory(String DSN, DateTime OnDate) { List <FlightPosition> PositionDatas = new List <FlightPosition>(); String FromDate = OnDate.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss"); String ToDate = OnDate.ToString("yyyy-MM-dd HH:mm:ss"); String SQL = $@"SELECT * FROM AdsbHistory, (select FlightID, MAX(CreatedDate) as LastCreatedDate FROM AdsbHistory WHERE CreatedDate BETWEEN '{FromDate}' AND '{ToDate}' GROUP BY FlightId) as FilterAdsbHistory WHERE AdsbHistory.CreatedDate = FilterAdsbHistory.LastCreatedDate AND AdsbHistory.FlightId = FilterAdsbHistory.FlightId"; using (var CN = new SqlConnection(DSN)) { CN.Open(); using (var Cmd = new SqlCommand(SQL.ToString(), CN)) { var RS = Cmd.ExecuteReader(); while (RS.Read()) { int fSpeed = RS.GetOrdinal("Speed"); int fHeading = RS.GetOrdinal("Heading"); string FlightSource = RS["FlightSource"].ToString(); var Position = new FlightPosition { FlightID = RS["FlightId"].ToString(), Heading = RS.IsDBNull(fHeading) ? 0 : (Double)RS.GetDecimal(fHeading), TailNumber = RS["TailNumber"].ToString(), CallSign = RS["CallSign"].ToString(), Lon = (Double)RS.GetDecimal(RS.GetOrdinal("Lon")), Lat = (Double)RS.GetDecimal(RS.GetOrdinal("Lat")), Speed = RS.IsDBNull(fSpeed) ? 0 : (Double)RS.GetDecimal(fSpeed), Altitude = (Double)RS.GetDecimal(RS.GetOrdinal("Altitude")), ADSBDate = RS.GetDateTime(RS.GetOrdinal("AdsbDate")), History = getHistory(RS["HeadingHistory"].ToString()) }; PositionDatas.Add(Position); } //while } //using } //using(var CN) return(PositionDatas); }
private List <FlightPosition> getLivePositions(Exponent.ADSB.ADSBQuery QueryData = null) { if (QueryData == null) { QueryData = new ADSBQuery(); } if (QueryData.tracking_adsb_commercial == 0 & QueryData.tracking_adsb_rpas == 0 && QueryData.tracking_adsb_skycommander == 0) { QueryData.tracking_adsb_commercial = 1; } var PositionDatas = new List <FlightPosition>(); StringBuilder Filter = new StringBuilder(); StringBuilder WHERE = new StringBuilder(); StringBuilder SQL = new StringBuilder(@" select [FlightId], [Heading], [TailNumber], [CallSign], [Lon], [Lat], [Speed], HeadingHistory, [Altitude], [AdsbDate], FlightSource, HexCode from AdsbLive "); if (QueryData.adsb_omdb == 1 || QueryData.adsb_omdw == 1 || QueryData.adsb_omsj == 1) { if (QueryData.adsb_omdb == 1) { if (Filter.Length > 0) { Filter.AppendLine(" OR"); } Filter.Append("[OMDB] <= " + QueryData.ATCRadious); } if (QueryData.adsb_omdw == 1) { if (Filter.Length > 0) { Filter.AppendLine(" OR"); } Filter.Append("[OMDW] <= " + QueryData.ATCRadious); } if (QueryData.adsb_omsj == 1) { if (Filter.Length > 0) { Filter.AppendLine(" OR"); } Filter.Append("[OMSJ] <= " + QueryData.ATCRadious); } WHERE.Append("("); WHERE.Append(Filter); WHERE.Append(")"); Filter.Clear(); } Filter.Append(QueryData.getTrackingFilter()); if (Filter.Length > 0) { if (WHERE.Length > 0) { WHERE.AppendLine(" AND"); } WHERE.Append(Filter); Filter.Clear(); } if (WHERE.Length > 0) { SQL.AppendLine(" WHERE"); SQL.Append(WHERE); } using (var Cmd = new SqlCommand(SQL.ToString(), CN)) { var RS = Cmd.ExecuteReader(); while (RS.Read()) { int fSpeed = RS.GetOrdinal("Speed"); int fHeading = RS.GetOrdinal("Heading"); string FlightSource = RS["FlightSource"].ToString(); var Position = new FlightPosition { FlightID = RS["FlightId"].ToString(), Heading = RS.IsDBNull(fHeading) ? 0 : (Double)RS.GetDecimal(fHeading), TailNumber = RS["TailNumber"].ToString(), CallSign = RS["CallSign"].ToString(), Lon = (Double)RS.GetDecimal(RS.GetOrdinal("Lon")), Lat = (Double)RS.GetDecimal(RS.GetOrdinal("Lat")), Speed = RS.IsDBNull(fSpeed) ? 0 : (Double)RS.GetDecimal(fSpeed), Altitude = (Double)RS.GetDecimal(RS.GetOrdinal("Altitude")), ADSBDate = RS.GetDateTime(RS.GetOrdinal("AdsbDate")), History = getHistory(RS["HeadingHistory"].ToString()), FlightSource = FlightSource, HexCode = RS["HexCode"].ToString().ToUpper() }; if (FlightSource == "SkyCommander") { if (Position.Altitude < 0) { Position.Altitude = 0; } if ((Position.Altitude >= QueryData.minAltitude && Position.Altitude <= QueryData.maxAltitude) && (Position.Speed >= QueryData.minSpeed && Position.Speed <= QueryData.maxSpeed)) { PositionDatas.Add(Position); } } else { PositionDatas.Add(Position); } } //while RS.Close(); } //using //Find the breaches and alerts for SkyCommander foreach (var Position in PositionDatas.Where(e => e.FlightSource == "SkyCommander").ToList()) { Position.SetBreachFlights(CN, QueryData); Position.SetAlertFlights(CN, QueryData); } return(PositionDatas); }