2022-02-09 17:59:02 +00:00
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
2022-02-11 17:00:08 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
using System.Net.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2022-02-09 20:40:24 +00:00
|
|
|
using Newtonsoft.Json;
|
2022-02-11 17:00:08 +00:00
|
|
|
using EFB.Models;
|
|
|
|
using EFB.Models.JSON;
|
|
|
|
using EFB.Sessions;
|
|
|
|
using EFB.Controllers.Form;
|
|
|
|
using EFB.Controllers.API;
|
2022-02-09 17:59:02 +00:00
|
|
|
|
|
|
|
namespace EFB.Models
|
|
|
|
{
|
|
|
|
public class ChartModel
|
|
|
|
{
|
2022-02-11 19:54:11 +00:00
|
|
|
public string ICAO { get; set; }
|
2022-02-09 17:59:02 +00:00
|
|
|
public Chart[] General { get; set; }
|
|
|
|
public Chart[] TextualData { get; set; }
|
|
|
|
public Chart[] GroundLayout { get; set; }
|
|
|
|
public Chart[] SID { get; set; }
|
|
|
|
public Chart[] STAR { get; set; }
|
|
|
|
public Chart[] Approach { get; set; }
|
|
|
|
public Chart[] Transition { get; set; }
|
|
|
|
public Chart[] PilotBriefing { get; set; }
|
2022-02-09 20:40:24 +00:00
|
|
|
|
|
|
|
[JsonConstructor]
|
|
|
|
public ChartModel(){
|
|
|
|
//Empty constructor for JSON Serialisation Purposes
|
|
|
|
}
|
2022-02-11 19:54:11 +00:00
|
|
|
public ChartModel(string ICAO, ChartList response)
|
2022-02-09 20:19:32 +00:00
|
|
|
{
|
2022-02-11 19:54:11 +00:00
|
|
|
this.ICAO = ICAO;
|
2022-02-09 20:19:32 +00:00
|
|
|
General = FillChart(response.General);
|
|
|
|
TextualData = FillChart(response.TextualData);
|
|
|
|
GroundLayout = FillChart(response.GroundLayout);
|
|
|
|
SID = FillChart(response.SID);
|
|
|
|
STAR = FillChart(response.STAR);
|
|
|
|
Approach = FillChart(response.Approach);
|
|
|
|
Transition = FillChart(response.Transition);
|
|
|
|
PilotBriefing = FillChart(response.PilotBriefing);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Chart[] FillChart(ChartsCollection collection){
|
|
|
|
if (collection != null)
|
|
|
|
{
|
|
|
|
return collection.Charts;
|
|
|
|
}
|
|
|
|
return new Chart[]{};
|
|
|
|
}
|
2022-02-11 17:00:08 +00:00
|
|
|
|
|
|
|
public static async Task<ChartList> FetchAsync(string ICAO){
|
|
|
|
Console.WriteLine("Start");
|
|
|
|
if (FormAuthenticator.ValidateICAOCode(ICAO))
|
|
|
|
{
|
|
|
|
APIInterface API = new APIInterface();
|
|
|
|
Dictionary <string, string> headerData = new Dictionary<string, string>();
|
|
|
|
headerData.Add("referer", "luke-else.co.uk");
|
|
|
|
|
|
|
|
Dictionary<string, string> formData = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
formData.Add("token", Environment.GetEnvironmentVariable("ChartFoxAPIKey", EnvironmentVariableTarget.User));
|
|
|
|
FormUrlEncodedContent body = new FormUrlEncodedContent(formData);
|
|
|
|
|
|
|
|
//make Charts request
|
|
|
|
var requestCharts = await API.Post<ChartResponse>($"https://chartfox.org/api/charts/grouped/{ICAO}", headerData, body);
|
|
|
|
Console.WriteLine("End");
|
2022-02-11 19:40:31 +00:00
|
|
|
if (requestCharts.Result.Status == "success")
|
|
|
|
{
|
|
|
|
return requestCharts.Result.Response;
|
|
|
|
}
|
2022-02-11 17:00:08 +00:00
|
|
|
}
|
2022-02-11 19:40:31 +00:00
|
|
|
return null;
|
2022-02-11 17:00:08 +00:00
|
|
|
}
|
2022-02-09 17:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public class Pinned
|
|
|
|
{
|
|
|
|
public Chart[] Charts { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
// public class Chart *Found in Models/JSON*
|
|
|
|
// {
|
|
|
|
// public string Name { get; set; }
|
|
|
|
// public string Identifier { get; set; }
|
|
|
|
// public int TypeCode { get; set; }
|
|
|
|
// public string Type { get; set; }
|
|
|
|
// public string Runway { get; set; }
|
|
|
|
// public string PseudoURL { get; set; }
|
|
|
|
// public string URL { get; set; }
|
|
|
|
// }
|
2022-02-09 20:19:32 +00:00
|
|
|
|
2022-02-09 17:59:02 +00:00
|
|
|
}
|