Ejemplo n.º 1
0
        public Weather Get(string region)
        {
            string        webRootPath     = _hostingEnvironment.WebRootPath;
            string        contentRootPath = _hostingEnvironment.ContentRootPath;
            string        path            = Path.GetDirectoryName(this.GetType().Assembly.Location);
            string        weatherPath     = Path.Combine(path, "Images/");
            Weather       weather         = new Weather();
            WeatherHelper weatherHelper   = new WeatherHelper();

            try
            {
                var dict1 = weatherHelper.GetTodayWeather2(string.Format(Config.Weather, region), weatherPath);
                if (dict1.Count > 0)
                {
                    weather.Region            = dict1["region"];
                    weather.Day               = dict1["day"];
                    weather.Week              = dict1["week"];
                    weather.LunarDay          = dict1["lunarDay"];
                    weather.NowTemperature    = dict1["nowTemperature"];
                    weather.LowTemperature    = dict1["lowTemperature"];
                    weather.HighTemperature   = dict1["highTemperature"];
                    weather.Describe          = dict1["describe"];
                    weather.Code              = dict1["code"];
                    weather.Image             = dict1["image"];
                    weather.WhiteImage        = dict1["whiteImage"];
                    weather.BlackImage        = dict1["blackImage"];
                    weather.AqiValue          = dict1["aqiValue"];
                    weather.AqiLevel          = dict1["aqiLevel"];
                    weather.AqiDescribe       = dict1["aqiDescribe"];
                    weather.ParticulateMatter = dict1["particulateMatter"];
                    weather.Humidity          = dict1["humidity"];
                    weather.Wind              = dict1["wind"];
                    weather.UltravioletRays   = dict1["ultravioletRays"];
                    weather.Sunrise           = dict1["sunrise"];
                    weather.Sunset            = dict1["sunset"];
                }
            }
            catch (Exception e) { }
            try
            {
                var dict2 = weatherHelper.GetTodayAQI(string.Format(Config.Aqi, region));
                if (dict2.Count > 0)
                {
                    weather.AqiValue    = dict2["idx"];
                    weather.AqiLevel    = dict2["aqiLevel"];
                    weather.AqiDescribe = dict2["qualityStr"];
                }
            }
            catch (Exception e) { }
            return(weather);
        }