Exemplo n.º 1
0
        public async Task<List<ClosestPointModel>> BindData(string adress)
        {
           
            var client = new RestClient("https://geocode-maps.yandex.ru/1.x/?format=json&lang=uk_Ua&geocode="+adress);

            var request = new RestRequest("resource/", Method.GET);
            
            var data = await client.GetTaskAsync<GeocodeModel.RootObject>(request);

            var latitude = data.response.GeoObjectCollection.featureMember[0].GeoObject.Point.pos[0];
            var longitude = data.response.GeoObjectCollection.featureMember[0].GeoObject.Point.pos[1];
            
            RepositoryHolder holder = new RepositoryHolder();

            ClosestPointMapper mapper = new ClosestPointMapper();
            var adressRepository = holder.AdressRepository;
           List<ClosestPointModel> resultData =
                adressRepository.
                    Fetch().
                    Select(p => mapper.EntityToUI(p, latitude, longitude))
                    .OrderBy(z => z.FakeLatitude).
                    ThenBy(z => z.FakeLongitude).
                    Take(20).ToList();

           
            return resultData;
        }
        private async Task GetDeviceData(TokenResponseDto token)
        {
            var client = new RestClient("https://api.netatmo.com");
            var request = new RestRequest("/api/getstationsdata");
            request.AddQueryParameter("access_token", token.AccessToken);

            var data = await client.GetTaskAsync<StationDataResponseDto>(request);

            if (data?.Body?.Devices == null)
            {
                return;
            }

            lock (_deviceLock)
            {
                foreach (var dataDevice in data.Body.Devices)
                {
                    var station = dataDevice.StationName;
                    dataDevice.BatteryPercent = 100;

                    UpdateDevice(station, dataDevice);

                    if (dataDevice.Modules == null)
                    {
                        continue;
                    }

                    foreach (var module in dataDevice.Modules)
                    {
                        UpdateDevice(station, module);
                    }
                }
            }
        }