110,539
社区成员
发帖
与我相关
我的任务
分享
public static List<string[]> RemoveEmptyPorts
{
get
{
List<string[]> list = new List<string[]>();
Cache c = HttpRuntime.Cache;
if (c.Get("ports") == null)
{
CacheDependency cache = new CacheDependency(HttpContext.Current.Server.MapPath("~/wx/ports.xml"));
string file = HttpContext.Current.Server.MapPath("~/wx/ports.xml");
XmlDocument doc = new XmlDocument();
doc.Load(file);
XmlNodeList nodes = doc.SelectNodes("/thesaurus/expansion");
string[] port = null;
string[] removePort = null;
//List索引位置
int indexList = 0;
foreach (XmlNode node in nodes)
{
XmlNodeList xnl = node.SelectNodes("sub");
for (int i = 0; i < xnl.Count; i++)
{
if (i == 0)
{
//xnl.Count + 1==最后一项记录attributes="ncode"的助记码
port = new string[xnl.Count + 1];
//xnl.Count + 2=Ports 索引,Ports中的string[]索引
removePort = new string[xnl.Count + 2];
}
port[i] = xnl[i].InnerText;
if (xnl[i].Attributes["ncode"] != null
&& !string.IsNullOrEmpty(xnl[i].Attributes["ncode"].Value)
&& xnl[i].Attributes["ncode"].Value.ToLower().Equals("true"))
{
port[port.Length - 1] = xnl[i].InnerText;
}
//去除空格
removePort[i] = xnl[i].InnerText.Replace(" ", "");
if (i + 1 == xnl.Count)
{
Ports.Add(port);
//记录List索引,string[]索引
removePort[i + 1] = indexList.ToString();
removePort[i + 2] = i.ToString();
list.Add(removePort);
}
}
indexList++;
}
c.Add("ports", list, cache, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
}
else
{
list = c["ports"] as List<string[]>;
}
return list;
}
}