Compare commits
	
		
			7 Commits
		
	
	
		
			8ac4a3d693
			...
			eff67b7697
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| eff67b7697 | |||
| e271e49374 | |||
| 5316df08a5 | |||
| 10af903706 | |||
| eda71069a4 | |||
| 8be3b0fa02 | |||
| 0252f115c6 | 
							
								
								
									
										81
									
								
								Controllers/FlightsimController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								Controllers/FlightsimController.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,81 @@
 | 
				
			|||||||
 | 
					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
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    //[Route("[controller]")]
 | 
				
			||||||
 | 
					    public class FlightsimController : Controller
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        private readonly ILogger<FlightsimController> _logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public FlightsimController(ILogger<FlightsimController> logger)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            _logger = logger;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public async Task<IActionResult> Index()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            //Retrieve and Check current user status
 | 
				
			||||||
 | 
					            UserModel user = HttpContext.Session.GetObject<UserModel>("User");
 | 
				
			||||||
 | 
					            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 latestPositionModel = await Mongo.GetLatestData(user.EMail);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            RouteModel route = await RouteModel.StringToRoute(user.Departure, user.Arrival, user.Cruise, user.Route);
 | 
				
			||||||
 | 
					            IWaypoint closest = DetermineClosest(route, latestPositionModel.LatestPosition);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return View(new FlightsimModel(latestPositionModel, closest));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private IWaypoint DetermineClosest(RouteModel route, SimPosition currentPosition){
 | 
				
			||||||
 | 
					            IWaypoint closest = null;
 | 
				
			||||||
 | 
					            float closestDistance = float.MaxValue;
 | 
				
			||||||
 | 
					            //Assuming that we are on the earth for simplicity
 | 
				
			||||||
 | 
					            IWaypoint waypoint = route.Departure;
 | 
				
			||||||
 | 
					            while (waypoint.Next != null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                int earthRadius = 6371;
 | 
				
			||||||
 | 
					                float distanceLat = DegreesToRadians(waypoint.Latitude - currentPosition.Latitude);
 | 
				
			||||||
 | 
					                float distanceLon = DegreesToRadians(waypoint.Longitude - currentPosition.Longitude);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                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));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                float distance = (float)(earthRadius * c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (distance < closestDistance)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    closest = waypoint;
 | 
				
			||||||
 | 
					                    closestDistance = distance;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                waypoint = waypoint.Next;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return closest;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        private float DegreesToRadians(float degrees){
 | 
				
			||||||
 | 
					            return (float)(degrees * Math.PI / 180);
 | 
				
			||||||
 | 
					        } 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
 | 
				
			||||||
 | 
					        public IActionResult Error()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return View("Error!");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -144,7 +144,7 @@ namespace EFB.Controllers
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                        foreach (var item in responsePoll.Result)
 | 
					                        foreach (var item in responsePoll.Result)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            if (item.Command == "fpl" || item.Command == "solution")
 | 
					                            if (item.Command == "notvalid" || item.Command == "solution")
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                collected = true;
 | 
					                                collected = true;
 | 
				
			||||||
                                routeString = item.FlightPlan;
 | 
					                                routeString = item.FlightPlan;
 | 
				
			||||||
@@ -175,6 +175,9 @@ namespace EFB.Controllers
 | 
				
			|||||||
                        //fill in route
 | 
					                        //fill in route
 | 
				
			||||||
                        string finalRoute = RouteModel.ParseRoute(routeString);
 | 
					                        string finalRoute = RouteModel.ParseRoute(routeString);
 | 
				
			||||||
                        user.Route = finalRoute;
 | 
					                        user.Route = finalRoute;
 | 
				
			||||||
 | 
					                        user.Departure = departure;
 | 
				
			||||||
 | 
					                        user.Arrival = arrival;
 | 
				
			||||||
 | 
					                        user.Cruise = cruise;
 | 
				
			||||||
                        HttpContext.Session.SetObject("User", user);
 | 
					                        HttpContext.Session.SetObject("User", user);
 | 
				
			||||||
                        
 | 
					                        
 | 
				
			||||||
                        return RedirectToAction("Index", "Route");
 | 
					                        return RedirectToAction("Index", "Route");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,5 +5,7 @@
 | 
				
			|||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
 | 
					    <PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
 | 
				
			||||||
    <PackageReference Include="MySql.Data" Version="*"/>
 | 
					    <PackageReference Include="MySql.Data" Version="*"/>
 | 
				
			||||||
 | 
					    <PackageReference Include="MongoDB.Driver" Version="*"/>
 | 
				
			||||||
 | 
					    <PackageReference Include="MongoDB.Bson" Version="*"/>
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
</Project>
 | 
					</Project>
 | 
				
			||||||
							
								
								
									
										19
									
								
								Models/FlightsimModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								Models/FlightsimModel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					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 IWaypoint Closest { get; set; }
 | 
				
			||||||
 | 
					        public FlightsimModel(SimPositionModel position, IWaypoint closest)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            CurrentPosition = position;
 | 
				
			||||||
 | 
					            Closest = closest;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -54,11 +54,11 @@ namespace EFB.Models
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            while (reader.Read())
 | 
					            while (reader.Read())
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                int id = reader.GetInt32(0);
 | 
					                int id = reader.GetInt32("id");
 | 
				
			||||||
                string name = reader.GetString(1);
 | 
					                string name = reader.GetString("name");
 | 
				
			||||||
                string type = reader.GetString(2);
 | 
					                string type = reader.GetString("type");
 | 
				
			||||||
                string latitude = reader.GetString(4);
 | 
					                string latitude = reader.GetString("latitude");
 | 
				
			||||||
                string longitude = reader.GetString(5);
 | 
					                string longitude = reader.GetString("longitude");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (type == "VOR" || type == "NDB")
 | 
					                if (type == "VOR" || type == "NDB")
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,8 +8,8 @@ namespace EFB.Models.Route
 | 
				
			|||||||
    public interface IWaypoint
 | 
					    public interface IWaypoint
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public string Name { get; set; }
 | 
					        public string Name { get; set; }
 | 
				
			||||||
        public string Longitude { get; set; }
 | 
					        public float Longitude { get; set; }
 | 
				
			||||||
        public string Latitude { get; set; }
 | 
					        public float Latitude { get; set; }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        public string Airway { get; set; }
 | 
					        public string Airway { get; set; }
 | 
				
			||||||
        public IWaypoint Next { get; set; }
 | 
					        public IWaypoint Next { get; set; }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,8 +8,8 @@ namespace EFB.Models.Route
 | 
				
			|||||||
    public class NavaidModel:IWaypoint
 | 
					    public class NavaidModel:IWaypoint
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public string Name { get; set; }
 | 
					        public string Name { get; set; }
 | 
				
			||||||
        public string Longitude { get; set; }
 | 
					        public float Longitude { get; set; }
 | 
				
			||||||
        public string Latitude { get; set; }
 | 
					        public float Latitude { get; set; }
 | 
				
			||||||
        public int Frequency { get; set; }
 | 
					        public int Frequency { get; set; }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        public string Airway { get; set; }
 | 
					        public string Airway { get; set; }
 | 
				
			||||||
@@ -17,9 +17,11 @@ namespace EFB.Models.Route
 | 
				
			|||||||
        public IWaypoint Previous { get; set; } = null;
 | 
					        public IWaypoint Previous { get; set; } = null;
 | 
				
			||||||
        public bool Visited { get; set; } = false;
 | 
					        public bool Visited { get; set; } = false;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        public NavaidModel(string name, string airway){
 | 
					        public NavaidModel(string name, string airway, float longitude, float latitude){
 | 
				
			||||||
            Name = name;
 | 
					            Name = name;
 | 
				
			||||||
            Airway = airway;
 | 
					            Airway = airway;
 | 
				
			||||||
 | 
					            Longitude = longitude;
 | 
				
			||||||
 | 
					            Latitude = latitude;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -8,17 +8,19 @@ namespace EFB.Models.Route
 | 
				
			|||||||
    public class WaypointModel:IWaypoint
 | 
					    public class WaypointModel:IWaypoint
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public string Name { get; set; }
 | 
					        public string Name { get; set; }
 | 
				
			||||||
        public string Longitude { get; set; }
 | 
					        public float Longitude { get; set; }
 | 
				
			||||||
        public string Latitude { get; set; }
 | 
					        public float Latitude { get; set; }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        public string Airway { get; set; }
 | 
					        public string Airway { get; set; }
 | 
				
			||||||
        public IWaypoint Next { get; set; } = null;
 | 
					        public IWaypoint Next { get; set; } = null;
 | 
				
			||||||
        public IWaypoint Previous { get; set; } = null;
 | 
					        public IWaypoint Previous { get; set; } = null;
 | 
				
			||||||
        public bool Visited { get; set; }
 | 
					        public bool Visited { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public WaypointModel(string name, string airway){
 | 
					        public WaypointModel(string name, string airway, float longitude, float latitude){
 | 
				
			||||||
            Name = name;
 | 
					            Name = name;
 | 
				
			||||||
            Airway = airway;
 | 
					            Airway = airway;
 | 
				
			||||||
 | 
					            Longitude = longitude;
 | 
				
			||||||
 | 
					            Latitude = latitude;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,12 +22,12 @@ namespace EFB.Models
 | 
				
			|||||||
        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))
 | 
					            if (FormAuthenticator.ValidateICAOCode(departure))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Departure = new WaypointModel(departure, departureRoute);
 | 
					                Departure = new WaypointModel(departure, departureRoute, 0, 0);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (FormAuthenticator.ValidateICAOCode(arrival))
 | 
					            if (FormAuthenticator.ValidateICAOCode(arrival))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Arrival = new WaypointModel(arrival, arrivalRoute);
 | 
					                Arrival = new WaypointModel(arrival, arrivalRoute, 0, 0);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (FormAuthenticator.ValidateCruiseAlt(cruise))
 | 
					            if (FormAuthenticator.ValidateCruiseAlt(cruise))
 | 
				
			||||||
@@ -53,7 +53,8 @@ namespace EFB.Models
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Generate a route Object
 | 
					        //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(" ");
 | 
					            string[] routeTemp = routeString.Split(" ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //Set departure and arrival route
 | 
					            //Set departure and arrival route
 | 
				
			||||||
@@ -65,17 +66,34 @@ namespace EFB.Models
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            route.Current = route.Departure;
 | 
					            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)
 | 
					            for (var i = 1; i < routeTemp.Length-1; i+=2)
 | 
				
			||||||
            {//Already used first item, continue itterating over every other item
 | 
					            {//Already used first item, continue itterating over every other item
 | 
				
			||||||
                IWaypoint next;
 | 
					                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
 | 
					                //Populate 'next' waypoint
 | 
				
			||||||
                if (routeTemp[i].Length > 3)
 | 
					                if (routeTemp[i].Length > 3)
 | 
				
			||||||
                {//waypoint Type
 | 
					                {//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
 | 
					                }else
 | 
				
			||||||
                {//Navaid Type
 | 
					                {//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;
 | 
					                next.Previous = route.Current;
 | 
				
			||||||
@@ -90,6 +108,15 @@ namespace EFB.Models
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            route.Current = route.Departure;
 | 
					            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;
 | 
					            return route;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										53
									
								
								Models/SimPositionModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								Models/SimPositionModel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
				
			|||||||
 | 
					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
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public class SimPositionModel
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        [BsonId]
 | 
				
			||||||
 | 
					        public ObjectId Id { get; set; }
 | 
				
			||||||
 | 
					        public string EMail { get; set; } = "";
 | 
				
			||||||
 | 
					        public DateTime LatestPacketUpdate { get; set; }
 | 
				
			||||||
 | 
					        public SimPosition LatestPosition { get; set; } = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public SimPositionModel(string email, SimPosition position){
 | 
				
			||||||
 | 
					            EMail = email;
 | 
				
			||||||
 | 
					            LatestPacketUpdate = DateTime.Now;
 | 
				
			||||||
 | 
					            LatestPosition = position;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public class SimPosition
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public float Latitude { get; set; }
 | 
				
			||||||
 | 
					        public float Longitude { get; set; }
 | 
				
			||||||
 | 
					        public int Altitude { get; set; }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        public SimPosition(float latitude, float longitude, int altitude){
 | 
				
			||||||
 | 
					            Latitude = latitude;
 | 
				
			||||||
 | 
					            Longitude = longitude;
 | 
				
			||||||
 | 
					            Altitude = altitude;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //**Packet Processing not required**//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // public SimPosition(Packet[] data){
 | 
				
			||||||
 | 
					        //     if (data[0].Data != null)
 | 
				
			||||||
 | 
					        //     {
 | 
				
			||||||
 | 
					        //         //Use Linq to search through the packets for a given id and use that data
 | 
				
			||||||
 | 
					        //         Latitude = (data.Where(x => x.Id == 22).Select(x => x.Data[0]).ToArray())[0];
 | 
				
			||||||
 | 
					        //         Longitude = (data.Where(x => x.Id == 23).Select(x => x.Data[0]).ToArray())[0];
 | 
				
			||||||
 | 
					        //         Altitude = Convert.ToInt32((data.Where(x => x.Id == 24).Select(x => x.Data[0]).ToArray())[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //     }
 | 
				
			||||||
 | 
					        // }   
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -21,7 +21,12 @@ namespace EFB.Models
 | 
				
			|||||||
        public TokenModel UserToken { get; set; } = null;
 | 
					        public TokenModel UserToken { get; set; } = null;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        //Contains the most recent route generated by the user through the App
 | 
					        //Contains the most recent route generated by the user through the App
 | 
				
			||||||
 | 
					        public string Departure { get; set; }
 | 
				
			||||||
        public string Route { get; set; }
 | 
					        public string Route { get; set; }
 | 
				
			||||||
 | 
					        public string Arrival { get; set; }
 | 
				
			||||||
 | 
					        public uint Cruise { get; set; }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        public TokenModel RouteToken { get; set; } = null;
 | 
					        public TokenModel RouteToken { get; set; } = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Contains the Departure and Arrival Charts for the user's route
 | 
					        //Contains the Departure and Arrival Charts for the user's route
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										30
									
								
								Mongo/Mongo.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								Mongo/Mongo.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					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){
 | 
				
			||||||
 | 
					            MongoClient client = new MongoClient(
 | 
				
			||||||
 | 
					                Environment.GetEnvironmentVariable("MongoDBConnectionString", EnvironmentVariableTarget.User)
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					            MongoDatabaseBase database = (MongoDatabaseBase)client.GetDatabase("EFB");
 | 
				
			||||||
 | 
					            MongoCollectionBase<SimPositionModel> collection = (MongoCollectionBase<SimPositionModel>)database.GetCollection<SimPositionModel>("Simdata");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            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 data[0];
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										53
									
								
								Views/Flightsim/Index.cshtml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								Views/Flightsim/Index.cshtml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
				
			|||||||
 | 
					@model EFB.Models.FlightsimModel;
 | 
				
			||||||
 | 
					@{
 | 
				
			||||||
 | 
					    ViewData["Title"] = "Welcome";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<div class="row d-flex">
 | 
				
			||||||
 | 
					            <div class="card-body col-md-6 bg-primary">
 | 
				
			||||||
 | 
					                <div class="container jumbotron">
 | 
				
			||||||
 | 
					                    <h3>Current Position</h3>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    <br />
 | 
				
			||||||
 | 
					                    <br />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    <h5 style="color: gray;">Last Updated at: @Model.CurrentPosition.LatestPacketUpdate.ToString()</h5>
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                    <div class="row d-flex">
 | 
				
			||||||
 | 
					                        <div class="col-md-6">
 | 
				
			||||||
 | 
					                            <h4>Latitude</h4>
 | 
				
			||||||
 | 
					                            @Model.CurrentPosition.LatestPosition.Latitude
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            <h4>Longitude</h4>
 | 
				
			||||||
 | 
					                            @Model.CurrentPosition.LatestPosition.Longitude
 | 
				
			||||||
 | 
					                        </div>
 | 
				
			||||||
 | 
					                        <div class="col-md-6">
 | 
				
			||||||
 | 
					                            <h4>Altitude</h4>
 | 
				
			||||||
 | 
					                            @Model.CurrentPosition.LatestPosition.Altitude ft
 | 
				
			||||||
 | 
					                        </div>
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <div class="card-body col-md-6 bg-success">
 | 
				
			||||||
 | 
					                <div class="container jumbotron">
 | 
				
			||||||
 | 
					                    <h3>Closest Waypoint</h3>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    <br />
 | 
				
			||||||
 | 
					                    <br />
 | 
				
			||||||
 | 
					                    <h4>@Model.Closest.Name -> @Model.Closest.Airway</h4>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    <h4>Latitude</h4>
 | 
				
			||||||
 | 
					                    @Model.Closest.Latitude
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    <h4>Longitude</h4>
 | 
				
			||||||
 | 
					                    @Model.Closest.Longitude
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -35,7 +35,7 @@
 | 
				
			|||||||
                            <a class="nav-link text-light" asp-area="" asp-controller="Charts" asp-action="Index">Charts</a>
 | 
					                            <a class="nav-link text-light" asp-area="" asp-controller="Charts" asp-action="Index">Charts</a>
 | 
				
			||||||
                        </li>
 | 
					                        </li>
 | 
				
			||||||
                        <li class="nav-item">
 | 
					                        <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>
 | 
					                        </li>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        @{
 | 
					                        @{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user