资源简介
天气预报源码、包括从IP获取天气预报,具体教程http://www.cnblogs.com/ailiangwu/archive/2009/07/22/1528342.html
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Regularexpressions;
using System.Net;
using System.xml;
using System.IO;
using Flashado.framework;
namespace Flashado.Weather
{
/// 城市类
public class City
{
private const string __Url = “http://www.weather.com.cn/data/listinfo/city{0}.xml“;
/// 名称
public string Name { get; set; }
/// ID
public string ID { get; set; }
/// 城市xml路径
public static string _CityxmlPath = “WeatherCity.xml“;
private static CityxmlInfo[] _Citys=null;
public static CityxmlInfo[] Default{
get{
if (_Citys == null)
{
_Citys = Load(Path.GetFullPath(_CityxmlPath));
}
return _Citys;
}
}
public override string ToString()
{
return this.Name;
}
/// 获取城市类的集合
/// 城市类
public static City[] GetList()
{
return GetList(string.Empty);
}
/// 获取城市类的集合
/// 城市Id
/// 城市类
public static City[] GetList(string id)
{
var url = string.Format(__Url id);
using (WebClient wc = new WebClient())
{
wc.Encoding = Encoding.UTF8;
string str = wc.DownloadString(url);
List citys = new List();
var cs = str.Split(‘‘);
foreach (var c in cs)
{
var carr = c.Split(‘|‘);
citys.Add(new City()
{
ID = carr[0]
Name = carr[1]
});
}
return citys.ToArray();
}
}
///
/// 获取城市代码
///
/// 城市名称
/// 城市代码
public static string GetCityCodeByName(string name){
var city=Default.FirstOrDefaultlInfo>(c=>c.Name==name);
if(city==null){
return string.Empty;
}
return city.Code;
}
private static string GetCityByIp(string regex string input)
{
var reg = new Regex(regex);
var match = reg.Matches(input);
if(match.Count==0){
return string.Empty;
}
return match[match.Count-1].Result(“$1“);
}
/// 更具IP获取城市代码
/// IP库地址
/// IP地址
/// 城市代码
public static string GetCityCodeByIp(string ipDataPathstring ip){
IPLocation.IPLocation.IPLocate(ipDataPathip);
var country = IPLocation.IPLocation.Country;
var regex = new Regex(“([^市省]+)市“);
var match=regex.Match(country);
var area=string.Empty;
var province = string.Empty;
var city = string.Empty;
var matCity = Regex.Matches(country “([^市省]+)市“);
var matArea = Regex.Matches(country “([^市省区]+)区“);
var matProvince = Regex.Matches(country “([^省]+)省“);
if(matArea.Count>0){
area = matArea[0].Result(“$1“);
}
if (matProvince.Count > 0
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 60416 2009-04-02 22:20 Flashado.Weather\bin\Debug\Flashado.fr
文件 165376 2009-04-02 22:20 Flashado.Weather\bin\Debug\Flashado.fr
文件 132756 2009-04-02 22:20 Flashado.Weather\bin\Debug\Flashado.fr
文件 20480 2009-07-21 18:06 Flashado.Weather\bin\Debug\Flashado.Weather.dll
文件 30208 2009-07-21 18:06 Flashado.Weather\bin\Debug\Flashado.Weather.pdb
文件 7290 2009-07-21 18:06 Flashado.Weather\bin\Debug\Flashado.Weather.xm
文件 20480 2006-12-16 00:23 Flashado.Weather\bin\Debug\IPLocation.dll
文件 139264 2005-05-30 19:22 Flashado.Weather\bin\Debug\SgmlReaderDll.dll
文件 4867 2009-07-21 16:41 Flashado.Weather\City.cs
文件 863 2009-05-19 18:59 Flashado.Weather\Cityxm
文件 1243 2009-07-21 17:14 Flashado.Weather\Exponential.cs
文件 3481 2009-07-20 10:12 Flashado.Weather\Flashado.Weather.csproj
文件 168 2009-07-21 16:05 Flashado.Weather\Flashado.Weather.csproj.user
文件 942 2009-07-21 18:06 Flashado.Weather\obj\Debug\Flashado.Weather.csproj.FileListAbsolute.txt
文件 20480 2009-07-21 18:06 Flashado.Weather\obj\Debug\Flashado.Weather.dll
文件 30208 2009-07-21 18:06 Flashado.Weather\obj\Debug\Flashado.Weather.pdb
文件 10240 2009-07-21 17:05 Flashado.Weather\obj\Debug\Refactor\Flashado.Weather.dll
文件 1400 2009-05-05 18:17 Flashado.Weather\Properties\AssemblyInfo.cs
文件 7882 2009-07-21 18:03 Flashado.Weather\Weather.cs
文件 900 2009-07-20 10:12 Flashado.Weather\WeatherSimple.cs
文件 2244 2009-07-20 10:12 Flashado.Weather\WeatherSimpleInfo.cs
文件 60416 2009-04-02 22:20 Flashado.Weather.WInForm\bin\Debug\Flashado.fr
文件 165376 2009-04-02 22:20 Flashado.Weather.WInForm\bin\Debug\Flashado.fr
文件 132756 2009-04-02 22:20 Flashado.Weather.WInForm\bin\Debug\Flashado.fr
文件 20480 2009-07-21 18:06 Flashado.Weather.WInForm\bin\Debug\Flashado.Weather.dll
文件 30208 2009-07-21 18:06 Flashado.Weather.WInForm\bin\Debug\Flashado.Weather.pdb
文件 13824 2009-07-21 18:06 Flashado.Weather.WInForm\bin\Debug\Flashado.Weather.WInForm.exe
文件 26112 2009-07-21 18:06 Flashado.Weather.WInForm\bin\Debug\Flashado.Weather.WInForm.pdb
文件 14328 2009-07-22 08:50 Flashado.Weather.WInForm\bin\Debug\Flashado.Weather.WInForm.vshost.exe
文件 490 2007-07-21 01:33 Flashado.Weather.WInForm\bin\Debug\Flashado.Weather.WInForm.vshost.exe.manifest
............此处省略175个文件信息
评论
共有 条评论