예제 #1
0
        public static CityWeatherData FromApiData(CurrentWeatherInfo apiInfo)
        {
            var data = new CityWeatherData();

            if (null != apiInfo)
            {
                data.CityName    = apiInfo.name;
                data.CountryName = apiInfo.sys.country;
                data.CityId      = apiInfo.id;
                data.Temperature = apiInfo.main.temp;
                foreach (var inf in apiInfo.weather)
                {
                    var end = " ";
                    if (apiInfo.weather.Count > 1)
                    {
                        end = " ,";
                    }
                    data.WeatherInfo = inf.description + end;
                }
                data.WeatherInfo        = data.WeatherInfo.FirstCharToUpper();
                data.MainWeatherImageId = apiInfo.weather[0].id;
                data.LastUpdateTime     = apiInfo.dt;
                data.SunriseTime        = apiInfo.sys.sunrise;
                data.SunsetTime         = apiInfo.sys.sunset;
                data.Humidity           = apiInfo.main.humidity;
                data.Pressure           = apiInfo.main.pressure;
                data.Wind = apiInfo.wind.speed;
            }

            return(data);
        }
예제 #2
0
        public MainVM()
        {
            Weather          = new CurrentWeatherInfo();
            FWeather         = new ForecastWeatherInfo();
            ClothesInfo      = new ClothesSetInfo();
            MainCommand      = new MainBtnCommand(this);
            DeletecolCommand = new DeleteColCombiCommand(this);
            Cnt        = 0;
            ClothesCnt = 0;

            ClothesInfo.ValueDic = setDictValue();

            //옷들 사이의 연결관계 만들기
            ClothesInfo.OuterBytop     = outerBytopSet();
            ClothesInfo.TopBytop       = topBytopSet();
            ClothesInfo.TopBybottom    = topBybottomSet();
            ClothesInfo.TopSolo        = topSoloSet();
            ClothesInfo.TopBybottomCol = topBybottomColSet();
            ClothesInfo.OuterByTopCol  = outerBytopColSet();
            ClothesInfo.OuterByBottom  = OuterByBottomSet();
            ClothesInfo.TopByskirt     = topByskirtSet();
            ClothesInfo.OuterBySkirt   = outerByskirtSet();
            ClothesInfo.TopBySkirtCol  = topByskirtColSet();

            RenewFiles();
            GetWeather();
            GetFWeather();
            SetClothes();
        }
예제 #3
0
        public static CurrentWeatherInfo GetWeatherInformation(string cityName)
        {
            CurrentWeatherInfo result = new CurrentWeatherInfo();

            string url = string.Format(BASE_URL, cityName, API_KEY);

            using (HttpClient Client = new HttpClient())
            {
                var    response = Client.GetAsync(url);
                string json     = response.Result.Content.ReadAsStringAsync().Result;

                result = JsonConvert.DeserializeObject <CurrentWeatherInfo>(json);
            }
            return(result);
        }
        private double GetCurrentTemperature(double kelvin)
        {
            double             convertKelvinToFahrenheit = Convert.ToDouble(((kelvin - 273.15) * 9 / 5) + 32);
            CurrentWeatherInfo currentWeather            = new CurrentWeatherInfo
            {
                Temperature = Math.Round(convertKelvinToFahrenheit, 2)
            };

            try
            {
                return(currentWeather.Temperature);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                _context.SaveChangesAsync();
            }
            return(currentWeather.Temperature);
        }