public AFValues GetBikeStationValues(BikeStation bikeStation, AFElement element)
        {
            AFValues values = new AFValues();

            if ((element.Attributes["Free Bikes"] != null) && (element.Attributes["Free Bikes"].PIPoint != null))
            {
                values.Add(new AFValue(element.Attributes["Free Bikes"], bikeStation.free_bikes, new OSIsoft.AF.Time.AFTime(bikeStation.timestamp)));
            }
            if ((element.Attributes["Empty Slots"] != null) && (element.Attributes["Empty Slots"].PIPoint != null))
            {
                values.Add(new AFValue(element.Attributes["Empty Slots"], bikeStation.empty_slots, new OSIsoft.AF.Time.AFTime(bikeStation.timestamp)));
            }
            return(values);
        }
        public async Task <List <BikeStation> > GetCityBikeStations(Network network)
        {
            dynamic dObj = await CustomHttpRequest.Instance.GetNetworkStationsData(network);

            if (dObj == null)
            {
                return(new List <BikeStation>());
            }
            List <BikeStation> bikeStationList = new List <BikeStation>();

            if (dObj["network"]["stations"] != null)
            {
                for (int i = 0; i < dObj["network"]["stations"].Count; i++)
                {
                    BikeStation bikeStation = new BikeStation();
                    bikeStation.StationNumber = i + 1;
                    if (dObj["network"]["stations"][i].empty_slots != null)
                    {
                        bikeStation.empty_slots = Convert.ToInt32(dObj["network"]["stations"][i].empty_slots.Value.ToString());
                    }
                    if (dObj["network"]["stations"][i].free_bikes != null)
                    {
                        bikeStation.free_bikes = Convert.ToInt32(dObj["network"]["stations"][i].free_bikes.Value.ToString());
                    }
                    bikeStation.id        = dObj["network"]["stations"][i].id.Value.ToString();
                    bikeStation.latitude  = Convert.ToDouble(dObj["network"]["stations"][i].latitude.Value.ToString());
                    bikeStation.longitude = Convert.ToDouble(dObj["network"]["stations"][i].longitude.Value.ToString());
                    bikeStation.name      = dObj["network"]["stations"][i].name.Value.ToString();
                    bikeStation.timestamp = DateTime.Now;
                    bikeStationList.Add(bikeStation);
                    //if (IsValid(bikeStation.name))
                    //{
                    //    bikeStationList.Add(bikeStation);
                    //}
                    //else
                    //{
                    //    log.Info($"{bikeStation.name} is not a valid name. ");
                    //}
                }
            }

            return(bikeStationList);
        }
        public bool CreateBikeStation(BikeStation bikeStation, AFElement cityElement)
        {
            AFElement element = cityElement.Elements[bikeStation.FixedName];

            if (element != null)
            {
                return(false);
            }

            try
            {
                element = cityElement.Elements.Add(bikeStation.FixedName, afDb.ElementTemplates[bikeStationElementTemplateName]);
                element.Attributes["Id"].SetValue(new AFValue(bikeStation.id));
                element.Attributes["Longitude"].SetValue(new AFValue(bikeStation.longitude));
                element.Attributes["Latitude"].SetValue(new AFValue(bikeStation.latitude));
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }