private readonly Dictionary<string, string> datafeedConfig = new Dictionary<string, string>();
public string GetConfig(string itemName, string attributeName)
{
string key = itemName + "_" + attributeName;
if (datafeedConfig.ContainsKey(key))
{
return datafeedConfig[key];
}
string configPath = AppDomain.CurrentDomain.BaseDirectory + "\\ProductDatafeedConfig\\ProductDatafeed.config";
var xmlDocument = new XmlDocument();
xmlDocument.Load(configPath);
XmlNode root = xmlDocument.SelectSingleNode("ProductDatafeed");
if (root != null)
{
var selectSingleNode = root.SelectSingleNode(itemName);
if (selectSingleNode != null)
{
if (selectSingleNode.Attributes != null)
{
XmlAttribute item = selectSingleNode.Attributes[attributeName];
if (item != null)
{
datafeedConfig.Add(key, item.Value);
return item.Value;
}
throw new ApplicationException("未在" + configPath + "找到指定的配置项");
}
}
}
throw new ApplicationException(configPath + "配置错误");
}
public string GetConfig(string itemName, string attributeName)
{
string key = itemName + "_" + attributeName;
if (datafeedConfig.ContainsKey(key))
{
return datafeedConfig[key];
}
string configPath = AppDomain.CurrentDomain.BaseDirectory + "\\ProductDatafeedConfig\\ProductDatafeed.config";
var xmlDocument = new XmlDocument();
xmlDocument.Load(configPath);
XmlNode root = xmlDocument.SelectSingleNode("ProductDatafeed");
if (root != null)
{
var selectSingleNode = root.SelectSingleNode(itemName);
if (selectSingleNode != null)
{
if (selectSingleNode.Attributes != null)
{
XmlAttribute item = selectSingleNode.Attributes[attributeName];
if (item != null)
{
datafeedConfig.Add(key, item.Value);
return item.Value;
}
throw new ApplicationException("未在" + configPath + "找到指定的配置项");
}
}
}
throw new ApplicationException(configPath + "配置错误");
}