public StationAvailabilityViewModel(StationAvailability stationAvailability)
 {
     this.stationAvailability = stationAvailability;
 }
        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;
        }
        private StationAvailability LoadAvailabilityFromHTML2(string statusStr)
        {
            XDocument doc = XDocument.Load(new System.IO.StringReader(statusStr));
            var bikes = doc.Descendants("div").Where(el => (string)el.Attribute("class") == "rackInfo_infoReady").FirstOrDefault();
            var docks = doc.Descendants("div").Where(el => (string)el.Attribute("class") == "rackInfo_infoEmpty").FirstOrDefault();

            var sa = new StationAvailability();
            sa.Available = bikes != null ? (int)bikes : 0;
            sa.Free = docks != null ? (int)docks : 0;
            sa.Total = sa.Free + sa.Available;
            return sa;
        }
 private StationAvailability LoadAvailabilityFromHTML(string s)
 {
     var bikePos = s.IndexOf("Bicycles", StringComparison.InvariantCultureIgnoreCase);
     if (bikePos > 0)
         s = s.Substring(bikePos);
     var numbersOnly = new Regex("\\d+", RegexOptions.Compiled);
     var matches = numbersOnly.Matches(s);
     var sa = new StationAvailability();
     sa.Available = int.Parse(matches[0].Value);
     sa.Free = int.Parse(matches[1].Value);
     sa.Total = sa.Free + sa.Available;
     return sa;
 }
 public void Update(StationAvailability availability)
 {
     this.Availability = availability;
     this.LastUpdate = DateTime.Now;
 }
 public StationAndAvailability(StationLocation station, StationAvailability availability)
 {
     this.Station = station;
     this.Availability = availability;
 }