/// <summary> /// Load Settings from config. /// </summary> /// <param name="isServer"></param> /// <returns></returns> public static TcpSettings[] LoadSettings(bool isServer) { List <TcpSettings> list = new List <TcpSettings>(); try { System.Configuration.Configuration config = NetConfig.GetConfiguration(); XmlDocument doc = new XmlDocument(); doc.Load(config.FilePath); Netlog.Debug("LoadSettings : " + config.FilePath); string xpath = isServer ? "//TcpServerSettings" : "//TcpClientSettings"; XmlNode root = doc.SelectSingleNode(xpath); foreach (XmlNode n in root.ChildNodes) { if (n.NodeType == XmlNodeType.Comment) { continue; } TcpSettings ps = new TcpSettings(n, isServer); list.Add(ps); } return(list.ToArray()); } catch (Exception ex) { throw ex; } }
void LoadTcpSttingsInternal(string configHost, bool isServer) { if (string.IsNullOrEmpty(configHost)) { throw new ArgumentNullException("TcpSettings.LoadTcpSttingsInternal name"); } System.Configuration.Configuration config = NetConfig.GetConfiguration(); XmlDocument doc = new XmlDocument(); doc.Load(config.FilePath); Netlog.Debug("LoadTcpSttingsInternal : " + config.FilePath); string xpath = isServer ? "//TcpServerSettings" : "//TcpClientSettings"; XmlNode root = doc.SelectSingleNode(xpath); XmlNode node = null; bool found = false; foreach (XmlNode n in root.ChildNodes) { if (n.NodeType == XmlNodeType.Comment) { continue; } XmlAttribute attr = n.Attributes["HostName"]; if (attr != null && attr.Value == configHost) { node = n; found = true; break; } } if (!found) { throw new ArgumentException("Invalid TcpSettings with HostName:" + configHost); } LoadTcpSettings(node, isServer); }