public List <RoutesInfo> GetRouteInformation() { List <RoutesInfo> routeInfoList = new List <RoutesInfo>(); try { using (HttpClient httpClient1 = new HttpClient()) { httpClient1.BaseAddress = new Uri("http://sanjayjdm.apphb.com/"); httpClient1.DefaultRequestHeaders.Accept.Clear(); httpClient1.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); string jsonResponseString = httpClient1.GetStringAsync("api/getroutes?appKey=ttpapikey.asxc123nju89mno0").Result; string jsonwithDouble = jsonResponseString.Replace("'", "\""); XDocument doc = XDocument.Parse(jsonwithDouble); string pureJson = doc.Root.Value; var routeList = Newtonsoft.Json.Linq.JObject.Parse(pureJson).SelectToken("Routes").ToObject <List <RoutesInfo> >(); foreach (var route in routeList) { RoutesInfo routeInfo = new RoutesInfo(); routeInfo.routeid = route.routeid; routeInfo.routeName = route.routeName; routeInfoList.Add(routeInfo); } } } catch (Exception exep) { throw new Exception(exep.Message); } return(routeInfoList); }
public async Task <HttpResponseMessage> RouteRequest(HttpRequest request) { string path = request.Path.ToString(); string basePath = '/' + path.Split('/')[1]; Destination destination; try { destination = RoutesInfo.First(r => r.Endpoint.Equals(basePath)).Destination; } catch { return(ConstructErrorMessage("The path could not be found.")); } if (destination.RequiresAuthentication) { string token = request.Headers["token"]; request.Query.Append(new KeyValuePair <string, StringValues>("token", new StringValues(token))); HttpResponseMessage authResponse = await AuthenticationService.SendRequest(request); if (!authResponse.IsSuccessStatusCode) { return(ConstructErrorMessage("Authentication failed.")); } } return(await destination.SendRequest(request)); }
/// <summary> /// Saves the data into desired folder. /// </summary> /// <param name="basePath">Base path to the folder.</param> /// <param name="folder">Desired folder.</param> public void Save(string basePath = "./") { if (Directory.Exists(basePath + "basic")) { Directory.Delete(basePath + "basic", true); } Directory.CreateDirectory(basePath + "basic"); RoutesInfo.WriteBasic(new StreamWriter(basePath + "basic/routes_info.tfb")); Stops.WriteBasic(new StreamWriter(basePath + "basic/stops.tfb")); Stations.WriteBasic(new StreamWriter(basePath + "basic/stations.tfb")); using (var sw = new StreamWriter(basePath + "basic/.version")) sw.WriteLine(Version); }