-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from Nikolai558/development
Releasing v2.0.0
- Loading branch information
Showing
43 changed files
with
2,497 additions
and
807 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FeBuddyLibrary.Helpers; | ||
using FeBuddyLibrary.Models; | ||
using Newtonsoft.Json; | ||
|
||
namespace FeBuddyLibrary.DataAccess | ||
{ | ||
public class AircraftData | ||
{ | ||
AircraftDataRootObject AllAircraftData; | ||
|
||
public void CreateAircraftDataAlias(string outputFilePath) | ||
{ | ||
AllAircraftData = GetACDataAsync().Result; | ||
WriteACData(outputFilePath); | ||
} | ||
|
||
private async Task<AircraftDataRootObject> GetACDataAsync() | ||
{ | ||
HttpClient client = new HttpClient(); | ||
|
||
var url = "https://www4.icao.int/doc8643/External/AircraftTypes"; | ||
var values = new Dictionary<string, string> | ||
{ | ||
{"Connection", "keep-alive" }, | ||
{"Content-Length", "0" }, | ||
{"Pragma", "no-cache" }, | ||
{"Cache-Control", "no-cache" }, | ||
{"Content-Type", "application/json" } | ||
}; | ||
|
||
var content = new FormUrlEncodedContent(values); | ||
var response = await client.PostAsync(url, content); | ||
|
||
string responseStringJson = await response.Content.ReadAsStringAsync(); | ||
|
||
responseStringJson = "{\"AllAircraftData\":" + responseStringJson + "}"; | ||
|
||
AircraftDataRootObject output = JsonConvert.DeserializeObject<AircraftDataRootObject>(responseStringJson); | ||
|
||
return output; | ||
} | ||
|
||
private void WriteACData(string outputFilePath) | ||
{ | ||
string command; | ||
|
||
StringBuilder aliasFileSB = new StringBuilder(); | ||
|
||
Dictionary<string, AircraftDataInformation> uniqueACData = getUniqueACData(AllAircraftData); | ||
|
||
// .acinfoc172 -> | ||
// *** [CODE] C172 ::: [MAKE] CESSNA AIRCRAFT COMPANY ::: [MODEL] 172, P172, R172, Skyhawk, Hawk XP, Cutlass (T-41, Mescalero) ::: [ENGINE] 1/PistonProp ::: [WEIGHT] Small ::: [C/D] 600/1000 ::: [SRS] 1 | ||
// | ||
// .ACINFOC172 .MSG FAA_ISR *** [CODE] C172 ::: [MAKE] CESSNA AIRCRAFT COMPANY ::: [MODEL] 172, P172, R172, Skyhawk, Hawk XP, Cutlass (T-41, Mescalero) ::: [ENGINE] 1/PistonProp ::: [WEIGHT] Small ::: [C/D] 600/1000 ::: [SRS] 1 | ||
|
||
Dictionary<string, string> weights = new Dictionary<string, string>() | ||
{ | ||
{"L", "Light" }, | ||
{"M", "Medium" }, | ||
{"H", "Heavy" }, | ||
{"L/M", "Light/Medium" }, | ||
{"J", "Super" } | ||
}; | ||
|
||
foreach (string acDesignator in uniqueACData.Keys) | ||
{ | ||
AircraftDataInformation currentAircraftData = uniqueACData[acDesignator]; | ||
// TODO - Figure out SRS and C/D | ||
try | ||
{ | ||
command = $".ACINFO{acDesignator} .MSG FAA_ISR *** [CODE] {acDesignator} ::: [MAKE] {currentAircraftData.ManufacturerCode} ::: [MODEL] {currentAircraftData.ModelFullName} ::: [ENGINE] {currentAircraftData.EngineCount}/{currentAircraftData.EngineType} ::: [WEIGHT] {weights[currentAircraftData.WTC]} ::: [C/D] ???/??? ::: [SRS] ???"; | ||
} | ||
catch (KeyNotFoundException e) | ||
{ | ||
Logger.LogMessage("WARNING", e.Message); | ||
command = $".ACINFO{acDesignator} .MSG FAA_ISR *** [CODE] {acDesignator} ::: [MAKE] {currentAircraftData.ManufacturerCode} ::: [MODEL] {currentAircraftData.ModelFullName} ::: [ENGINE] {currentAircraftData.EngineCount}/{currentAircraftData.EngineType} ::: [WEIGHT] {currentAircraftData.WTC} ::: [C/D] ???/??? ::: [SRS] ???"; | ||
} | ||
|
||
|
||
aliasFileSB.AppendLine(command); | ||
} | ||
|
||
File.WriteAllText(outputFilePath, aliasFileSB.ToString()); | ||
File.AppendAllText($"{GlobalConfig.outputDirectory}\\ALIAS\\AliasTestFile.txt", aliasFileSB.ToString()); | ||
} | ||
|
||
private Dictionary<string, AircraftDataInformation> getUniqueACData(AircraftDataRootObject aircraftData) | ||
{ | ||
Dictionary<string, AircraftDataInformation> uniqueAircraftData = new Dictionary<string, AircraftDataInformation>(); | ||
|
||
foreach (AircraftDataInformation acData in aircraftData.AllAircraftData) | ||
{ | ||
if (uniqueAircraftData.ContainsKey(acData.Designator)) | ||
{ | ||
AircraftDataInformation tempAircraftData = uniqueAircraftData[acData.Designator]; | ||
|
||
PropertyInfo[] properties = typeof(AircraftDataInformation).GetProperties(); | ||
foreach (PropertyInfo property in properties) | ||
{ | ||
bool acDataIsNull = property.GetValue(acData) is null; | ||
bool tempAircraftDataIsNull = property.GetValue(tempAircraftData) is null; | ||
|
||
if (!acDataIsNull && !tempAircraftDataIsNull) | ||
{ | ||
if (property.GetValue(tempAircraftData).ToString().Contains(",")) | ||
{ | ||
string[] propertyContains = property.GetValue(tempAircraftData).ToString().Split(","); | ||
|
||
if (propertyContains.Length > 0 && propertyContains.Contains(property.GetValue(acData).ToString())) | ||
{ | ||
continue; | ||
} | ||
} | ||
|
||
if (property.GetValue(acData).ToString() != property.GetValue(tempAircraftData).ToString()) | ||
{ | ||
property.SetValue(uniqueAircraftData[acData.Designator], property.GetValue(acData).ToString() + ", " + property.GetValue(tempAircraftData).ToString()); | ||
} | ||
} | ||
else if (acDataIsNull && !tempAircraftDataIsNull) | ||
{ | ||
property.SetValue(uniqueAircraftData[acData.Designator], property.GetValue(tempAircraftData).ToString()); | ||
} | ||
else if (!acDataIsNull && tempAircraftDataIsNull) | ||
{ | ||
property.SetValue(uniqueAircraftData[acData.Designator], property.GetValue(acData).ToString()); | ||
} | ||
else | ||
{ | ||
continue; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
uniqueAircraftData[acData.Designator] = acData; | ||
} | ||
} | ||
|
||
return uniqueAircraftData; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using FeBuddyLibrary.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FeBuddyLibrary.DataAccess | ||
{ | ||
public class GetAptWxData | ||
{ | ||
Dictionary<string, AptWxModel> AllAptWxModels = new Dictionary<string, AptWxModel>(); | ||
|
||
|
||
public Dictionary<string, AptWxModel> GetAptWxDataMain(string effectiveDate) | ||
{ | ||
ParseAptWxData(effectiveDate); | ||
return AllAptWxModels; | ||
} | ||
|
||
private void ParseAptWxData(string effectiveDate) | ||
{ | ||
foreach (string line in File.ReadLines($"{GlobalConfig.tempPath}\\{effectiveDate}_AWOS\\AWOS.txt")) | ||
{ | ||
// Check to make sure we are grabbing the AWOS1 stuff | ||
|
||
if (line.Substring(0, 5).Contains("AWOS1")) | ||
{ | ||
AptWxModel tempModel = new AptWxModel | ||
{ | ||
SensorIdent = line.Substring(5, 4).Trim(), | ||
SensorType = line.Substring(9, 10).Trim(), | ||
CommissioningStatus = line.Substring(19, 1).Trim(), | ||
NavaidFlag = line.Substring(30, 1).Trim(), | ||
StationLat = line.Substring(31, 14).Trim(), | ||
StationLon = line.Substring(45, 15).Trim(), | ||
Elevation = line.Substring(60, 7).Trim(), | ||
StationFreq = line.Substring(68, 7).Trim(), | ||
SecondStationFreq = line.Substring(75, 7).Trim() | ||
}; | ||
|
||
// Grab the Sensor Type UP to the '-' if it has one. | ||
if (tempModel.SensorType.Contains('-')) | ||
{ | ||
tempModel.SensorType = tempModel.SensorType.Split('-')[0]; | ||
} | ||
|
||
|
||
if (AllAptWxModels.ContainsKey(tempModel.SensorIdent)) | ||
{ | ||
if (tempModel.CommissioningStatus == "Y") | ||
{ | ||
if (!string.IsNullOrWhiteSpace(tempModel.StationFreq)) | ||
{ | ||
// If the station does not have a frequency do not add to alias command. | ||
AllAptWxModels[tempModel.SensorIdent] = tempModel; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
if (!string.IsNullOrWhiteSpace(tempModel.StationFreq)) | ||
{ | ||
// If the station does not have a frequency do not add to alias command. | ||
AllAptWxModels[tempModel.SensorIdent] = tempModel; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
continue; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.