Esempio n. 1
0
 /// <summary>
 /// Executes the plug in.
 /// </summary>
 /// <param name="SESSION">The SESSION.</param>
 /// <param name="InPacket">The in packet.</param>
 /// <param name="OutPacket">The out packet.</param>
 /// <param name="Key">The key.</param>
 protected override void ExecutePlugIn(eTerm.AsyncSDK.Core.eTerm363Session SESSION, eTerm.AsyncSDK.Core.eTerm363Packet InPacket, eTerm.AsyncSDK.Core.eTerm363Packet OutPacket, eTerm.AsyncSDK.AsyncLicenceKey Key)
 {
     using (FileStream fs = new FileStream(@"Weather.BIN", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
         BinaryReader br     = new BinaryReader(fs);
         byte[]       buffer = new byte[fs.Length];
         br.Read(buffer, 0, buffer.Length);
         WeaterCityVersion version  = new WeaterCityVersion().DeXmlSerialize(TEACrypter.GetDefaultKey, buffer);
         Match             cityName = Regex.Match(Encoding.GetEncoding("gb2312").GetString(SESSION.UnOutPakcet(InPacket)).Trim(), @"([\u4E00-\u9FA5]+)", RegexOptions.Multiline | RegexOptions.IgnoreCase);
         try {
             // Create the query.
             IEnumerable <WeatherCity> queryCitys =
                 from entity in version.WebCityList
                 where entity.CityName == cityName.Value
                 select entity;
             foreach (WeatherCity city in queryCitys)
             {
                 WeatherCity CityCode = version.WebCityList.SingleOrDefault <WeatherCity>(CityDetail => CityDetail.ParentId == city.CityId);
                 if (CityCode == null)
                 {
                     continue;
                 }
                 List <WeatherResult> WeatherResultLst = getResult(getWeater(CityCode.CityName));
                 if (WeatherResultLst.Count > 0)
                 {
                     StringBuilder sb = new StringBuilder();
                     foreach (WeatherResult WeatherItem in WeatherResultLst)
                     {
                         sb.AppendFormat("{0} {1} {2}摄氏度-{3}摄氏度", WeatherItem.Day, WeatherItem.WeekDay, WeatherItem.MinTemperature, WeatherItem.MaxTemperature);
                         break;
                     }
                     SESSION.SendPacket(__eTerm443Packet.BuildSessionPacket(SESSION.SID, SESSION.RID, sb.ToString()));
                 }
                 else
                 {
                     SESSION.SendPacket(__eTerm443Packet.BuildSessionPacket(SESSION.SID, SESSION.RID, "无天气信息"));
                 }
                 return;
             }
         }
         catch (Exception ex) {
             SESSION.SendPacket(__eTerm443Packet.BuildSessionPacket(SESSION.SID, SESSION.RID, ex.Message));
             return;
         }
         br.Close();
         SESSION.SendPacket(__eTerm443Packet.BuildSessionPacket(SESSION.SID, SESSION.RID, "无该城市信息"));
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Executes the plug in.
 /// </summary>
 /// <param name="SESSION">The SESSION.</param>
 /// <param name="InPacket">The in packet.</param>
 /// <param name="OutPacket">The out packet.</param>
 /// <param name="Key">The key.</param>
 protected override void ExecutePlugIn(eTerm.AsyncSDK.Core.eTerm363Session SESSION, eTerm.AsyncSDK.Core.eTerm363Packet InPacket, eTerm.AsyncSDK.Core.eTerm363Packet OutPacket, eTerm.AsyncSDK.AsyncLicenceKey Key)
 {
     try {
         List <WeatherCity> collection = new List <WeatherCity>();
         WeatherCity        RootCity   = new WeatherCity()
         {
             CityId = string.Empty, CityName = string.Empty
         };
         ReadCity(RootCity, collection);
         new WeaterCityVersion()
         {
             VersionDate = DateTime.Now, WebCityList = collection
         }.XmlSerialize(TEACrypter.GetDefaultKey, new FileInfo(@"Weather.BIN").FullName);
         SESSION.SendPacket(__eTerm443Packet.BuildSessionPacket(SESSION.SID, SESSION.RID, "城市更新成功"));
     }
     catch (Exception ex) {
         SESSION.SendPacket(__eTerm443Packet.BuildSessionPacket(SESSION.SID, SESSION.RID, ex.Message));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Reads the city.
        /// </summary>
        /// <param name="ParentCity">The parent city.</param>
        private void ReadCity(WeatherCity ParentCity, List <WeatherCity> collection)
        {
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(string.Format(@"http://www.weather.com.cn/data/list3/city{0}.xml", ParentCity.CityId));

            using (HttpWebResponse myRes = (HttpWebResponse)myReq.GetResponse()) {
                using (Stream stream = myRes.GetResponseStream()) {
                    StreamReader sr = new StreamReader(stream, Encoding.UTF8);
                    //250401|衡阳,250402|衡山,250403|衡东,250404|祁东,250405|衡阳县,250406|常宁,250407|衡南,250408|耒阳,250409|南岳
                    foreach (Match m in Regex.Matches(sr.ReadToEnd(), @"([0-9]+)\|([\u4E00-\u9FA5 0-9]+)", RegexOptions.IgnoreCase))
                    {
                        WeatherCity subCity = new WeatherCity()
                        {
                            ParentId = ParentCity.CityId, CityId = m.Groups[1].Value, CityName = m.Groups[2].Value, CityPinYin = Cn2PyUtil.FullConvert(m.Groups[2].Value)
                        };
                        if (!Regex.IsMatch(subCity.CityName, @"^[0-9]+$"))
                        {
                            ReadCity(subCity, collection);
                        }
                        collection.Add(subCity);
                    }
                    sr.Dispose();
                }
            }
        }