Example #1
0
        public int NumberOfBikesAvailable(String stationName)
        {
            stationName = stationName.ToUpper();

            if (bikesCache.Contains(stationName))
            {
                return((int)bikesCache.Get(stationName));
            }
            else
            {
                velibWeb = new VelibWeb(key);
                var response = velibWeb.ConnectToAPI("stations?");
                if (response.Equals("KO"))
                {
                    return(-1);
                }

                var stations         = JsonConvert.DeserializeObject <List <Station> >(response);
                int responseToClient = -1;
                foreach (Station station in stations)
                {
                    if (station.name.Equals(stationName))
                    {
                        responseToClient = station.available_bikes;
                        CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();
                        cacheItemPolicy.AbsoluteExpiration = DateTime.Now.AddMinutes(1);
                        contractsCache.Add(stationName, responseToClient, cacheItemPolicy);
                        break;
                    }
                }

                return(responseToClient);
            }
        }
Example #2
0
        public List <String> CitiesInContract(String contractName)
        {
            contractName = contractName.ToUpper();
            if (citiesCache.Contains(contractName))
            {
                return((List <String>)citiesCache.Get(contractName));
            }
            else
            {
                velibWeb = new VelibWeb(key);
                var response = velibWeb.ConnectToAPI("contracts?");
                if (response.Equals("KO"))
                {
                    return(null);
                }
                List <Contract> contracts = JsonConvert.DeserializeObject <List <Contract> >(response);

                List <String> responseToClient = new List <String>();
                foreach (Contract contract in contracts)
                {
                    if (contract.name.ToUpper().Equals(contractName))
                    {
                        foreach (String city in contract.cities)
                        {
                            responseToClient.Add(city);
                        }
                        break;
                    }
                }
                CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();
                cacheItemPolicy.AbsoluteExpiration = DateTime.Now.AddMinutes(1);
                contractsCache.Add(contractName, responseToClient, cacheItemPolicy);
                return(responseToClient);
            }
        }
Example #3
0
 public List <Contract> Contracts()
 {
     if (contractsCache.Contains("Contracts"))
     {
         return((List <Contract>)contractsCache.Get("Contracts"));
     }
     else
     {
         velibWeb = new VelibWeb(key);
         var response = velibWeb.ConnectToAPI("contracts?");
         if (response.Equals("KO"))
         {
             return(null);
         }
         List <Contract> contracts       = JsonConvert.DeserializeObject <List <Contract> >(response);
         CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();
         cacheItemPolicy.AbsoluteExpiration = DateTime.Now.AddMinutes(1);
         contractsCache.Add("Contracts", contracts, cacheItemPolicy);
         return(contracts);
     }
 }
Example #4
0
        public List <Station> StationsOfTheCity(String cityName)
        {
            cityName = cityName.ToUpper();
            if (stationsCache.Contains(cityName))
            {
                return((List <Station>)stationsCache.Get(cityName));
            }
            else
            {
                velibWeb = new VelibWeb(key);
                var response = velibWeb.ConnectToAPI("stations?contract=" + cityName);
                if (response.Equals("KO"))
                {
                    return(null);
                }
                var stations = JsonConvert.DeserializeObject <List <Station> >(response);

                CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();
                cacheItemPolicy.AbsoluteExpiration = DateTime.Now.AddMinutes(1);
                contractsCache.Add(cityName, stations, cacheItemPolicy);
                return(stations);
            }
        }