2 Commits

Author SHA1 Message Date
1fc6d2bbcd Updated port on docker-compose.yml file 2022-02-23 22:16:23 +00:00
3f9bf384b0 Setup for docker use 2022-02-19 21:26:31 +00:00
37 changed files with 480 additions and 274 deletions

24
.dockerignore Normal file
View File

@ -0,0 +1,24 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
README.md

14
.vscode/launch.json vendored
View File

@ -2,19 +2,14 @@
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net5.0/EFB.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
@ -30,6 +25,15 @@
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
},
{
"name": "Docker .NET Core Launch",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"netCore": {
"appProject": "${workspaceFolder}/EFB.csproj"
}
}
]
}

56
.vscode/tasks.json vendored
View File

@ -37,6 +37,62 @@
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"type": "docker-build",
"label": "docker-build: debug",
"dependsOn": [
"build"
],
"dockerBuild": {
"tag": "efb:dev",
"target": "base",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
},
"netCore": {
"appProject": "${workspaceFolder}/EFB.csproj"
}
},
{
"type": "docker-build",
"label": "docker-build: release",
"dependsOn": [
"build"
],
"dockerBuild": {
"tag": "efb:latest",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
},
"netCore": {
"appProject": "${workspaceFolder}/EFB.csproj"
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build: debug"
],
"dockerRun": {},
"netCore": {
"appProject": "${workspaceFolder}/EFB.csproj",
"enableDebugging": true
}
},
{
"type": "docker-run",
"label": "docker-run: release",
"dependsOn": [
"docker-build: release"
],
"dockerRun": {},
"netCore": {
"appProject": "${workspaceFolder}/EFB.csproj"
}
}
]
}

View File

@ -1,8 +1,10 @@
using EFB.Models;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Net.Http;
using EFB.Models;
namespace EFB.Controllers.API
{
@ -10,10 +12,10 @@ namespace EFB.Controllers.API
{
private HttpClient HttpClient { get; set; }
public async Task<ResponseModel<T>> Get<T>(string Endpoint, Dictionary<string, string> Headers)
{
//Create the HTTP client used for the GetRequest.
public async Task<ResponseModel<T>> Get<T>(string Endpoint, Dictionary<string, string> Headers){
this.HttpClient = new HttpClient();
this.HttpClient.DefaultRequestHeaders.Clear();
if (Headers != null)
@ -28,9 +30,10 @@ namespace EFB.Controllers.API
{
try
{
//Get the response from the server
var pendingResult = this.HttpClient.GetAsync(Endpoint);
var result = await pendingResult;
string resultString = result.Content.ReadAsStringAsync().Result;
//Assess return value (object or raw string)
@ -40,29 +43,30 @@ namespace EFB.Controllers.API
{//If the user requests string for return type
response = JsonConvert.DeserializeObject<T>(resultString);
}
return new ResponseModel<T>()
{
return new ResponseModel<T>(){
//Sender should be aware of type T becuase of Generic type
Result = (T)response
};
}
catch (System.Exception e)
{
return new ResponseModel<T> { Error = e.Message };
}
}
//Returned in the event No other response has been returned
return new ResponseModel<T> { Error = "Invalid Endpoint - Please try again later" };
return new ResponseModel<T>{Error = e.Message};
}
public async Task<ResponseModel<T>> Post<T>(string Endpoint, Dictionary<string, string> Headers, HttpContent Body)
{
//Create a HTTP client to allow for making Post requests
}
//Returned in the event No other response has been returned
return new ResponseModel<T>{Error = "Invalid Endpoint - Please try again later"};
}
public async Task<ResponseModel<T>> Post<T>(string Endpoint, Dictionary<string, string> Headers, HttpContent Body){
this.HttpClient = new HttpClient();
this.HttpClient.DefaultRequestHeaders.Clear();
if (Headers != null)
{//Go through and add each header to the HTTP Client
{
foreach (var Header in Headers)
{
this.HttpClient.DefaultRequestHeaders.Add(Header.Key, Header.Value);
@ -71,11 +75,11 @@ namespace EFB.Controllers.API
if (Form.FormAuthenticator.ValidateEndpoint(Endpoint))
{
try
{//Try statement to catch errors in the process of making the request
try{//Try statement to catch errors in the process of making the request
var pendingResult = this.HttpClient.PostAsync(Endpoint, Body);
var result = await pendingResult;
string resultString = result.Content.ReadAsStringAsync().Result;
object response = resultString;
if (typeof(T) != typeof(string))
@ -83,28 +87,28 @@ namespace EFB.Controllers.API
response = JsonConvert.DeserializeObject<T>(resultString);
}
return new ResponseModel<T>()
{
return new ResponseModel<T>(){
//Sender should be aware of type T becuase of Generic type
Result = (T)response
};
}
catch (System.Exception e)
{
return new ResponseModel<T> { Error = e.Message };
}catch(System.Exception e){
return new ResponseModel<T>{Error = e.Message};
}
}
//Returned in the event No other response has been returned
return new ResponseModel<T> { Error = "Invalid Endpoint - Please try again later" };
return new ResponseModel<T>{Error = "Invalid Endpoint - Please try again later"};
}
public async Task<ResponseModel<T>> Put<T>(string Endpoint, Dictionary<string, string> Headers, HttpContent Body)
{
//Create HTTP client to allow for HttpRequests
public async Task<ResponseModel<T>> Put<T>(string Endpoint, Dictionary<string, string> Headers, HttpContent Body){
this.HttpClient = new HttpClient();
this.HttpClient.DefaultRequestHeaders.Clear();
if (Headers != null)
{//Loop through and add each heder to the HTTP client
{
foreach (var Header in Headers)
{
this.HttpClient.DefaultRequestHeaders.Add(Header.Key, Header.Value);
@ -113,13 +117,11 @@ namespace EFB.Controllers.API
if (Form.FormAuthenticator.ValidateEndpoint(Endpoint))
{
try
{//Try statement to catch errors in the process of making the request
try{//Try statement to catch errors in the process of making the request
var pendingResult = this.HttpClient.PutAsync(Endpoint, Body);
var result = await pendingResult;
string resultString = result.Content.ReadAsStringAsync().Result;
//Recieve the response as a string which will be morphed in other types
object response = resultString;
if (typeof(T) != typeof(string))
@ -127,21 +129,20 @@ namespace EFB.Controllers.API
response = JsonConvert.DeserializeObject<T>(resultString);
}
return new ResponseModel<T>()
{
return new ResponseModel<T>(){
//Sender should be aware of type T becuase of Generic type
Result = (T)response
};
}
catch (System.Exception e)
{
return new ResponseModel<T> { Error = e.Message };
}catch(System.Exception e){
return new ResponseModel<T>{Error = e.Message};
}
}
//Returned in the event No other response has been returned
return new ResponseModel<T> { Error = "Invalid Endpoint - Please try again later" };
return new ResponseModel<T>{Error = "Invalid Endpoint - Please try again later"};
}
}
}

View File

@ -1,8 +1,13 @@
using EFB.Models;
using EFB.Sessions;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using EFB.Models;
using Microsoft.AspNetCore.Http;
using EFB.Sessions;
namespace EFB.Controllers
{

View File

@ -1,9 +1,14 @@
using EFB.Controllers.Form;
using EFB.Models;
using EFB.Sessions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using EFB.Models;
using EFB.Models.JSON;
using EFB.Controllers.Form;
using EFB.Sessions;
namespace EFB.Controllers
{
@ -26,7 +31,7 @@ namespace EFB.Controllers
return RedirectToAction("Index", "Home");
}
if (ICAO == null)
if(ICAO == null)
return View();
if (FormAuthenticator.ValidateICAOCode(ICAO))
@ -40,16 +45,14 @@ namespace EFB.Controllers
HttpContext.Session.SetObject("User", user);
return RedirectToAction("ViewCharts");
}
}
else
}else
{
TempData["Error"] = "Invalid ICAO";
}
return View();
}
public IActionResult ViewCharts(string chart)
{
public IActionResult ViewCharts(string chart){
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
if (user != null)
{

View File

@ -1,11 +1,14 @@
using EFB.Models;
using EFB.Models.Route;
using EFB.MongoData;
using EFB.Sessions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EFB.Sessions;
using Microsoft.Extensions.Logging;
using EFB.Models;
using EFB.MongoData;
using EFB.Models.Route;
namespace EFB.Controllers
{
@ -23,15 +26,13 @@ namespace EFB.Controllers
{
//Retrieve and Check current user status
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
if (user == null)
{
if(user == null){
TempData["Error"] = "You must be logged in before you are able to view the FlightSim Page";
return RedirectToAction("Index", "Home");
}
//Retrieve the user's latest sim position and construct it into FlightsimModel
if (user.Route == null)
{
if (user.Route == null){
TempData["Error"] = "You must have a route planned before you are able to view the Flightsim page";
return RedirectToAction("Index", "Route");
}
@ -45,8 +46,7 @@ namespace EFB.Controllers
}
private IWaypoint DetermineClosest(RouteModel route, SimPosition currentPosition)
{
private IWaypoint DetermineClosest(RouteModel route, SimPosition currentPosition){
IWaypoint closest = null;
float closestDistance = float.MaxValue;
//Assuming that we are on the earth for simplicity
@ -60,8 +60,8 @@ namespace EFB.Controllers
float latitude1 = DegreesToRadians(currentPosition.Latitude);
float latitude2 = DegreesToRadians(waypoint.Latitude);
var a = Math.Sin(distanceLat / 2) * Math.Sin(distanceLat / 2) + Math.Sin(distanceLon / 2) * Math.Sin(distanceLon / 2) * Math.Cos(latitude1) * Math.Cos(latitude2);
var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
var a = Math.Sin(distanceLat/2) * Math.Sin(distanceLat/2) + Math.Sin(distanceLon/2) * Math.Sin(distanceLon/2) * Math.Cos(latitude1) * Math.Cos(latitude2);
var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1-a));
float distance = (float)(earthRadius * c);
@ -74,8 +74,7 @@ namespace EFB.Controllers
}
return closest;
}
private float DegreesToRadians(float degrees)
{
private float DegreesToRadians(float degrees){
return (float)(degrees * Math.PI / 180);
}

View File

@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EFB.Controllers.Form
{
public static class FormAuthenticator
{
public static bool ValidateEMail(string EMail)
{
public static bool ValidateEMail(string EMail){
if (EMail != null && EMail.Contains("@") && EMail.Contains(".") && !EMail.Contains(" "))
{
if (EMail.Count(x => x == '@') == 1)
@ -17,8 +19,7 @@ namespace EFB.Controllers.Form
return false;
}
public static bool ValidateEndpoint(string Endpoint)
{
public static bool ValidateEndpoint(string Endpoint){
//If it contains http & :// it can be either https or http
if (Endpoint.Contains("http") && Endpoint.Contains("://") && Endpoint.Length > 7)
{
@ -27,8 +28,7 @@ namespace EFB.Controllers.Form
return false;
}
public static bool ValidateICAOCode(string ICAO)
{
public static bool ValidateICAOCode(string ICAO){
if (ICAO.Length == 4)
{
//If the value contains a Number, then the value will return false
@ -37,8 +37,7 @@ namespace EFB.Controllers.Form
return false;
}
public static bool ValidateCruiseAlt(uint CruiseAlt)
{
public static bool ValidateCruiseAlt(uint CruiseAlt){
if (CruiseAlt > 0 && CruiseAlt < 50000)
{
return true;

View File

@ -1,9 +1,11 @@
using EFB.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.AspNetCore.Http;
using EFB.Sessions;
using System.Linq;
using System.Threading.Tasks;
namespace EFB.Controllers
{
@ -18,10 +20,6 @@ namespace EFB.Controllers
public IActionResult Index()
{
//Ensure that the user is not already logged in
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
if (user != null) return RedirectToAction("Index", "App");
return View();
}

View File

@ -1,8 +1,12 @@
using EFB.Models;
using EFB.Sessions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using EFB.Models;
using EFB.Sessions;
namespace EFB.Controllers
{
@ -28,12 +32,12 @@ namespace EFB.Controllers
if (HttpContext.Session.GetObject<NavdataModel[]>("Navdata") == null)
{//If the navdata needs re-caching
data = await NavdataModel.Populate();
HttpContext.Session.SetObject("Navdata", NavdataModel.MergeSort(ref data, 0, data.Length - 1));
HttpContext.Session.SetObject("Navdata", NavdataModel.MergeSort(ref data, 0, data.Length-1));
}
//get the data out of tempdata and cast it into an array
data = HttpContext.Session.GetObject<NavdataModel[]>("Navdata");
NavdataModel navaid = NavdataModel.BinarySearch(ref data, 0, data.Length - 1, identifier);
NavdataModel navaid = NavdataModel.BinarySearch(ref data, 0, data.Length-1, identifier);
if (navaid == null)
{

View File

@ -1,17 +1,18 @@
using EFB.Controllers.API;
using EFB.Controllers.Form;
using System;
using System.Threading.Tasks;
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;
using Newtonsoft.Json;
using EFB.Models;
using EFB.Models.JSON;
using EFB.Sessions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using EFB.Controllers.Form;
using EFB.Controllers.API;
namespace EFB.Controllers
{

View File

@ -1,13 +1,15 @@
using EFB.Controllers.API;
using EFB.Models;
using EFB.Models.JSON;
using EFB.Sessions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.Net.Http;
using EFB.Models.JSON;
using Microsoft.Extensions.Logging;
using EFB.Models;
using EFB.Sessions;
using EFB.Controllers.API;
namespace EFB.Controllers
{
@ -26,11 +28,8 @@ namespace EFB.Controllers
return View();
}
public async Task<IActionResult> Login(string email, string password)
{
//Ensure that the user is not already logged in
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
if (user != null) return RedirectToAction("Index", "App");
public async Task<IActionResult> Login(string email, string password){
if (!Form.FormAuthenticator.ValidateEMail(email))
{
@ -72,11 +71,9 @@ namespace EFB.Controllers
return RedirectToAction("Index", "Home");
}
user = new UserModel
{
UserModel user = new UserModel{
EMail = email,
UserToken = new TokenModel
{
UserToken = new TokenModel{
TokenValue = login.access_token,
Expiration = DateTime.UtcNow.AddSeconds(login.expires_in)
}
@ -85,10 +82,10 @@ namespace EFB.Controllers
//Using Session Extensions (Store the user session)
HttpContext.Session.SetObject("User", user);
return RedirectToAction("Index", "App");
}
public IActionResult Logout()
{
public IActionResult Logout(){
HttpContext.Session.SetObject("User", null);
return RedirectToAction("Index", "Home");
}

26
Dockerfile Normal file
View File

@ -0,0 +1,26 @@
FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /src
COPY ["EFB.csproj", "./"]
RUN dotnet restore "EFB.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "EFB.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "EFB.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "EFB.dll"]

View File

@ -1,6 +1,8 @@
using libmetar.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using libmetar.Services;
namespace EFB.Metar
{
@ -10,13 +12,11 @@ namespace EFB.Metar
private static TafService tafService { get; set; } = new TafService();
public static async Task<string> GetMETAR(string ICAO)
{
public static async Task<string> GetMETAR(string ICAO){
return (await metarService.GetRawAsync(ICAO)).Raw;
}
public static async Task<List<string>> GetTAF(string ICAO)
{
public static async Task<List<string>> GetTAF(string ICAO){
var downloadedTAF = (await tafService.GetRawAsync(ICAO)).RawSplit;
List<string> TAF = new List<string>();

View File

@ -1,11 +1,18 @@
using EFB.Controllers.API;
using EFB.Controllers.Form;
using EFB.Models.JSON;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
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;
using Newtonsoft.Json;
using EFB.Models;
using EFB.Models.JSON;
using EFB.Sessions;
using EFB.Controllers.Form;
using EFB.Controllers.API;
namespace EFB.Models
{
@ -22,8 +29,7 @@ namespace EFB.Models
public Chart[] PilotBriefing { get; set; }
[JsonConstructor]
public ChartModel()
{
public ChartModel(){
//Empty constructor for JSON Serialisation Purposes
}
public ChartModel(string ICAO, ChartList response)
@ -39,27 +45,25 @@ namespace EFB.Models
PilotBriefing = FillChart(response.PilotBriefing);
}
private Chart[] FillChart(ChartsCollection collection)
{
private Chart[] FillChart(ChartsCollection collection){
if (collection != null)
{
return collection.Charts;
}
return new Chart[] { };
return new Chart[]{};
}
public static async Task<ChartList> FetchAsync(string ICAO)
{
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>();
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));
formData.Add("token", Environment.GetEnvironmentVariable("ChartFoxAPIKey"));
FormUrlEncodedContent body = new FormUrlEncodedContent(formData);
//make Charts request

View File

@ -1,3 +1,5 @@
using System;
namespace EFB.Models
{
public class ErrorViewModel

View File

@ -1,3 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EFB.Models.Route;
namespace EFB.Models

View File

@ -1,3 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace EFB.Models.JSON

View File

@ -1,4 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using System.Threading.Tasks;
namespace EFB.Models.JSON
{

View File

@ -1,3 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace EFB.Models.JSON

View File

@ -1,3 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace EFB.Models.JSON

View File

@ -1,9 +1,11 @@
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc;
using EFB.Sessions;
namespace EFB.Models
{
@ -17,8 +19,7 @@ namespace EFB.Models
public string Longitude { get; set; }
public NavdataModel(int id, string name, string type, string latitude, string longitude)
{
public NavdataModel(int id, string name, string type, string latitude, string longitude){
Id = id;
Name = name;
Type = type;
@ -28,8 +29,7 @@ namespace EFB.Models
}
[JsonConstructor]
public NavdataModel(int id, string name, string type, int? frequency, string latitude, string longitude)
{
public NavdataModel(int id, string name, string type, int? frequency, string latitude, string longitude){
Id = id;
Name = name;
Type = type;
@ -38,9 +38,8 @@ namespace EFB.Models
Longitude = longitude;
}
public static async Task<NavdataModel[]> Populate()
{
string password = Environment.GetEnvironmentVariable("MySQLPassword", EnvironmentVariableTarget.User);
public static async Task<NavdataModel[]> Populate(){
string password = Environment.GetEnvironmentVariable("MySQLPassword");
MySqlConnection con = new MySqlConnection($"server=server.luke-else.co.uk;userid=root;password={password};database=EFB");
con.Open();
@ -49,7 +48,7 @@ namespace EFB.Models
string query = "SELECT * FROM waypoints";
MySqlCommand command = new MySqlCommand(query, con);
MySqlDataReader reader = (MySqlDataReader)await command.ExecuteReaderAsync();
MySqlDataReader reader = (MySqlDataReader) await command.ExecuteReaderAsync();
List<NavdataModel> navdata = new List<NavdataModel>();
@ -68,9 +67,7 @@ namespace EFB.Models
navdata.Add(
new NavdataModel(id, name, type, frequency, latitude, longitude)
);
}
else
{
}else{
navdata.Add(
new NavdataModel(id, name, type, latitude, longitude)
);
@ -80,14 +77,13 @@ namespace EFB.Models
return navdata.ToArray<NavdataModel>();
}
public static NavdataModel BinarySearch(ref NavdataModel[] data, int start, int end, string target)
{
public static NavdataModel BinarySearch(ref NavdataModel[] data, int start, int end, string target){
int midpoint = start + ((end - start) / 2);
target = target.ToUpper().Trim();
string mid = data[midpoint].Name;
if (start == end - 1)
if (start == end-1)
{
if (mid == target)
{
@ -114,31 +110,26 @@ namespace EFB.Models
//Split the data down to the left and the right portions
NavdataModel[] left = MergeSort(ref data, start, midpoint);
NavdataModel[] right = MergeSort(ref data, midpoint + 1, end);
NavdataModel[] right = MergeSort(ref data, midpoint+1, end);
List<NavdataModel> combined = new List<NavdataModel>();
int leftPointer = 0;
int rightPointer = 0;
while (leftPointer <= left.Length - 1 || rightPointer <= right.Length - 1)
while (leftPointer <= left.Length-1 || rightPointer <= right.Length-1)
{
if (leftPointer == left.Length)
{//Take a value only from the right (left pointer had reached the end)
AddValue(ref combined, right[rightPointer], ref rightPointer);
}
else if (rightPointer == right.Length)
}else if (rightPointer == right.Length)
{//Take a value only from the left (right pointer has reached the end)
AddValue(ref combined, left[leftPointer], ref leftPointer);
}
else
{
}else{
if (String.Compare(left[leftPointer].Name, right[rightPointer].Name) <= 0)
{//Take a value from the left hand side of the list. (Left value is considered 'smaller')
AddValue(ref combined, left[leftPointer], ref leftPointer);
}
else
{//Take a value from the right (right value is considered smaller)
}else{//Take a value from the right (right value is considered smaller)
AddValue(ref combined, right[rightPointer], ref rightPointer);
}
}
@ -148,8 +139,7 @@ namespace EFB.Models
}
private static void AddValue(ref List<NavdataModel> data, NavdataModel value, ref int pointer)
{
private static void AddValue(ref List<NavdataModel> data, NavdataModel value, ref int pointer){
pointer++;
data.Add(value);
}

View File

@ -1,3 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EFB.Models
{
public class ResponseModel<T>

View File

@ -1,3 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EFB.Models.Route
{
public interface IWaypoint

View File

@ -1,6 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EFB.Models.Route
{
public class NavaidModel : IWaypoint
public class NavaidModel:IWaypoint
{
public string Name { get; set; }
public float Longitude { get; set; }
@ -12,8 +17,7 @@ namespace EFB.Models.Route
public IWaypoint Previous { get; set; } = null;
public bool Visited { get; set; } = false;
public NavaidModel(string name, string airway, float longitude, float latitude)
{
public NavaidModel(string name, string airway, float longitude, float latitude){
Name = name;
Airway = airway;
Longitude = longitude;

View File

@ -1,6 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EFB.Models.Route
{
public class WaypointModel : IWaypoint
public class WaypointModel:IWaypoint
{
public string Name { get; set; }
public float Longitude { get; set; }
@ -11,8 +16,7 @@ namespace EFB.Models.Route
public IWaypoint Previous { get; set; } = null;
public bool Visited { get; set; }
public WaypointModel(string name, string airway, float longitude, float latitude)
{
public WaypointModel(string name, string airway, float longitude, float latitude){
Name = name;
Airway = airway;
Longitude = longitude;

View File

@ -1,6 +1,10 @@
using EFB.Controllers.Form;
using EFB.Models.Route;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EFB.Models.Route;
using EFB.Controllers.Form;
using System.Net.Http;
namespace EFB.Models
{
@ -15,8 +19,7 @@ namespace EFB.Models
public WaypointModel Arrival { get; set; } = null;
public IWaypoint Current { get; set; } = null;
public uint Cruise { get; set; } = 0;
public RouteModel(string departure, string departureRoute, string arrival, string arrivalRoute, uint cruise)
{
public RouteModel(string departure, string departureRoute, string arrival, string arrivalRoute, uint cruise){
if (FormAuthenticator.ValidateICAOCode(departure))
{
Departure = new WaypointModel(departure, departureRoute, 0, 0);
@ -33,20 +36,16 @@ namespace EFB.Models
}
}
public IWaypoint Next()
{
if (Current.Next != null)
{
public IWaypoint Next(){
if(Current.Next != null){
Current = Current.Next;
return Current;
}
return null;
}
public IWaypoint Previous()
{
if (Current.Previous != null)
{
public IWaypoint Previous(){
if(Current.Previous != null){
Current = Current.Previous;
return Current;
}
@ -54,8 +53,7 @@ namespace EFB.Models
}
//Generate a route Object
public static async Task<RouteModel> StringToRoute(string departure, string arrival, uint cruise, string routeString)
{
public static async Task<RouteModel> StringToRoute(string departure, string arrival, uint cruise, string routeString){
var navdataFetch = NavdataModel.Populate();
string[] routeTemp = routeString.Split(" ");
@ -71,10 +69,10 @@ namespace EFB.Models
NavdataModel[] navdata = await navdataFetch;
navdata = NavdataModel.MergeSort(ref navdata, 0, navdata.Length - 1);
for (var i = 1; i < routeTemp.Length - 1; i += 2)
for (var i = 1; i < routeTemp.Length-1; i+=2)
{//Already used first item, continue itterating over every other item
IWaypoint next;
NavdataModel currentWaypoint = NavdataModel.BinarySearch(ref navdata, 0, navdata.Length - 1, routeTemp[i]);
NavdataModel currentWaypoint = NavdataModel.BinarySearch(ref navdata, 0, navdata.Length-1, routeTemp[i]);
if (currentWaypoint == null)
{
currentWaypoint = new NavdataModel(0, routeTemp[i], null, "0", "0");
@ -84,16 +82,15 @@ namespace EFB.Models
{//waypoint Type
next = new WaypointModel(
routeTemp[i],
routeTemp[i + 1],
routeTemp[i+1],
float.Parse(currentWaypoint.Longitude),
float.Parse(currentWaypoint.Latitude)
);
}
else
}else
{//Navaid Type
next = new NavaidModel(
routeTemp[i],
routeTemp[i + 1],
routeTemp[i+1],
float.Parse(currentWaypoint.Longitude),
float.Parse(currentWaypoint.Latitude)
);
@ -126,8 +123,7 @@ namespace EFB.Models
//Generate a route String
public static string ParseRoute(string route)
{
public static string ParseRoute(string route){
route.Replace('/', ' ');
var routeArr = route.Split(' ');

View File

@ -1,6 +1,10 @@
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using MongoDB.Driver;
namespace EFB.Models
{
@ -12,8 +16,7 @@ namespace EFB.Models
public DateTime LatestPacketUpdate { get; set; }
public SimPosition LatestPosition { get; set; } = null;
public SimPositionModel(string email, SimPosition position)
{
public SimPositionModel(string email, SimPosition position){
EMail = email;
LatestPacketUpdate = DateTime.Now;
LatestPosition = position;
@ -28,8 +31,7 @@ namespace EFB.Models
public float Longitude { get; set; }
public int Altitude { get; set; }
public SimPosition(float latitude, float longitude, int altitude)
{
public SimPosition(float latitude, float longitude, int altitude){
Latitude = latitude;
Longitude = longitude;
Altitude = altitude;

View File

@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EFB.Models
{
@ -10,8 +13,7 @@ namespace EFB.Models
public string TokenValue { get; init; }
public DateTime Expiration { get; init; }
public bool IsExpired()
{
public bool IsExpired(){
//Check if the current time is beyond expiration
if (DateTime.UtcNow > Expiration)
{

View File

@ -1,3 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EFB.Models
{
public class UserModel

View File

@ -1,5 +1,14 @@
using EFB.Models.JSON;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Razor;
using Newtonsoft.Json;
using EFB.Models.JSON;
using Microsoft.AspNetCore;
using EFB.Sessions;
namespace EFB.Models
{
@ -8,8 +17,7 @@ namespace EFB.Models
public ChartModel Charts { get; set; }
public Chart Selected { get; set; }
public ViewChartModel(ChartModel current, string selected)
{
public ViewChartModel(ChartModel current, string selected){
Charts = current;
if (selected != null)
{

View File

@ -1,29 +1,29 @@
using EFB.Models;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Bson;
using EFB.Models;
namespace EFB.MongoData
{
public class Mongo
{
//function that is responsible to getting the user's latest sim position from the MongoDB
public static async Task<SimPositionModel> GetLatestData(string email)
{
//Create mongo client to allow connection to the database
public static async Task<SimPositionModel> GetLatestData(string email){
MongoClient client = new MongoClient(
Environment.GetEnvironmentVariable("MongoDBConnectionString", EnvironmentVariableTarget.User)
Environment.GetEnvironmentVariable("MongoDBConnectionString")
);
MongoDatabaseBase database = (MongoDatabaseBase)client.GetDatabase("EFB");
MongoCollectionBase<SimPositionModel> collection = (MongoCollectionBase<SimPositionModel>)database.GetCollection<SimPositionModel>("Simdata");
//Create filter to select specifically the records where the Email is the same as what we specified
FilterDefinition<SimPositionModel> filter = Builders<SimPositionModel>.Filter.Eq(x => x.EMail, email);
var data = await collection.FindAsync<SimPositionModel>(filter).Result.ToListAsync();
if (data.Count > 0)
{//Return the first item in the list (Should only be 1)
{
return data[0];
}//Or return null if not present
}
return null;
}
}

View File

@ -1,5 +1,11 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EFB
{

View File

@ -8,8 +8,7 @@ namespace EFB.Sessions
public static void SetObject(this ISession session, string key, object value)
{//Sets the object of a session to Object
session.SetString(key, JsonConvert.SerializeObject(value, Formatting.None,
new JsonSerializerSettings()
{
new JsonSerializerSettings(){
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}
));

View File

@ -1,8 +1,13 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EFB
{

16
docker-compose.debug.yml Normal file
View File

@ -0,0 +1,16 @@
# Please refer https://aka.ms/HTTPSinContainer on how to setup an https developer certificate for your ASP .NET Core service.
version: '3.4'
services:
efb:
image: efb
build:
context: .
dockerfile: ./Dockerfile
ports:
- 5000:5000
environment:
- ASPNETCORE_ENVIRONMENT=Development
volumes:
- ~/.vsdbg:/remote_debugger:rw

16
docker-compose.yml Normal file
View File

@ -0,0 +1,16 @@
# Please refer https://aka.ms/HTTPSinContainer on how to setup an https developer certificate for your ASP .NET Core service.
version: '3.4'
services:
efb:
image: efb
build:
context: .
dockerfile: ./Dockerfile
ports:
- 80:5000
environment:
- MongoDBConnectionString=
- MySQLPassword=
- ChartFoxAPIKey=