Esempio n. 1
0
 public FavoriteLocation(StationLocation station)
 {
     this.Station = station;
     this.Name = station.Name;
     this.City = station.City;
     this.Address = station.Address;
     this.Coordinate = new GeoCoordinate(station.Latitude, station.Longitude);
     this.FavoriteType = Model.FavoriteType.Station;
 }
        public override IObservable<StationAndAvailability> GetAvailability2(StationLocation station, bool forceUpdate = false)
        {
            if (!forceUpdate)
            {
                var availability = GetAvailabilityFromCache(station);
                if (availability.Availability != null)
                    return Observable.Return<StationAndAvailability>(availability);
            }

            return DownloadStationsWithAvailability(station.City)
                .Select(sl => sl.Where(sa => sa.Station.Number == station.Number).FirstOrDefault());
        }
Esempio n. 3
0
        public override IObservable<StationAndAvailability> GetAvailability2(StationLocation station, bool forceUpdate = false)
        {
            if (!forceUpdate)
            {
                var availability = GetAvailabilityFromCache(station);
                if (availability.Availability != null)
                    return Observable.Return<StationAndAvailability>(availability);
            }

            return DownloadUrl.GetAsync<AzureService.StationInfo>(GetStationDetailsUri(station.City, station.Number.ToString()), AzureServiceCredentials.AuthHeaders)
                .Retry(1)
                .ObserveOn(ThreadPoolScheduler.Instance)
                .Select(s =>
                {
                    var sa = new StationAndAvailability(station, s.GetAvailability());
                    UpdateAvailabilityCacheItem(sa);
                    return sa;
                });
        }
        public override IObservable<StationAndAvailability> GetAvailability2(StationLocation station, bool forceUpdate = false)
        {
            if (!forceUpdate)
            {
                var availability = GetAvailabilityFromCache(station);
                if (availability.Availability != null)
                    return Observable.Return<StationAndAvailability>(availability);
            }

            switch (station.City)
            {
                case "antwerpen":
                    var urlData = string.Format("idStation={0}&s_id_idioma=en", station.Number);
                    return DownloadUrl.PostAsync(StationInfoUrl(station.City), urlData, station)
                        .Retry(1)
                        .ObserveOn(ThreadPoolScheduler.Instance)
                        .Select(s =>
                        {
                            var availability = LoadAvailabilityFromHTML(s.Object);
                            availability.Open = station.Open;
                            availability.Connected = true;
                            var sa = new StationAndAvailability(station, availability);
                            UpdateAvailabilityCacheItem(sa);
                            return sa;
                        });

                case "stockholm":
                    return DownloadUrl.GetAsync(string.Format(StationInfoUrl(station.City), station.Number))
                        .Retry(1)
                        .ObserveOn(ThreadPoolScheduler.Instance)
                        .Select(s =>
                        {
                            var availability = LoadAvailabilityFromHTML2(s);
                            availability.Open = station.Open;
                            availability.Connected = true;
                            var sa = new StationAndAvailability(station, availability);
                            UpdateAvailabilityCacheItem(sa);
                            return sa;
                        });

                default:
                    return base.GetAvailability2(station, forceUpdate);
            }
        }
 protected StationAndAvailability GetAvailabilityFromCache(StationLocation station)
 {
     StationAndAvailability result = new StationAndAvailability(station, null);
     CachedAvailability availability = null;
     lock (AvailabilityCache)
     {
         if (AvailabilityCache.TryGetValue(station.City + station.Number.ToString(), out availability) && !availability.IsOutdated(MaxCacheAge))
             result.Availability = availability.Availability;
     }
     return result;
 }
 public bool IsAvailabilityValid(StationLocation station)
 {
     CachedAvailability availability;
     lock (AvailabilityCache)
     {
         return (AvailabilityCache.TryGetValue(station.City + station.Number.ToString(), out availability) && !availability.IsOutdated(MaxCacheAge));
     }
 }
 public virtual IObservable<StationAndAvailability> GetAvailability2(StationLocation station, bool forceUpdate = false)
 {
     return null;
 }
 public virtual IObservable<StationAvailability> GetAvailability(StationLocation station, bool forceUpdate = false)
 {
     return GetAvailability2(station, forceUpdate)
         .Select(a => a != null ? a.Availability : null);
 }
 public City GetCityForStation(StationLocation station)
 {
     City result = null;
     if (station != null)
     {
         result = City;
         if (result == null || result.Provider == null || !string.Equals(station.City, result.UrlCityName))
             result = BikeServiceProvider.FindByCityName(station.City);
     }
     return result;
 }
Esempio n. 10
0
 public override IObservable<StationAndAvailability> GetAvailability2(StationLocation station, bool forceUpdate = false)
 {
     var city = FindCity(station.City);
     return city.Provider.GetAvailability2(station, forceUpdate);
 }
 public IObservable<StationAvailability> GetAvailability(StationLocation station, bool forceUpdate = false)
 {
     City scity = null;
     if (!GetCityForStation(station, out scity))
     {
         // maybe notify/log the error
         return Observable.Empty<StationAvailability>();
     }
     else
         return scity.Provider
             .GetAvailability(station, forceUpdate)
             .Do(a =>
             {
                 if (a != null)
                     station.Open = a.Open;
             });
 }
 public bool IsAvailabilityValid(StationLocation station)
 {
     City scity = null;
     if (!GetCityForStation(station, out scity))
     {
         // maybe notify/log the error
         return false;
     }
     else
         return scity.Provider.IsAvailabilityValid(station);
 }
 public bool GetCityForStation(StationLocation station, out City scity)
 {
     scity = GetCityForStation(station);
     return scity != null;
 }
Esempio n. 14
0
        private static List<StationAndAvailability> LoadStationsFromHTML(string stationsStr, string cityName)
        {
            if (string.IsNullOrWhiteSpace(stationsStr))
                return null;
            List<StationAndAvailability> stations = new List<StationAndAvailability>();

            const string CDataStr = @"""data"":""[{";
            const string CDataEndStr = @"}]"",""";
            var dataStart = stationsStr.IndexOf(CDataStr);
            if (dataStart > 0)
            {
                dataStart += CDataStr.Length - 2;
                var dataEnd = stationsStr.IndexOf(CDataEndStr, dataStart);
                if (dataEnd > 0)
                {
                    stationsStr = stationsStr.Substring(dataStart, dataEnd - dataStart + 2);
                }
            }

            stationsStr = Regex.Unescape(stationsStr);
            List<BicingAvailability> availabilityList = stationsStr.FromJson<List<BicingAvailability>>();
            foreach (var item in availabilityList)
            {
                if (string.IsNullOrEmpty(item.AddressStreet1))
                    continue;

                var station = new StationLocation();
                station.Name = item.StationName;
                station.Number = item.StationID;
                station.Latitude = item.AddressGmapsLatitude;
                station.Longitude = item.AddressGmapsLongitude;
                station.Open = item.StationStatusCode == "OPN";
                station.Address = item.AddressStreet1;
                station.City = cityName;
                if (!string.IsNullOrEmpty(item.AddressNumber))
                    station.Address += " " + item.AddressNumber;

                var availability = new StationAvailability();
                availability.Available = item.StationAvailableBikes;
                availability.Free = item.StationFreeSlot;
                availability.Total = availability.Available + availability.Free;
                availability.Open = station.Open;

                stations.Add(new StationAndAvailability(station, availability));
            }
            return stations;
        }
Esempio n. 15
0
 public StationAndAvailability(StationLocation station, StationAvailability availability)
 {
     this.Station = station;
     this.Availability = availability;
 }
Esempio n. 16
0
 public LocationState(StationLocation location)
 {
     this.Location = location;
 }
 public IObservable<StationAndAvailability> GetAvailability2(StationLocation station)
 {
     City scity = null;
     if (!GetCityForStation(station, out scity))
     {
         // maybe notify/log the error
         return Observable.Empty<StationAndAvailability>();
     }
     else
         return scity.Provider
             .GetAvailability2(station)
             .Do(a =>
             {
                 if (a != null && a.Availability != null)
                     station.Open = a.Availability.Open;
             });
 }