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;
 }
示例#2
0
        /// <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);
        }
示例#3
0
		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);
        }
示例#5
0
        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;
        }
示例#6
0
		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;
		}
示例#7
0
        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;
        }
示例#8
0
 public static bool IsGoodWeather(WeatherCode weatherCode)
 {
     return(new[] { WeatherCode.Sunny, WeatherCode.Dry, WeatherCode.Humid }.Contains(weatherCode));
 }
示例#9
0
 // -------------------------------------------------------------------------------------------
 void DecodeWeather(ref int _value, WeatherCode _code)
 {
     CodeConfig.Me.Calculate(_code.weatherType, ref _value, _code.Temperature);
 }