Skip to content

Commit

Permalink
- Implement v3 VATSIM API
Browse files Browse the repository at this point in the history
  • Loading branch information
e4rthdog committed May 3, 2021
1 parent 12ff318 commit 14c21bc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void Main(string[] args)
{
tableArrivals.ClearRows();
tableDepartures.ClearRows();
VATSIMList = Util.DownloadVatsimData(myStringWebResource, fileName, config["VATSIMINTERVAL"]);
VATSIMList = Util.DownloadVatsimData("https://data.vatsim.net/v3/vatsim-data.json", fileName, config["VATSIMINTERVAL"]);
tableArrivals.SetHeaders("Callsign", "Aircraft", "Departure", "Arrival", "TAS", "Altitude", "Distance To");
VATSIMList.Where(d => d.planned_destairport == lookFor).OrderBy(o => o.DistanceTo).ToList().ForEach(d =>
{
Expand Down
91 changes: 39 additions & 52 deletions Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using Microsoft.Extensions.Configuration;
using VatsimData;

namespace VatBoardCons
{
Expand Down Expand Up @@ -190,8 +189,7 @@ public static List<VatLine> DownloadVatsimData(string _uri, string _filename, st
WriteLn("\nDownloading VATSIM data ...", ConsoleColor.Black, ConsoleColor.Yellow, false);
try
{
WebClient wc = new WebClient();
wc.DownloadFile(_uri, _filename);
VatsimData.VatsimData.GetData(_uri);
WriteLn("DONE!", ConsoleColor.Black, ConsoleColor.Yellow);
}
catch (WebException wex)
Expand All @@ -202,61 +200,50 @@ public static List<VatLine> DownloadVatsimData(string _uri, string _filename, st
System.Environment.Exit(-1);
}
}
string[] dataLines = File.ReadAllLines(_filename);
bool isPilot = false;
foreach (string dataLine in dataLines)
var fp = new FlightPlan();
foreach (var pilot in VatsimData.VatsimData.Data.Pilots)
{
if (isPilot && dataLine != "!SERVERS:" && dataLine.Contains(":PILOT:"))
string user_lat_dep = "0.0";
string user_lon_dep = "0.0";
string user_lat_dest = "0.0";
string user_lon_dest = "0.0";
if (pilot.FlightPlan != null)
{
string[] col = dataLine.Split(":");
if (col[3] == "PILOT")
fp = (FlightPlan)pilot.FlightPlan;

if (Airports.Any(x => x.code == fp.Departure))
{
user_lat_dep = Airports.Find(x => x.code == fp.Departure).lat;
user_lon_dep = Airports.Find(x => x.code == fp.Departure).lon;
}
if (Airports.Any(x => x.code == fp.Arrival))
{
string user_lat_dep = "0.0";
string user_lon_dep = "0.0";
string user_lat_dest = "0.0";
string user_lon_dest = "0.0";
if (Airports.Any(x => x.code == col[11]))
{
user_lat_dep = Airports.Find(x => x.code == col[11]).lat;
user_lon_dep = Airports.Find(x => x.code == col[11]).lon;
}
if (Airports.Any(x => x.code == col[13]))
{
user_lat_dest = Airports.Find(x => x.code == col[13]).lat;
user_lon_dest = Airports.FirstOrDefault(x => x.code == col[13]).lon;
}
dataList.Add(new VatLine
{
callsign = col[0],
planned_depairport = col[11],
planned_destairport = col[13],
planned_aircraft = col[9],
planned_tascruise = col[8],
altitude = col[7],
lat = col[5],
lon = col[6],
DistanceTo = Util.distance(
Convert.ToDouble(user_lat_dest.Replace(".", ",")),
Convert.ToDouble(user_lon_dest.Replace(".", ",")),
Convert.ToDouble(col[5].Replace(".", ",")),
Convert.ToDouble(col[6].Replace(".", ",")), 'N'),
DistanceFrom = Util.distance(
Convert.ToDouble(user_lat_dep.Replace(".", ",")),
Convert.ToDouble(user_lon_dep.Replace(".", ",")),
Convert.ToDouble(col[5].Replace(".", ",")),
Convert.ToDouble(col[6].Replace(".", ",")), 'N'),
});
user_lat_dest = Airports.Find(x => x.code == fp.Arrival).lat;
user_lon_dest = Airports.FirstOrDefault(x => x.code == fp.Arrival).lon;
}
}

if (dataLine == "!CLIENTS:")
dataList.Add(new VatLine
{
isPilot = true;
}
if (dataLine == "!SERVERS:")
{
isPilot = false;
}
callsign = pilot.Callsign,
planned_depairport = fp.Departure,
planned_destairport = fp.Arrival,
planned_aircraft = fp.Aircraft,
planned_tascruise = fp.CruiseTAS,
altitude = fp.Altitude,
lat = pilot.Latitude.ToString(),
lon = pilot.Longitude.ToString(),
DistanceTo = Util.distance(
Convert.ToDouble(user_lat_dest.Replace(".", ",")),
Convert.ToDouble(user_lon_dest.Replace(".", ",")),
Convert.ToDouble(pilot.Latitude.ToString().Replace(".", ",")),
Convert.ToDouble(pilot.Longitude.ToString().Replace(".", ",")), 'N'),
DistanceFrom = Util.distance(
Convert.ToDouble(user_lat_dep.Replace(".", ",")),
Convert.ToDouble(user_lon_dep.Replace(".", ",")),
Convert.ToDouble(pilot.Latitude.ToString().Replace(".", ",")),
Convert.ToDouble(pilot.Longitude.ToString().Replace(".", ",")), 'N'),
});
}
return dataList;
}
Expand Down
12 changes: 10 additions & 2 deletions VatBoard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ReadLine" Version="2.0.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<Reference Include="VatsimData">
<HintPath>V:\_DEV\VatsimData\VatsimData\bin\Release\netstandard2.0\VatsimData.dll</HintPath>
<Private>true</Private>
</Reference>
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 14c21bc

Please sign in to comment.