public object Convert(object value, Type targetType, object parameter, string language) { var weatherForecastProjection = (WeatherForecastProjection)value; var forecastCloudCoverIconNumber = Rp5Extensions.GetForecastCloudCoverIconNumber(weatherForecastProjection.Cloudiness.Percents); var text = Rp5Extensions.IsDayForecast(weatherForecastProjection) ? "day" : "night"; var bitmapImage = new BitmapImage(); bitmapImage.UriSource = new Uri($"ms-appx:///Assets/Rp5Icons/ic_forecast_cloud_cover_{text}_{forecastCloudCoverIconNumber}.png"); return(bitmapImage); }
public async Task <IList <WeatherForecastProjection> > GetForecastByCityIdAsync(int idCity) { var str1 = EncodeBase64String(idCity.ToString()); var str2 = Rp5StringProcess(Rp5CityIdProcessMethod(idCity * 3.141D, 3).ToString(EnUsCultureInfo)); var str3 = Rp5StringProcess(_md5AlgorithmProvider.GetMd5Hash(str2)); var str4 = EncodeBase64String("ru"); var requestUri = $"http://rp5.ru/wduck/i.php?city={str2}&api={str1}&io={str3}&l={str4}"; using (var httpClient = new HttpClient()) using (var httpResponse = await httpClient.GetAsync(requestUri)) { var response = await httpResponse.Content.ReadAsStringAsync(); var decodedRespose = DecodeResponse(response); var deserializedObject = JsonConvert.DeserializeObject <Rp5WeatherForecastRootObject>(decodedRespose); return(Rp5Extensions.ConvertToWeatherForecastProjections(deserializedObject)); } }
public object Convert(object value, Type targetType, object parameter, string language) { var weatherForecastProjection = (WeatherForecastProjection)value; var bitmapImage = new BitmapImage(); string text; object result; switch (weatherForecastProjection.PrecipitationType) { case PrecipitationType.Rain: text = "rain"; break; case PrecipitationType.RainAndSnow: text = "rain_and_snow"; break; case PrecipitationType.Snow: text = "snow"; break; default: bitmapImage.UriSource = new Uri("ms-appx:///Assets/Rp5Icons/ic_forecast_no_precipitation.png"); result = bitmapImage; return(result); } bitmapImage.UriSource = new Uri($"ms-appx:///Assets/Rp5Icons/ic_forecast_{text}_{Rp5Extensions.GetPrecipitationIconNumber(weatherForecastProjection.Precipitation.Mm)}.png"); result = bitmapImage; return(result); }