public Destination GetDestination(RouteParams routeParams) { Console.WriteLine("Call is being routed with the following parameters: owner: {0}, caller id: {1}, dialed number: {2}, state: {3}", routeParams.CallerInfo.Owner, routeParams.CallerInfo.CallerId, routeParams.CallerInfo.DialedNumber, routeParams.State); //var lst = client.GetExtensionInfos(); //var lst2 = client.GetPhoneBook(); //var sessions = _client.GetActiveSessions(); //if (routeParams.Destination.DialedNumber == "*90" && !dndExtensions.Contains(routeParams.CallerInfo.Owner)) //{ // Console.WriteLine("Extension {0} added to the DND list.", routeParams.CallerInfo.Owner); // dndExtensions.Add(routeParams.CallerInfo.Owner); //} //if (routeParams.Destination.DialedNumber == "*91" && dndExtensions.Contains(routeParams.CallerInfo.Owner)) //{ // Console.WriteLine("Extension {0} removed from the DND list.", routeParams.CallerInfo.Owner); // dndExtensions.Remove(routeParams.CallerInfo.Owner); //} //if (dndExtensions.Contains(routeParams.Destination.DialedNumber)) //{ // return new Destination(routeParams.CallerInfo.Owner, null, null, 10); //} return null; }
private void FillRouteParamsFromPath() { //string __path = ControllerContext.HttpContext.Request.RawUrl; string __path = ControllerContext.HttpContext.Request.GetDisplayUrl(); //for (int i = 0; i < ControllerContext.HttpContext.Request.QueryString.Count; i++) for (int i = 0; i < ControllerContext.HttpContext.Request.Query.Count; i++) { string __queryParamName = ""; //__queryParamName = ControllerContext.HttpContext.Request.QueryString.GetKey(i); List <string> __list_queryparamnames = ControllerContext.HttpContext.Request.Query.Keys.ToList(); __queryParamName = __list_queryparamnames[i]; if (RouteParams.ContainsKey(__queryParamName)) { //string __queryParamValue = ""; Microsoft.Extensions.Primitives.StringValues ____queryParamValue; //__queryParamValue = ControllerContext.HttpContext.Request.QueryString[i]; ControllerContext.HttpContext.Request.Query.TryGetValue(__queryParamName, out ____queryParamValue); RouteParams[__queryParamName]._value = ____queryParamValue[0]; } } if (!string.IsNullOrEmpty(__path) && __path != "/") { RouteParams.ExtractParamsFromPathString(__path, '/'); } }
public Destination GetDestination(RouteParams routeParams) { Console.WriteLine("Call is being routed with the following parameters: owner: {0}, caller id: {1}, dialed number: {2}, state: {3}", routeParams.CallerInfo.Owner, routeParams.CallerInfo.CallerId, routeParams.CallerInfo.DialedNumber, routeParams.State); //var lst = client.GetExtensionInfos(); //var lst2 = client.GetPhoneBook(); //var sessions = _client.GetActiveSessions(); //if (routeParams.Destination.DialedNumber == "*90" && !dndExtensions.Contains(routeParams.CallerInfo.Owner)) //{ // Console.WriteLine("Extension {0} added to the DND list.", routeParams.CallerInfo.Owner); // dndExtensions.Add(routeParams.CallerInfo.Owner); //} //if (routeParams.Destination.DialedNumber == "*91" && dndExtensions.Contains(routeParams.CallerInfo.Owner)) //{ // Console.WriteLine("Extension {0} removed from the DND list.", routeParams.CallerInfo.Owner); // dndExtensions.Remove(routeParams.CallerInfo.Owner); //} //if (dndExtensions.Contains(routeParams.Destination.DialedNumber)) //{ // return new Destination(routeParams.CallerInfo.Owner, null, null, 10); //} return(null); }
public async Task <IActionResult> Calculate(Params p) { var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true }; //check if airport exists string url = urlFlight + "airports/" + p.airport; HttpClient client = new HttpClient(); Uri uri = new Uri(url); HttpResponseMessage reponse = await client.GetAsync(uri); if (reponse.StatusCode == HttpStatusCode.OK) { string data = await reponse.Content.ReadAsStringAsync(); Airport airport = JsonSerializer.Deserialize <Airport>(data, options); //get the route Uri uriRoute = new Uri(urlRoute); RouteParams rp = new RouteParams() { startLat = p.latitude, startLon = p.longitude, endLat = airport.latitude - 0.007f, endLon = airport.longitude - 0.007f, mean = "car" }; string jsonString = JsonSerializer.Serialize(rp); var content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await client.PostAsync(uriRoute, content); string time = await response.Content.ReadAsStringAsync(); RouteResponse result = JsonSerializer.Deserialize <RouteResponse>(time, options); return(Ok(result)); } else { //invalid airport code return(BadRequest("Invalid airport number!")); } }
public ActionResult CalculateRoute(RouteParams param) { List <double[]> pointsList = new List <double[]>(); foreach (var point in param.Points) { var lat = double.Parse(point[0], CultureInfo.InvariantCulture); var lon = double.Parse(point[1], CultureInfo.InvariantCulture); var personId = double.Parse(point[2], CultureInfo.InvariantCulture); pointsList.Add(new double[] { lat, lon, personId }); } var startLat = double.Parse(param.StartCoord[0], CultureInfo.InvariantCulture); var startLon = double.Parse(param.StartCoord[1], CultureInfo.InvariantCulture); var startPersonId = double.Parse(param.StartCoord[2], CultureInfo.InvariantCulture); var endLat = double.Parse(param.EndCoord[0], CultureInfo.InvariantCulture); var endLon = double.Parse(param.EndCoord[1], CultureInfo.InvariantCulture); var endPersonId = double.Parse(param.EndCoord[2], CultureInfo.InvariantCulture); double[][] pointsArray = pointsList.ToArray(); double[] startingPoint = new double[] { startLat, startLon, startPersonId }; double[] endPoint = new double[] { endLat, endLon, endPersonId }; var problem = new Problem(pointsArray, startingPoint, colonySize: 50, iterations: 10, endPoint: endPoint); var route = problem.FindRoute(); List <Result> routeResult = new List <Result>(); foreach (double[] node in route) { Result res = new Result { Latitude = node[0], Longitude = node[1], PersonId = (int)node[2] }; routeResult.Add(res); } return(Json(new { result = "Redirect", url = Url.Action("DrawRoute", "Routes"), routeResult = routeResult })); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); MiscParams = new MiscParams(); RouteParams = new RouteParams(); QueryParametersList = new QueryParametersList(); RouteParamsToQueryParametersMappingsList = new RouteParamsToQueryParametersMappingsList(); FillMiscParams(); SetRouteParams(); FillRouteParamsFromPath(); SetQueryParametersList(); SetRouteParamsToQueryParametersMappings(); FillQueryParametersListFromMappings(); }
protected override void SetRouteParams() { base.SetRouteParams(); string __actionMethodName = GetRouteValue( "action" //HttpContext.Request.RequestContext.RouteData.Values["action"].ToString().ToLower() ); switch (__actionMethodName) { case "index": RouteParams.Add("Page", new RouteParam() { name = "Page", defaultValue = "1" }); break; } }
private async Task <string> GetRouteParam(string first, string second, string third, RouteParams paramType) { ISlugService service = paramType == RouteParams.City ? this.cityService : paramType == RouteParams.Type ? (ISlugService)this.escortTypeService : paramType == RouteParams.Service ? this.serviceService : null; if (service == null) { throw new ArgumentException($"Unknown {nameof(paramType)}: {paramType}"); } if (await service.IsSlugExists(first)) { return(first); } if (await service.IsSlugExists(second)) { return(second); } if (await service.IsSlugExists(third)) { return(third); } return(string.Empty); // throw new ArgumentException($"Unkown route: {first}/{second}/{third}"); }