Exemple #1
0
 private void UpdateDeviceValues(SunResponse data)
 {
     _sunDevice.SetValues(
         sunHours: data.results.day_length,
         sunRise: data.results.sunrise,
         sunSet: data.results.sunset
         );
 }
        public static SunTime GetSunTime(double lat, double lng)
        {
            DateTime     now     = DateTime.Now;
            string       uri     = "https://api.sunrise-sunset.org/json?lat=" + lat + "&lng=" + lng + "&date=" + string.Format("{0:yyyy-MM-dd}", now) + "&formatted=0";
            WebRequest   request = WebRequest.Create(uri);
            Stream       stream  = request.GetResponse().GetResponseStream();
            StreamReader reader  = new StreamReader(stream);
            string       res     = reader.ReadToEnd();

            SunResponse parsed = JsonConvert.DeserializeObject <SunResponse>(res);

            return(parsed.results);
        }