public WeatherForecast() { this.Day = DateTime.Now; this.DayOfTheWeekDescription = this.Day.DayOfWeek.ToString(); this.MaximumTemperature = 0; this.MinimumTemperature = 0; this.TemperatureDescription = this.MaximumTemperature + "/" + this.MinimumTemperature; this.WeatherDescription = WeatherControl.NoDataResult; this.WeatherDescriptionCode = WeatherControl.NoCodeResult; this.WeatherCode = WeatherCode.Undefined; }
/// <summary> /// 拿的城市代码的一维数组,然后以-(-分割开 /// </summary> /// <param name="array"></param> /// <returns></returns> public static List <WeatherCode> GetWeatherCode(string[] array) { List <WeatherCode> weatherList = new List <WeatherCode>(); foreach (var item in array) { WeatherCode weatherCode = new WeatherCode(); weatherCode.WeatherName = item.Split('(')[0].Trim().ToString(); //Regex.Split(item, "(", RegexOptions.IgnoreCase)[0].Trim().ToString(); weatherCode.WeahterCode = item.Split('(')[1].TrimEnd(')').Trim().ToString(); weatherList.Add(weatherCode); } return(weatherList); }
public Forecast( DateTime date, int minTemperature, int maxTemperature, WeatherCode weatherCode) { if (!Enum.IsDefined(typeof(WeatherCode), weatherCode)) { throw new ArgumentException("Invalid weatherCode"); } this.date = date; this.minTemperature = minTemperature; this.maxTemperature = maxTemperature; this.weatherCode = weatherCode; }
public WeatherForecast(XNode xmlInformation) { string dateString = ((XElement)xmlInformation).Attribute("date").Value.ToString(); int day = Convert.ToInt32(dateString.Split(' ')[0]); int month = DateTime.ParseExact(dateString.Split(' ')[1], "MMM", System.Globalization.CultureInfo.InvariantCulture).Month; int year = Convert.ToInt32(dateString.Split(' ')[2]); this.Day = new DateTime(year, month, day); this.DayOfTheWeekDescription = this.Day.DayOfWeek.ToString(); this.MaximumTemperature = Convert.ToInt32(((XElement)xmlInformation).Attribute("high").Value.ToString()); this.MinimumTemperature = Convert.ToInt32(((XElement)xmlInformation).Attribute("low").Value.ToString()); this.TemperatureDescription = this.MaximumTemperature + "/" + this.MinimumTemperature; this.WeatherDescription = ((XElement)xmlInformation).Attribute("text").Value.ToString(); this.WeatherDescriptionCode = ((XElement)xmlInformation).Attribute("code").Value.ToString(); this.WeatherCode = (WeatherCode)Enum.Parse(typeof(WeatherCode), this.WeatherDescriptionCode); }
public Forecast( DateTime date, int minTemperature, int maxTemperature, WeatherCode weatherCode, int minRelativeHumidity, int maxRelativeHumidity, Wind wind) : this(date, minTemperature, maxTemperature, weatherCode) { if ((minRelativeHumidity < MIN_VALID_HUMIDITY) || (minRelativeHumidity > MAX_VALID_HUMIDITY)) { throw new ArgumentOutOfRangeException("minRelativeHumidity"); } if ((maxRelativeHumidity < MIN_VALID_HUMIDITY) || (maxRelativeHumidity > MAX_VALID_HUMIDITY)) { throw new ArgumentOutOfRangeException("maxRelativeHumidity"); } this.minRelativeHumidity = minRelativeHumidity; this.maxRelativeHumidity = maxRelativeHumidity; this.wind = wind; }
public static bool IsGoodWeather(WeatherCode weatherCode) { return(new[] { WeatherCode.Sunny, WeatherCode.Dry, WeatherCode.Humid }.Contains(weatherCode)); }
// ------------------------------------------------------------------------------------------- void DecodeWeather(ref int _value, WeatherCode _code) { CodeConfig.Me.Calculate(_code.weatherType, ref _value, _code.Temperature); }