Exemplo n.º 1
0
        /// <summary>
        /// Locks a bikestand and updates the interface
        /// </summary>
        private void Lock()
        {
            BikeStandRegistration bikestandRegistration = null;

            if (int.TryParse(LockID, out int convertedLockID))
            {
                bikestandRegistration = serverClient.Lock(convertedLockID);
            }
            else
            {
                IsLockErrorVisible = true;
            }
            if (bikestandRegistration != null)
            {
                BikeStation bikeStation = serverClient.GetBikeStation("" + bikestandRegistration.BikeStandID);
                IsAddFriendEnabled   = true;
                IsLockIDEnabled      = false;
                LockVisible          = false;
                UnlockVisible        = true;
                IsLockErrorVisible   = false;
                IsAddFriendVisible   = true;
                BikeStationText      = String.Format("Your bike was locked at {0} on the {1}", bikeStation.title, bikestandRegistration.RegistrationTime);
                IsBikeStationVisible = true;
            }
            else
            {
                IsLockErrorVisible = true;
            }
        }
Exemplo n.º 2
0
        private static async Task <List <BikeStation> > ProcessRepositories(String city)
        {
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter");
            if (city.ToLower() == "bordeaux")
            {
                var streamTask      = client.GetStreamAsync("https://api.alexandredubois.com/vcub-backend/vcub.php");
                var bikeStationsbdx = await JsonSerializer.DeserializeAsync <List <BikeStationBdx> >(await streamTask);

                var listBikestation = new List <BikeStation>();
                foreach (var bikeStation in bikeStationsbdx)
                {
                    var bikeStations = new BikeStation(bikeStation);
                    listBikestation.Add(bikeStations);
                }
                return(listBikestation);
            }
            else
            {
                var streamTask   = client.GetStreamAsync("https://download.data.grandlyon.com/ws/rdata/jcd_jcdecaux.jcdvelov/all.json");
                var bikeStations = await JsonSerializer.DeserializeAsync <RootObject>(await streamTask);

                return(bikeStations.values);
            }
        }
Exemplo n.º 3
0
 public bool RepairStation(BikeStation station)
 {
     if (station.StationStatus == false)
     {
         return(false);
     }
     else
     {
         station.StationStatus = false;
         return(true);
     }
 }
Exemplo n.º 4
0
        private static async Task <List <BikeStation> > ProcessRepositoriesBdx()
        {
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter");

            var streamTask      = client.GetStreamAsync("https://api.alexandredubois.com/vcub-backend/vcub.php");
            var bikeStationsbdx = await JsonSerializer.DeserializeAsync <List <BikeStationBdx> >(await streamTask);

            var listBikestation = new List <BikeStation>();

            foreach (var bikeStation in bikeStationsbdx)
            {
                var bikeStations = new BikeStation(bikeStation);
                listBikestation.Add(bikeStations);
            }
            return(listBikestation);
        }
Exemplo n.º 5
0
        public static int FindDistance(BikeStation mystation, BikeStation station)
        {
            /*
             *  Using GPS Lat/Lng
             *  ROUGH CALC, not exact! (doesnt need to be; just need ballpark nearby stations)
             *  Conversion: 1000m distance = approx 0.01 GPS       -> multiply x 10^6
             *  - TODO: investigate GPS based on region/city to see if this GPS->Metres conversion varies
             */

            double latdiff = Math.Abs(mystation.position.lat - station.position.lat) * 100000;
            double lngdiff = Math.Abs(mystation.position.lng - station.position.lng) * 100000;  // to metres
            //  int simple_dist = (int)(latdiff > lngdiff ? latdiff : lngdiff);        // take larger
            // better to use Pythagoras! if lat == long, error would be 41%! (sqrt 2)
            double pythag_dist = Math.Sqrt(Math.Pow(latdiff, 2) + Math.Pow(lngdiff, 2));


            return((int)pythag_dist);
        }
Exemplo n.º 6
0
        /// <summary>
        /// This method updates the interface according to the relevant data from the backend when the Actionview appears
        /// </summary>
        public void OnAppearing()
        {
            if (sharedData.ScannedBikestandID != null)
            {
                int qrLockID;
                if (int.TryParse(sharedData.ScannedBikestandID, out qrLockID))
                {
                    LockID = "" + qrLockID;
                }
            }
            sharedData.ScannedBikestandID = null;
            BikeStandRegistration bikestandRegistration = serverClient.GetLockedBikestand();

            if (bikestandRegistration != null)
            {
                LockID             = "" + bikestandRegistration.BikeStandID;
                LockVisible        = false;
                UnlockVisible      = true;
                IsLockIDEnabled    = false;
                IsAddFriendEnabled = true;
                IsAddFriendVisible = true;
                BikeStation bikeStation = serverClient.GetBikeStation("" + bikestandRegistration.BikeStandID);
                if (bikeStation != null)
                {
                    BikeStationText      = String.Format("Your bike was locked at {0} on the {1}", bikeStation.title, bikestandRegistration.RegistrationTime);
                    IsBikeStationVisible = true;
                }
                String sharedWithUsername = serverClient.GetSharedUsername();
                if (!String.IsNullOrEmpty(sharedWithUsername))
                {
                    sharedAccessTo     = sharedWithUsername;
                    SharedWithText     = "Shared with: " + sharedAccessTo;
                    IsShared           = true;
                    IsAddFriendEnabled = false;
                }
            }
            else
            {
                IsAddFriendVisible   = false;
                IsBikeStationVisible = false;
                IsShared             = false;
                IsAddFriendEnabled   = true;
            }
        }
        public async Task <IActionResult> GetStationById(CityEnum city, int id = 11)
        {
            List <BikeStation> stations = (List <BikeStation>)cache.CheckCache(city.ToString());
            BikeStation        station  = null;

            if (stations != null)
            {
                station = stations.Single(x => x.stationNumber == id);
            }
            else
            {
                string result = await dbhelper.GetStation(city.ToString(), id);

                station = JsonConvert.DeserializeObject <BikeStation>(result);
            }
            List <BikeStation> stationAsList = new List <BikeStation>()
            {
                station
            };

            return(Ok(stationAsList));
        }
Exemplo n.º 8
0
        public static List <BikeStation> FindNearbyStations(List <BikeStation> stations, BikeStation mystation, int metres)
        {
            var s = stations.Where(x => FindDistance(mystation, x) < metres).ToList();

            return(s);
        }