public string GetHelp() { DateTime startTime = DateTime.Now; MonitorStatic.AddRequestFromClient(); MonitorStatic.AddDelay(DateTime.Now.Subtract(startTime).TotalMilliseconds); return("Choose 1. List all stations of a city, the server will show you all the stations available in the city you input.\n" + "Attention: You should input a valid city.\n\n" + "Choose 2. Search for a station by name, first you need to input a city, then you input the name of the station you want to search, you can get the information of this station.\n" + "Attention: Both the name of the city and the station should be valid, there is no limitation of upper or lower case for the names.\n"); }
public async Task <string> GetStationInfo(string city, string station) { DateTime startTime = DateTime.Now; MonitorStatic.AddRequestFromClient(); if (cacheStation[station] != null) { MonitorStatic.AddDelay(DateTime.Now.Subtract(startTime).TotalMilliseconds); return((string)cacheStation[station]); } string requestUri = "https://api.jcdecaux.com/vls/v1/stations/?contract=" + city + "&apiKey=" + key; WebRequest request = WebRequest.Create(requestUri); request.ContentType = "text/html;charset=UTF-8"; request.Method = "GET"; request.Proxy = null; MonitorStatic.AddRequestToVelib(); WebResponse response; try { response = await request.GetResponseAsync(); } catch (Exception e) { return("Not a valid city"); } Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); // Display the content. List <Station> velibs = JsonConvert.DeserializeObject <List <Station> >(responseFromServer); Station a = null; foreach (Station velib in velibs) { if (velib.name.Contains(station.ToUpper())) { a = velib; cacheStation.Set(station, a.ToString(), policy); MonitorStatic.AddCacheInfo(); break; } } if (a != null) { MonitorStatic.AddDelay(DateTime.Now.Subtract(startTime).TotalMilliseconds); return(a.ToString()); } MonitorStatic.AddDelay(DateTime.Now.Subtract(startTime).TotalMilliseconds); return("Not a valid station, please try again."); }
public string GetRequestToVelib(string startTime, string endTime) { double start; double end; try { start = Convert.ToDouble(startTime); end = Convert.ToDouble(endTime); }catch (Exception e) { return("Please input a valid number"); } return("Number of requests to Velib: " + MonitorStatic.GetRequestNumberToVelib(start, end).ToString()); }
public async Task <string> GetStationsOfACity(string city) { DateTime startTime = DateTime.Now; MonitorStatic.AddRequestFromClient(); if (cacheCity[city] != null) { MonitorStatic.AddDelay(DateTime.Now.Subtract(startTime).TotalMilliseconds); return((string)cacheCity[city]); } string requestUri = "https://api.jcdecaux.com/vls/v1/stations/?contract=" + city + "&apiKey=" + key; WebRequest request = WebRequest.Create(requestUri); request.ContentType = "text/html;charset=UTF-8"; request.Method = "GET"; request.Proxy = null; MonitorStatic.AddRequestToVelib(); WebResponse response; try { response = await request.GetResponseAsync(); } catch (Exception e) { MonitorStatic.AddDelay(DateTime.Now.Subtract(startTime).TotalMilliseconds); return("Not a valid city.Please try again."); } Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); // Display the content. List <Station> velibs = JsonConvert.DeserializeObject <List <Station> >(responseFromServer); string result = ""; foreach (var station in velibs) { result += station.name; result += "\n"; } cacheCity.Set(city, result, policy); MonitorStatic.AddCacheInfo(); MonitorStatic.AddDelay(DateTime.Now.Subtract(startTime).TotalMilliseconds); return(result); }
public string GetDelay() { return(MonitorStatic.GetDelay()); }
public int GetCacheNumber() { return(MonitorStatic.GetCacheInfo()); }