Esempio n. 1
0
        protected override WeatherInfo ParseWeatherInfo(string content)
        {
            WeatherInfo info = new WeatherInfo();

            if (content.IndexOf("180_180/qing_0") != -1)
            {
                info.weatherType = WeatherType.Sunny;
            }
            else if ((content.IndexOf("180_180/duoyun_0") != -1) || (content.IndexOf("180_180/yin_0") != -1))
            {
                info.weatherType = WeatherType.Sunny;
            }
            else if ((((content.IndexOf("180_180/xiaoyu_0") != -1) || (content.IndexOf("180_180/zhongyuyu_0") != -1)) || ((content.IndexOf("180_180/dayu_0") != -1) || (content.IndexOf("180_180/baoyu_0") != -1))) || (((content.IndexOf("180_180/zhenyu_0") != -1) || (content.IndexOf("180_180/tedabaoyu_0") != -1)) || (content.IndexOf("180_180/yujiaxue_0") != -1)))
            {
                info.weatherType = WeatherType.Rainy;
            }
            else if (content.IndexOf("180_180/leizhenyu_0") != -1)
            {
                info.weatherType = WeatherType.Lightning;
            }
            else
            {
                info.weatherType = WeatherType.Sunny;
            }
            info.temperature = 30f;
            info.extraInfo   = content.Length.ToString();
            return(info);
        }
Esempio n. 2
0
        protected override WeatherInfo ParseWeatherInfo(string content)
        {
            string str = this.FetchInnerTextByPattern(content, "WeatherLocationAndTemperature.0.1.1.0.1");

            if (str == null)
            {
                return(null);
            }
            string s = this.FetchInnerTextByPattern(content, "WeatherLocationAndTemperature.0.1.1.2.0");

            if (s == null)
            {
                return(null);
            }
            WeatherInfo info = new WeatherInfo {
                weatherType = this.GetWeatherTypeFromPattern(str)
            };

            if (!float.TryParse(s, out info.temperature))
            {
                info.temperature = -100f;
            }
            info.temperature = (info.temperature - 32f) / 1.8f;
            return(info);
        }
Esempio n. 3
0
        protected override WeatherInfo ParseWeatherInfo(string content)
        {
            WeatherInfo info = new WeatherInfo();
            JSONNode    node = JSONNode.Parse(content);

            if (node != null)
            {
                info.weatherType = WeatherType.Sunny;
                info.temperature = node["current_observation"]["temp_c"].AsFloat;
            }
            info.extraInfo = content;
            return(info);
        }
Esempio n. 4
0
        protected override WeatherInfo ParseWeatherInfo(string content)
        {
            string str   = "var PAGECONF";
            int    index = content.IndexOf(str);

            if (index == -1)
            {
                return(null);
            }
            int startIndex = content.IndexOf("{", index);

            if (startIndex == -1)
            {
                return(null);
            }
            int num3 = content.IndexOf("};", startIndex);

            if (num3 == -1)
            {
                return(null);
            }
            int length = (num3 - startIndex) + 1;

            if (length <= 0)
            {
                return(null);
            }
            string aJSON = content.Substring(startIndex, length);

            try
            {
                JSONNode    node      = JSONNode.Parse(aJSON);
                char[]      trimChars = new char[] { '\'' };
                string      key       = node["HOSTCITY"]["weatherCode"].Value.Trim(trimChars).Substring(0, 5);
                char[]      chArray2  = new char[] { '\'' };
                string      s         = node["HOSTCITY"]["temp"].Value.Trim(chArray2);
                WeatherInfo info      = new WeatherInfo {
                    weatherType = !this._weatherInfoDict.ContainsKey(key) ? WeatherType.Sunny : this._weatherInfoDict[key]
                };
                if (!float.TryParse(s, out info.temperature))
                {
                    info.temperature = -100f;
                }
                return(info);
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 5
0
        private void OnGUI()
        {
            if (GUILayout.Button("Query Weather", new GUILayoutOption[0]))
            {
            }
            WeatherInfo weatherInfo = Singleton <RealTimeWeatherManager> .Instance.GetWeatherInfo();

            if (weatherInfo != null)
            {
                GUILayout.Label("WeatherType:" + weatherInfo.weatherType.ToString(), new GUILayoutOption[0]);
                GUILayout.Label("Temperature:" + weatherInfo.temperature.ToString(), new GUILayoutOption[0]);
                GUILayout.Label((("ExtraInfo:" + weatherInfo.extraInfo) == null) ? string.Empty : weatherInfo.extraInfo, new GUILayoutOption[0]);
            }
            else
            {
                GUILayout.Label("<No Weather Info>", new GUILayoutOption[0]);
            }
        }
Esempio n. 6
0
        public bool IsWeatherInfoExpired()
        {
            WeatherInfo weatherInfo = this.GetWeatherInfo();

            return((weatherInfo.weatherType == WeatherType.None) || (DateTime.Now.Subtract(weatherInfo.infoTime).TotalSeconds >= this._config.weatherInfoPeriod));
        }