Several changes - updated string to route to include coordinates - updated model for flight sim to only contain the closest point - User model now tracks route status... departure etc
This commit is contained in:
		@@ -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)]
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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; }
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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<RouteModel> 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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,7 @@
 | 
			
		||||
                            <a class="nav-link text-light" asp-area="" asp-controller="Charts" asp-action="Index">Charts</a>
 | 
			
		||||
                        </li>
 | 
			
		||||
                        <li class="nav-item">
 | 
			
		||||
                            <a class="nav-link text-light" asp-area="" asp-controller="" asp-action="Index">FlightSim</a>
 | 
			
		||||
                            <a class="nav-link text-light" asp-area="" asp-controller="Flightsim" asp-action="Index">FlightSim</a>
 | 
			
		||||
                        </li>
 | 
			
		||||
 | 
			
		||||
                        @{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user