Route Polling Complete
App now fetched a route, still needs to be moved into a Linked List
This commit is contained in:
parent
18bf369a1b
commit
f2e852fcf0
@ -43,7 +43,8 @@ namespace EFB.Controllers
|
|||||||
return View("Error!");
|
return View("Error!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> New(string departure, string arrival, string cruise){
|
public async Task<IActionResult> New(string departure, string arrival, string cruise)
|
||||||
|
{
|
||||||
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
||||||
if (!(user == null || user.Token.IsExpired()))
|
if (!(user == null || user.Token.IsExpired()))
|
||||||
{//If the user is still authenticated
|
{//If the user is still authenticated
|
||||||
@ -62,7 +63,8 @@ namespace EFB.Controllers
|
|||||||
Dictionary<string, string> headerData = new Dictionary<string, string>();
|
Dictionary<string, string> headerData = new Dictionary<string, string>();
|
||||||
headerData.Add("Authorization", $"Bearer {user.Token.TokenValue}");
|
headerData.Add("Authorization", $"Bearer {user.Token.TokenValue}");
|
||||||
|
|
||||||
RouteRequest routeRequest = new RouteRequest(){
|
RouteRequest routeRequest = new RouteRequest()
|
||||||
|
{
|
||||||
departure = departure,
|
departure = departure,
|
||||||
destination = arrival,
|
destination = arrival,
|
||||||
preferredminlevel = cruiseAlt / 1000,
|
preferredminlevel = cruiseAlt / 1000,
|
||||||
@ -77,7 +79,8 @@ namespace EFB.Controllers
|
|||||||
|
|
||||||
if (responseRoute.Error == null)
|
if (responseRoute.Error == null)
|
||||||
{//Update User session and add route ID
|
{//Update User session and add route ID
|
||||||
RouteModel route = new RouteModel(){
|
RouteModel route = new RouteModel()
|
||||||
|
{
|
||||||
RouteID = responseRoute.Result.ToString()
|
RouteID = responseRoute.Result.ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,7 +108,8 @@ namespace EFB.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<IActionResult> Poll(){
|
public async Task<IActionResult> Poll()
|
||||||
|
{
|
||||||
if (HttpContext.Session.GetString("User") != null)
|
if (HttpContext.Session.GetString("User") != null)
|
||||||
{//If the user is currently logged in
|
{//If the user is currently logged in
|
||||||
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
||||||
@ -116,7 +120,7 @@ namespace EFB.Controllers
|
|||||||
//Make calls to the server to fetch route
|
//Make calls to the server to fetch route
|
||||||
bool collected = false;
|
bool collected = false;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
string route;
|
string route = "";
|
||||||
|
|
||||||
APIInterface API = new APIInterface();
|
APIInterface API = new APIInterface();
|
||||||
|
|
||||||
@ -131,10 +135,11 @@ namespace EFB.Controllers
|
|||||||
ResponseModel<List<PollResponse>> responsePoll = await pollingRequest;
|
ResponseModel<List<PollResponse>> responsePoll = await pollingRequest;
|
||||||
|
|
||||||
|
|
||||||
if (responsePoll.Result[count].Command == "solution")
|
int routePos = responsePoll.Result.Count - 1;
|
||||||
|
if (responsePoll.Result[routePos].Command == "solution")
|
||||||
{
|
{
|
||||||
collected = true;
|
collected = true;
|
||||||
route = responsePoll.Result[count].FlightPlan;
|
route = responsePoll.Result[routePos].FlightPlan;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,16 +148,54 @@ namespace EFB.Controllers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (collected)
|
||||||
|
{
|
||||||
|
//fill in route
|
||||||
|
string finalRoute = ParseRoute(route);
|
||||||
|
|
||||||
return RedirectToAction("Index", "Route");
|
TempData["Error"] = finalRoute;
|
||||||
|
|
||||||
}else{
|
|
||||||
return RedirectToAction("Index", "Route");
|
return RedirectToAction("Index", "Route");
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
TempData["Error"] = "Unable to get route!";
|
||||||
|
return RedirectToAction("Index", "Route");
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return RedirectToAction("Index", "Route");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return RedirectToAction("Index", "Route");
|
return RedirectToAction("Index", "Route");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string ParseRoute(string route){
|
||||||
|
TempData["Error"] = route;
|
||||||
|
|
||||||
|
route.Replace('/', ' ');
|
||||||
|
var routeArr = route.Split(' ');
|
||||||
|
|
||||||
|
string finalRoute = "";
|
||||||
|
|
||||||
|
foreach (var item in routeArr)
|
||||||
|
{
|
||||||
|
var waypoint = item.Split('/')[0];
|
||||||
|
if (waypoint.Length <= 7 && waypoint.Length >= 3 && !waypoint.Contains('-'))
|
||||||
|
{
|
||||||
|
finalRoute += $"{waypoint} ";
|
||||||
|
|
||||||
|
if (waypoint.Length == 7 && finalRoute.Length > 8)
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalRoute;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user