Exemple #1
0
        public async Task <WeatherResponse> GetWeatherResponse(string cityName)
        {
            requestJsonService  = new RequestJsonService();
            requestImageService = new RequestImageService();

            var requestUrl = string.Format(queryEndpoint, cityName, appId);
            var json       = await requestJsonService.RequestJsonAsync(requestUrl).ConfigureAwait(false);

            if (string.IsNullOrEmpty(json))
            {
                return(new WeatherResponse());
            }
            var weather = JsonConvert.DeserializeObject <WeatherResponse>(json);

            var requestIconUrl    = string.Format(queryIconEndpoint, weather.Weather.First().Icon);
            var responseByteArray = await requestImageService.RequestByteArrayAsyc(requestIconUrl).ConfigureAwait(false);

            if (responseByteArray != null)
            {
                NSData  nsdata = NSData.FromArray(responseByteArray);
                NSImage image  = new NSImage(nsdata);

                weather.ImageDownloaded = image;
            }

            return(weather);
        }
        public MainWindowViewModel()
        {
            requestJsonService = new RequestJsonService();

            var cities = requestJsonService.RequestLocalJson(path).Result;

            if (string.IsNullOrEmpty(cities))
            {
                Cities = new List <City>();
            }
            Cities = JsonConvert.DeserializeObject <IList <City> >(cities);
        }