Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #85 from Nikolai558/feature-req-83
Browse files Browse the repository at this point in the history
Feature Request #83
  • Loading branch information
Nikolai558 authored Mar 13, 2021
2 parents 8aa4491 + 10e7898 commit ce5813f
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 51 deletions.
2 changes: 1 addition & 1 deletion ClassData/DataAccess/GetFaaMetaFileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace ClassData.DataAccess
{
public class GetFaaMetaFileData
{
private List<MetaAirportModel> AllAirports = new List<MetaAirportModel>();
private List<MetaAirportModel> AllAirports = GlobalConfig.AllMetaFileAirports;

public void QuarterbackFunc()
{
Expand Down
180 changes: 180 additions & 0 deletions ClassData/DataAccess/PublicationParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
using ClassData.Models;
using ClassData.Models.MetaFileModels;
using NASARData;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassData.DataAccess
{
public class PublicationParser
{
// TODO - Populate this list from somewhere from some how.
public static List<string> allArtcc = GlobalConfig.allArtcc;

private string outputDirectory = GlobalConfig.outputDirectory + "PUBLICATIONS";

public void WriteAirportInfoTxt(string responsibleArtcc)
{
StringBuilder airportInArtccInfo = new StringBuilder();
StringBuilder airportProcedureChanges = new StringBuilder();
StringBuilder airportProcedures = new StringBuilder();

if (responsibleArtcc == "FAA")
{
foreach (string artcc in allArtcc)
{
if (artcc == "FAA")
{
continue;
}
// This creates our Airport list that the ARTCC is responsible for.
airportInArtccInfo = new StringBuilder();
airportProcedureChanges = new StringBuilder();
airportProcedures = new StringBuilder();
foreach (AptModel airport in GlobalConfig.allAptModelsForCheck)
{
if (airport.ResArtcc == artcc)
{
string airportInfo = $"{airport.Id} - {airport.Icao}";
airportInArtccInfo.AppendLine(airportInfo);
}
}
string airportsInArtccFilePath = $"{outputDirectory}\\{artcc}_{AiracDateCycleModel.AllCycleDates[GlobalConfig.airacEffectiveDate]}\\{artcc}_Airports.txt";
CreateDirAndFile(airportsInArtccFilePath);
File.WriteAllText(airportsInArtccFilePath, airportInArtccInfo.ToString());

// this will create our ALL publications and Changes Publications file.
foreach (MetaAirportModel apt in GlobalConfig.AllMetaFileAirports)
{
foreach (string resAirport in airportInArtccInfo.ToString().Split('\n'))
{
if (string.IsNullOrEmpty(resAirport))
{
continue;
}
string wantedAirport = resAirport.Substring(0, resAirport.IndexOf('-')).Trim();
if (wantedAirport == apt.AptIdent)
{
List<string> hasChanges = new List<string>();

airportProcedures.AppendLine($"[{apt.AptIdent}]");
foreach (MetaRecordModel recordModel in apt.Records)
{
airportProcedures.AppendLine($"\t{recordModel.ChartName} | https://aeronav.faa.gov/d-tpp/{AiracDateCycleModel.AllCycleDates[GlobalConfig.airacEffectiveDate]}/{recordModel.PdfName}");
if ((recordModel.UserAction != "" && recordModel.UserAction != " ") && !hasChanges.Contains(apt.AptIdent))
{
hasChanges.Add(apt.AptIdent);
}
}

if (hasChanges.Contains(apt.AptIdent))
{
airportProcedureChanges.AppendLine($"[{apt.AptIdent}]");
foreach (MetaRecordModel recordModel1 in apt.Records)
{
if (recordModel1.UserAction != "" && recordModel1.UserAction != " ")
{
airportProcedureChanges.AppendLine($"\t({recordModel1.UserAction}) {recordModel1.ChartName} | https://aeronav.faa.gov/d-tpp/{AiracDateCycleModel.AllCycleDates[GlobalConfig.airacEffectiveDate]}/compare_pdf/{recordModel1.PdfName.Substring(0, recordModel1.PdfName.Length - 4)}_cmp.pdf");
}
}
}
}
}
}
string ProcedureFilePath = $"{outputDirectory}\\{artcc}_{AiracDateCycleModel.AllCycleDates[GlobalConfig.airacEffectiveDate]}\\Procedures.txt";
CreateDirAndFile(ProcedureFilePath);
File.WriteAllText(ProcedureFilePath, airportProcedures.ToString());

string ProcedureChangefilePath = $"{outputDirectory}\\{artcc}_{AiracDateCycleModel.AllCycleDates[GlobalConfig.airacEffectiveDate]}\\Procedure_Changes.txt";
CreateDirAndFile(ProcedureChangefilePath);
File.WriteAllText(ProcedureChangefilePath, airportProcedureChanges.ToString());
}
}
else if (allArtcc.Contains(responsibleArtcc))
{
foreach (AptModel airport in GlobalConfig.allAptModelsForCheck)
{
if (airport.ResArtcc == responsibleArtcc)
{
string output = $"{airport.Id} - {airport.Icao}";
airportInArtccInfo.AppendLine(output);
}
}
string airportsInArtccFilePath = $"{outputDirectory}\\{responsibleArtcc}_{AiracDateCycleModel.AllCycleDates[GlobalConfig.airacEffectiveDate]}\\Res_Artcc_Airports.txt";
CreateDirAndFile(airportsInArtccFilePath);
File.WriteAllText(airportsInArtccFilePath, airportInArtccInfo.ToString());

foreach (MetaAirportModel apt in GlobalConfig.AllMetaFileAirports)
{
foreach (string resAirport in airportInArtccInfo.ToString().Split('\n'))
{
if (string.IsNullOrEmpty(resAirport))
{
continue;
}
string wantedAirport = resAirport.Substring(0, resAirport.IndexOf('-')).Trim();
if (wantedAirport == apt.AptIdent)
{
List<string> hasChanges = new List<string>();

airportProcedures.AppendLine($"[{apt.AptIdent}]");
foreach (MetaRecordModel recordModel in apt.Records)
{
airportProcedures.AppendLine($"\t{recordModel.ChartName} | https://aeronav.faa.gov/d-tpp/{AiracDateCycleModel.AllCycleDates[GlobalConfig.airacEffectiveDate]}/{recordModel.PdfName}");
if ((recordModel.UserAction != "" && recordModel.UserAction != " ") && !hasChanges.Contains(apt.AptIdent))
{
hasChanges.Add(apt.AptIdent);
}
}

if (hasChanges.Contains(apt.AptIdent))
{
airportProcedureChanges.AppendLine($"[{apt.AptIdent}]");
foreach (MetaRecordModel recordModel1 in apt.Records)
{
if (recordModel1.UserAction != "" && recordModel1.UserAction != " ")
{
airportProcedureChanges.AppendLine($"\t({recordModel1.UserAction}) {recordModel1.ChartName} | https://aeronav.faa.gov/d-tpp/{AiracDateCycleModel.AllCycleDates[GlobalConfig.airacEffectiveDate]}/compare_pdf/{recordModel1.PdfName.Substring(0, recordModel1.PdfName.Length - 4)}_cmp.pdf");
}
}
}
}
}
}

string ProcedureFilePath = $"{outputDirectory}\\{responsibleArtcc}_{AiracDateCycleModel.AllCycleDates[GlobalConfig.airacEffectiveDate]}\\Procedures.txt";
CreateDirAndFile(ProcedureFilePath);
File.WriteAllText(ProcedureFilePath, airportProcedures.ToString());

string ProcedureChangefilePath = $"{outputDirectory}\\{responsibleArtcc}_{AiracDateCycleModel.AllCycleDates[GlobalConfig.airacEffectiveDate]}\\Procedure_Changes.txt";
CreateDirAndFile(ProcedureChangefilePath);
File.WriteAllText(ProcedureChangefilePath, airportProcedureChanges.ToString());
}
else
{
throw new NotImplementedException();
}
}

/// <summary>
/// Create the Directories and File for the full file path put in.
/// </summary>
/// <param name="fullFilePath">Full File Path</param>
private void CreateDirAndFile(string fullFilePath)
{
if (!Directory.Exists(fullFilePath.Substring(0, fullFilePath.LastIndexOf('\\'))))
{
Directory.CreateDirectory(fullFilePath.Substring(0, fullFilePath.LastIndexOf('\\')));
}

if (!File.Exists(fullFilePath))
{
//File.Create(fullFilePath);
}
}
}
}
11 changes: 11 additions & 0 deletions ClassData/GlobalConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public class GlobalConfig
// Temp path for the user. ie: C:\Users\nik\AppData\Local\Temp\NASR_TO_SCT
public static readonly string tempPath = $"{Path.GetTempPath()}NASR2SCT";

public static List<MetaAirportModel> AllMetaFileAirports = new List<MetaAirportModel>();

public static string facilityID;

public static List<string> allArtcc = new List<string>() {
"FAA","FIM","SBA","ZAB","ZAK","ZAN","ZAP","ZAU","ZBW","ZDC","ZDV","ZEG","ZFW","ZHN",
"ZHU","ZID","ZJX","ZKC","ZLA","ZLC","ZMA","ZME","ZMP","ZNY","ZOA","ZOB","ZSE","ZSU",
"ZTL","ZUA","ZUL","ZVR","ZWG","ZYZ"
};

public static bool GetMetaUrlResponse()
{
string nextUrl = $"https://aeronav.faa.gov/d-tpp/{AiracDateCycleModel.AllCycleDates[nextAiracDate]}/xml_data/d-tpp_Metafile.xml";
Expand Down Expand Up @@ -130,6 +140,7 @@ public static void CheckTempDir(bool onlyCreateTempFolder)

public static void DownloadAllFiles(string effectiveDate, string airacCycle)
{
DownloadedFilePaths = new List<string>();
Dictionary<string, string> allURLs = new Dictionary<string, string>()
{
{ $"{effectiveDate}_STARDP.zip", $"https://nfdc.faa.gov/webContent/28DaySub/{effectiveDate}/STARDP.zip" },
Expand Down
4 changes: 4 additions & 0 deletions ClassData/NASARData.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<Compile Include="DataAccess\GetFixData.cs" />
<Compile Include="DataAccess\GetNavData.cs" />
<Compile Include="DataAccess\GetStarDpData.cs" />
<Compile Include="DataAccess\PublicationParser.cs" />
<Compile Include="GlobalConfig.cs" />
<Compile Include="Models\Airport.cs" />
<Compile Include="Models\AirwayModel.cs" />
Expand Down Expand Up @@ -92,5 +93,8 @@
<ItemGroup>
<Content Include="NASR_2_SCT_icon.ico" />
</ItemGroup>
<ItemGroup>
<Folder Include="Static\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit ce5813f

Please sign in to comment.