コード例 #1
0
        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");
        }
コード例 #2
0
        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.");
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public string GetDelay()
 {
     return(MonitorStatic.GetDelay());
 }
コード例 #6
0
 public int GetCacheNumber()
 {
     return(MonitorStatic.GetCacheInfo());
 }