Пример #1
0
        public static void Start()
        {
            YiScheduler.Instance.Do(TimeSpan.FromMinutes(60), Start);
            try
            {
                var json = WebClient.DownloadString(QueryString);
                _currentWeather = JsonConvert.DeserializeObject <WeatherJson>(json);

                switch (_currentWeather.weather.First().main)
                {
                case "Rain":
                    CurrentWeatherType = WeatherType.Rain;
                    SetRaining(150, (int)_currentWeather.wind.deg);
                    break;

                case "Snow":
                    CurrentWeatherType = WeatherType.Snow;
                    SetSnowing(150, (int)_currentWeather.wind.deg);
                    break;

                default:
                {
                    SetClear(150, (int)_currentWeather.wind.deg);
                    Output.WriteLine("Default Weather: " + _currentWeather.weather.First().main);
                    break;
                }
                }
            }
            catch (Exception e)
            {
                Output.WriteLine(e);
            }
        }
Пример #2
0
    private void OnWeatherDataLoaded(string data)
    {
        WeatherJson weatherData = JsonUtility.FromJson <WeatherJson>(data);

        CloudValue = weatherData.clouds.all / 100f;
        Messenger.Broadcast(GameEvent.WeatherUpdated);

        Status = ManagerStatus.Started;
    }
 public static WeatherModel ToWeatherModel(this WeatherJson jsonModel)
 {
     return(new WeatherModel
     {
         Name = jsonModel.Name,
         Icon = $"https://openweathermap.org/img/w/{jsonModel.Weathers.FirstOrDefault()?.Icon}.png",
         Description = jsonModel.Weathers.FirstOrDefault()?.Description,
         Temperature = string.Format("{0:F2}° C", KelvinToCelsius(jsonModel.Main.Temperature))
     });
 }
Пример #4
0
        public WeatherData GetWeatherData(Location location, WeatherUnits unit)
        {
            string url = BaseURL + "/data/2.5/weather?";

            if (location is CityLocation)
            {
                CityLocation loc = (CityLocation)location;
                url += "q=" + loc.cityName;
                if (!System.String.IsNullOrEmpty(loc.countryCode))
                {
                    url += "," + loc.countryCode;
                }
            }
            else if (location is Ziplocation)
            {
                Ziplocation loc = (Ziplocation)location;
                url += "zip=" + loc.zipCode + "," + loc.countryCode;
            }
            else if (location is CoordinateLocation)
            {
                CoordinateLocation loc = (CoordinateLocation)location;
                url += "lat=" + loc.lat + "&lon=" + loc.lon;
            }
            else
            {
                throw new WeatherDataServiceException("unsupported location type");
            }
            if (unit == WeatherUnits.Celsius)
            {
                url += "&units=metric";
            }
            else if (unit == WeatherUnits.Fahrenheit)
            {
                url += "&units=imperial";
            }
            else if (unit == WeatherUnits.Kelvin)
            {
            }
            else
            {
                throw new WeatherDataServiceException("unsupported unit type");
            }
            url += "&appid=" + APIKey;

            DataContractJsonSerializer parser = new DataContractJsonSerializer(typeof(WeatherJson));
            WeatherJson json = (WeatherJson)parser.ReadObject(MakeWebRequest(url));

            return(FromJsonToData(json, location, unit));
        }
Пример #5
0
        private WeatherData FromJsonToData(WeatherJson json, Location location, WeatherUnits unit)
        {
            WeatherData data = new WeatherData();

            data.date        = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime().AddSeconds(json.dt);
            data.unit        = unit;
            data.location    = location;
            data.humidity    = json.main.humidity;
            data.temp        = json.main.temp;
            data.windSpeed   = json.wind.speed;
            data.clouds      = json.clouds.all;
            data.status      = json.weather.First().main;
            data.description = json.weather.First().description;
            return(data);
        }