public WeatherDashboardModel Map(DarkSkyModel model) { var dashboardModel = new WeatherDashboardModel(); dashboardModel.CurrentCelsius = model.Currently.Temperature; dashboardModel.CurrentFahrenheit = model.Currently.Temperature * (decimal)1.8 + 32; //using conversion formula dashboardModel.CurrentSummary = model.Currently.Summary; dashboardModel.Icon = model.Currently.Icon; dashboardModel.IconUrl = null; dashboardModel.Forecast = new List <DayDashboard>(); foreach (var day in model.Daily.Data.Take(int.Parse(settingsManager.Get(Constants.FORECAST_DEFAULT_SIZE)))) { var dayDashboard = new DayDashboard(); dayDashboard.Summary = day.Summary; dayDashboard.LowCelsius = day.TemperatureLow; dayDashboard.LowFahrenheit = day.TemperatureLow * (decimal)1.8 + 32; dayDashboard.HighCelsius = day.TemperatureHigh; dayDashboard.HighFahrenheit = day.TemperatureHigh * (decimal)1.8 + 32; dayDashboard.Icon = day.Icon; dayDashboard.IconUrl = null; dayDashboard.Date = new DateTime(1970, 1, 1).AddSeconds(day.Time); dashboardModel.Forecast.Add(dayDashboard); } return(dashboardModel); }
public async void GetWeatherData() { string responseBody = string.Empty; using (HttpClient client = new HttpClient()) { responseBody = await client.GetStringAsync($"{DarkSkyUri}{latitude},{longitude}?units=si"); } DarkSkyModel model = JsonConvert. DeserializeObject <JObject>(responseBody). ToObject <DarkSkyModel>(); Temperature = model.currently.temperature.ToString(); }
private DarkSkyModel GetDarkSkyModel() { var model = new DarkSkyModel(); model.Currently = new Currently(); model.Currently.Icon = "Numb"; model.Currently.Summary = "Cloudy"; model.Currently.Temperature = 30; model.Currently.Time = 1111111; model.Daily = new Daily(); model.Daily.Data = new List <DarkSkyDay>(); model.Daily.Data.Add(new DarkSkyDay() { Icon = "Numb", Summary = "Cloudy", TemperatureLow = 20, TemperatureHigh = 50, Time = 1122323 }); return(model); }
public void Initialize() { settingsManager = new Mock <ISettingsManager>(); model = GetDarkSkyModel(); }