private static List <WeatherObject> parceForecastWeatherJsonString(string jsonContentString) { List <WeatherObject> forecast = new List <WeatherObject>(); try { JObject obj = JObject.Parse(jsonContentString); JObject cityJson = (JObject)obj["city"]; CityObject city = parceCity(cityJson); JArray weatherList = (Newtonsoft.Json.Linq.JArray)obj["list"]; foreach (JObject weatherJson in weatherList) { WeatherObject weatherObj = parceWeather(city, weatherJson); weatherObj = parceForecastMainWeather(weatherObj, weatherJson); forecast.Add(weatherObj); } return(forecast); } catch (JsonReaderException e) { System.Diagnostics.Debug.WriteLine("-- Error parce json: {0} --", e.Message); } return(null); }
void locationEventHandleAction(MvxGeoLocation location) { string lat = location.Coordinates.Latitude.ToString(); string lon = location.Coordinates.Longitude.ToString(); CityObject city = new CityObject(null, null, new CityCoordinate(lat, lon)); WeatherMainModel pageModel = new WeatherMainModel(city); _currentLocationPageView = new WeatherMainPageViewModel(pageModel); }
private static WeatherObject parceWeather(CityObject city, JObject obj) { WeatherObject weather = new WeatherObject(city); var weatherJson = obj["weather"][0]; weather.Id = (int)weatherJson["id"]; weather.Main = (string)weatherJson["main"]; weather.Description = (string)weatherJson["description"]; weather.Icon = (string)weatherJson["icon"]; return(weather); }
//GetCurrentWeather public void GetCurrentWeather(CityObject city, Action <WeatherObject, WebException> eventHandler) { if (eventHandler != null) { if (city != null) { _openWeatherHttpRequest.GetWeatherWebRequests(city, eventHandler); } else { eventHandler(null, new WebException("City is null")); } } }
public void GetWeatherByCoordinates(CityCoordinate coordinate, Action <WeatherObject, WebException> eventHandler) { CityObject city = new CityObject(null, null, coordinate); if (eventHandler != null) { if (city != null) { _openWeatherHttpRequest.GetWeatherWebRequests(city, eventHandler); } else { eventHandler(null, new WebException("City is null")); } } }
public void GetForecastWeatherByCityName(string name, Action <List <WeatherObject>, WebException> eventHandler) { CityObject city = new CityObject(null, name, new CityCoordinate(null, null)); if (eventHandler != null) { if (city != null) { _openWeatherHttpRequest.GetForecastWeatherWebRequests(city, eventHandler); } else { eventHandler(null, new WebException("City is null")); } } }
private static WeatherObject parceCurrentWeatherJsonString(string jsonContentString) { try { JObject obj = JObject.Parse(jsonContentString); CityObject city = parceCity(obj); WeatherObject weather = parceWeather(city, obj); weather = parceCurrentMainInfoWeather(weather, (JObject)obj["main"]); weather = parceWindWeather(weather, (JObject)obj["wind"]); return(weather); } catch (JsonReaderException e) { System.Diagnostics.Debug.WriteLine("-- Error parce json: {0} --", e.Message); } return(null); }
public void GetForecastWeatherWebRequests(CityObject city, Action <List <WeatherObject>, WebException> eventHandler) { string urlRequestString = this.getUrlWeatherString(city, _urlForecastWeatherString); if (urlRequestString != null) { _wepRequest = WebRequest.CreateHttp(urlRequestString); _wepRequest.ContentType = "application/json"; _wepRequest.Method = "GET"; sendRequest((HttpWebResponse responce, WebException e) => { httpForecastWeatherWepResponceEventHandler(responce, e, eventHandler); }); } else { eventHandler(null, new WebException("City parametrs is null")); } }
private string getUrlWeatherString(CityObject city, string urlRequestString) { if ((city.Coordinates.Latitude != null) && (city.Coordinates.Longitude != null)) { return(string.Format(urlRequestString + "?lat={0}&lon={1}&APPID={2}", city.Coordinates.Latitude, city.Coordinates.Longitude, APIIDKey)); } else if (city.Id != null) { return(string.Format(urlRequestString + "?id={0}&APPID={1}", city.Id, APIIDKey)); } else if (city.Name != null) { return(string.Format(urlRequestString + "?q={0}&APPID={1}", city.Name, APIIDKey)); } return(null); }
public WeatherObject(CityObject city) : base() { this.City = city; }
public WeatherMainModel(CityObject city) : base(city) { ForecastWeather = new WeatherForecastModel(city); }
public WatherCurrentModel(CityObject city) : base() { CurrentWeather = new WeatherObject(city); }
public WeatherForecastModel(CityObject city) : base() { _currentCity = city; }