diff --git a/Controllers/FlightsimController.cs b/Controllers/FlightsimController.cs index a2af131..90ee24f 100644 --- a/Controllers/FlightsimController.cs +++ b/Controllers/FlightsimController.cs @@ -28,11 +28,13 @@ namespace EFB.Controllers if(user == null) return RedirectToAction("Index", "Home"); //Retrieve the user's latest sim position and construct it into FlightsimModel + if (user.Route == null) return RedirectToAction("Index", "Route"); + SimPositionModel latestPosition = await Mongo.GetLatestData(user.EMail); - // RouteModel route = RouteModel.StringToRoute(); + RouteModel route = await RouteModel.StringToRoute(user.Departure, user.Arrival, user.Cruise, user.Route); + return View(new FlightsimModel(latestPosition, null)); - return View(); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] diff --git a/Controllers/RouteController.cs b/Controllers/RouteController.cs index ee74e01..fc54f07 100644 --- a/Controllers/RouteController.cs +++ b/Controllers/RouteController.cs @@ -144,7 +144,7 @@ namespace EFB.Controllers foreach (var item in responsePoll.Result) { - if (item.Command == "fpl" || item.Command == "solution") + if (item.Command == "notvalid" || item.Command == "solution") { collected = true; routeString = item.FlightPlan; @@ -177,6 +177,7 @@ namespace EFB.Controllers user.Route = finalRoute; user.Departure = departure; user.Arrival = arrival; + user.Cruise = cruise; HttpContext.Session.SetObject("User", user); return RedirectToAction("Index", "Route"); diff --git a/Models/FlightsimModel.cs b/Models/FlightsimModel.cs index 90b6b10..6f9604e 100644 --- a/Models/FlightsimModel.cs +++ b/Models/FlightsimModel.cs @@ -2,17 +2,18 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using EFB.Models.Route; namespace EFB.Models { public class FlightsimModel { public SimPositionModel CurrentPosition { get; set; } - public RouteModel Route { get; set; } - public FlightsimModel(SimPositionModel position, RouteModel route) + public IWaypoint Closest { get; set; } + public FlightsimModel(SimPositionModel position, IWaypoint closest) { CurrentPosition = position; - Route = route; + Closest = closest; } } } \ No newline at end of file diff --git a/Models/Route/IWaypoint.cs b/Models/Route/IWaypoint.cs index 1c6944f..bddfe06 100644 --- a/Models/Route/IWaypoint.cs +++ b/Models/Route/IWaypoint.cs @@ -8,8 +8,8 @@ namespace EFB.Models.Route public interface IWaypoint { public string Name { get; set; } - public string Longitude { get; set; } - public string Latitude { get; set; } + public float Longitude { get; set; } + public float Latitude { get; set; } public string Airway { get; set; } public IWaypoint Next { get; set; } diff --git a/Models/Route/NavaidModel.cs b/Models/Route/NavaidModel.cs index ed147cd..0e35e8b 100644 --- a/Models/Route/NavaidModel.cs +++ b/Models/Route/NavaidModel.cs @@ -8,8 +8,8 @@ namespace EFB.Models.Route public class NavaidModel:IWaypoint { public string Name { get; set; } - public string Longitude { get; set; } - public string Latitude { get; set; } + public float Longitude { get; set; } + public float Latitude { get; set; } public int Frequency { get; set; } public string Airway { get; set; } @@ -17,9 +17,11 @@ namespace EFB.Models.Route public IWaypoint Previous { get; set; } = null; public bool Visited { get; set; } = false; - public NavaidModel(string name, string airway){ + public NavaidModel(string name, string airway, float longitude, float latitude){ Name = name; Airway = airway; + Longitude = longitude; + Latitude = latitude; } } } \ No newline at end of file diff --git a/Models/Route/WaypointModel.cs b/Models/Route/WaypointModel.cs index 1acc0bf..7518ed7 100644 --- a/Models/Route/WaypointModel.cs +++ b/Models/Route/WaypointModel.cs @@ -8,17 +8,19 @@ namespace EFB.Models.Route public class WaypointModel:IWaypoint { public string Name { get; set; } - public string Longitude { get; set; } - public string Latitude { get; set; } + public float Longitude { get; set; } + public float Latitude { get; set; } public string Airway { get; set; } public IWaypoint Next { get; set; } = null; public IWaypoint Previous { get; set; } = null; public bool Visited { get; set; } - public WaypointModel(string name, string airway){ + public WaypointModel(string name, string airway, float longitude, float latitude){ Name = name; Airway = airway; + Longitude = longitude; + Latitude = latitude; } } diff --git a/Models/RouteModel.cs b/Models/RouteModel.cs index 49795a9..9805407 100644 --- a/Models/RouteModel.cs +++ b/Models/RouteModel.cs @@ -19,15 +19,15 @@ 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); + Departure = new WaypointModel(departure, departureRoute, 0, 0); } if (FormAuthenticator.ValidateICAOCode(arrival)) { - Arrival = new WaypointModel(arrival, arrivalRoute); + Arrival = new WaypointModel(arrival, arrivalRoute, 0, 0); } if (FormAuthenticator.ValidateCruiseAlt(cruise)) @@ -53,7 +53,8 @@ namespace EFB.Models } //Generate a route Object - public static RouteModel StringToRoute(string departure, string arrival, uint cruise, string routeString){ + public static async Task StringToRoute(string departure, string arrival, uint cruise, string routeString){ + var navdataFetch = NavdataModel.Populate(); string[] routeTemp = routeString.Split(" "); //Set departure and arrival route @@ -65,17 +66,34 @@ namespace EFB.Models route.Current = route.Departure; + NavdataModel[] navdata = await navdataFetch; + navdata = NavdataModel.MergeSort(ref navdata, 0, navdata.Length - 1); + 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]); + if (currentWaypoint == null) + { + currentWaypoint = new NavdataModel(0, routeTemp[i], null, "0", "0"); + } //Populate 'next' waypoint if (routeTemp[i].Length > 3) {//waypoint Type - next = new WaypointModel(routeTemp[i], routeTemp[i+1]); + next = new WaypointModel( + routeTemp[i], + routeTemp[i+1], + float.Parse(currentWaypoint.Longitude), + float.Parse(currentWaypoint.Latitude) + ); }else {//Navaid Type - next = new NavaidModel(routeTemp[i], routeTemp[i+1]); + next = new NavaidModel( + routeTemp[i], + routeTemp[i+1], + float.Parse(currentWaypoint.Longitude), + float.Parse(currentWaypoint.Latitude) + ); } next.Previous = route.Current; @@ -90,6 +108,15 @@ namespace EFB.Models route.Current = route.Departure; + //Assign departure and arrival coordinate positions + NavdataModel departureNav = NavdataModel.BinarySearch(ref navdata, 0, navdata.Length - 1, departure); + NavdataModel arrivalNav = NavdataModel.BinarySearch(ref navdata, 0, navdata.Length - 1, arrival); + route.Departure.Latitude = float.Parse(departureNav.Latitude); + route.Departure.Longitude = float.Parse(departureNav.Longitude); + route.Arrival.Latitude = float.Parse(arrivalNav.Latitude); + route.Arrival.Latitude = float.Parse(arrivalNav.Longitude); + + return route; } diff --git a/Models/UserModel.cs b/Models/UserModel.cs index 4aa6982..cc4ece7 100644 --- a/Models/UserModel.cs +++ b/Models/UserModel.cs @@ -24,7 +24,7 @@ namespace EFB.Models public string Departure { get; set; } public string Route { get; set; } public string Arrival { get; set; } - public RouteModel RouteObject { get; set; } + public uint Cruise { get; set; } public TokenModel RouteToken { get; set; } = null; diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index d8901cc..20972fe 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -35,7 +35,7 @@ Charts @{