public static async Task <shPath> FindShortPath(string ScenarioId, double StartX, double StartY, double DestinationX, double DestinationY, bool isPriorityAboveNormal) { try { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:9000/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string strUri = "api/Routing/FindShortPath?ScenarioId=" + ScenarioId + "&StartX=" + StartX + "&StartY=" + StartY + "&DestinationX=" + DestinationX + "&DestinationY=" + DestinationY + "&isPriorityAboveNormal=" + isPriorityAboveNormal; HttpResponseMessage response = null; try { response = await client.GetAsync(strUri); if (response.StatusCode != System.Net.HttpStatusCode.OK) { Console.WriteLine("NOT OK: " + response.StatusCode.ToString()); return(null); } } catch (System.Net.WebException e) { return(null); } catch (TaskCanceledException e) { return(null); } catch (Exception e) { return(null); } HttpContent content = response.Content; string v = await content.ReadAsStringAsync(); shPath tmp = JsonConvert.DeserializeObject <shPath>(v); return(tmp); } } catch (Exception ex) { } return(null); }
public async Task <Route> generateRouteByShortestPath(String routeName, DPoint source, DPoint dest) { // assumption: source and dest are on a sidewalk shPath path = await RouteWebAPI.FindShortPath("0", source.x, source.y, dest.x, dest.y, false); Route route = new Route(); route.countryId = 0; route.guid = Util.CreateGuid(); route.name = routeName; route.owner = null; route.routeTypeId = 0; route.routePoints = new List <DPoint>(); foreach (shPoint point in path.Points) { route.routePoints.Add(new DPoint(point.x, point.y)); } return(route); }