public void FromXml(string configurationString) { XmlDocument config = new XmlDocument(); config.LoadXml(configurationString); Entries.Clear(); XmlElement root = config.DocumentElement; foreach (XmlElement host in root.SelectNodes("entries/entry")) { PingCollectorHostEntry hostEntry = new PingCollectorHostEntry(); hostEntry.PingType = PingCollectorTypeHelper.FromText(host.ReadXmlElementAttr("pingMethod", "Ping")); hostEntry.Address = host.ReadXmlElementAttr("address"); hostEntry.DescriptionLocal = host.ReadXmlElementAttr("description"); int tmp = 0; if (int.TryParse(host.ReadXmlElementAttr("maxTimeMS", "1000"), out tmp)) { hostEntry.MaxTimeMS = tmp; } if (int.TryParse(host.ReadXmlElementAttr("timeOutMS", "5000"), out tmp)) { hostEntry.TimeOutMS = tmp; } hostEntry.HttpHeaderUserName = host.ReadXmlElementAttr("httpHeaderUser"); hostEntry.HttpHeaderPassword = host.ReadXmlElementAttr("httpHeaderPwd"); hostEntry.HttpProxyServer = host.ReadXmlElementAttr("httpProxyServer"); hostEntry.HttpProxyUserName = host.ReadXmlElementAttr("httpProxyUser"); hostEntry.HttpProxyPassword = host.ReadXmlElementAttr("httpProxyPwd"); if (hostEntry.PingType == PingCollectorType.HTTP) { XmlNode htmlContentMatchNode = host.SelectSingleNode("htmlContentMatch"); if (htmlContentMatchNode != null) { hostEntry.HTMLContentContain = htmlContentMatchNode.InnerText; } } if (int.TryParse(host.ReadXmlElementAttr("socketPort", "23"), out tmp)) { hostEntry.SocketPort = tmp; } if (int.TryParse(host.ReadXmlElementAttr("receiveTimeoutMS", "30000"), out tmp)) { hostEntry.ReceiveTimeOutMS = tmp; } if (int.TryParse(host.ReadXmlElementAttr("sendTimeoutMS", "30000"), out tmp)) { hostEntry.SendTimeOutMS = tmp; } bool btmp; if (bool.TryParse(host.ReadXmlElementAttr("useTelnetLogin", "false"), out btmp)) { hostEntry.UseTelnetLogin = btmp; } hostEntry.TelnetUserName = host.ReadXmlElementAttr("userName"); hostEntry.TelnetPassword = host.ReadXmlElementAttr("password"); hostEntry.IgnoreInvalidHTTPSCerts = host.ReadXmlElementAttr("ignoreInvalidHTTPSCerts", false); hostEntry.HttpsSecurityProtocol = host.ReadXmlElementAttr("httpsSecurityProtocol"); hostEntry.SocketPingMsgBody = host.ReadXmlElementAttr("socketPingMsgBody", "QuickMon Ping Test"); hostEntry.PrimaryUIValue = host.ReadXmlElementAttr("primaryUIValue", false); Entries.Add(hostEntry); } }
//public List<PingCollectorHostEntry> HostEntries = new List<PingCollectorHostEntry>(); #region IAgentConfig Members public void ReadConfiguration(string configurationString) { XmlDocument config = new XmlDocument(); config.LoadXml(configurationString); Entries.Clear(); XmlElement root = config.DocumentElement; foreach (XmlElement host in root.SelectNodes("hostAddress/entry")) { PingCollectorHostEntry hostEntry = new PingCollectorHostEntry(); hostEntry.PingType = PingCollectorTypeHelper.FromText(host.ReadXmlElementAttr("pingMethod", "Ping")); hostEntry.Address = host.ReadXmlElementAttr("address"); hostEntry.DescriptionLocal = host.ReadXmlElementAttr("description"); int tmp = 0; if (int.TryParse(host.ReadXmlElementAttr("maxTimeMS", "1000"), out tmp)) { hostEntry.MaxTimeMS = tmp; } if (int.TryParse(host.ReadXmlElementAttr("timeOutMS", "5000"), out tmp)) { hostEntry.TimeOutMS = tmp; } hostEntry.HttpProxyServer = host.ReadXmlElementAttr("httpProxyServer"); if (int.TryParse(host.ReadXmlElementAttr("socketPort", "23"), out tmp)) { hostEntry.SocketPort = tmp; } if (int.TryParse(host.ReadXmlElementAttr("receiveTimeoutMS", "30000"), out tmp)) { hostEntry.ReceiveTimeOutMS = tmp; } if (int.TryParse(host.ReadXmlElementAttr("sendTimeoutMS", "30000"), out tmp)) { hostEntry.SendTimeOutMS = tmp; } bool btmp; if (bool.TryParse(host.ReadXmlElementAttr("useTelnetLogin", "false"), out btmp)) { hostEntry.UseTelnetLogin = btmp; } hostEntry.TelnetUserName = host.ReadXmlElementAttr("userName"); hostEntry.TelnetPassword = host.ReadXmlElementAttr("password"); hostEntry.IgnoreInvalidHTTPSCerts = host.ReadXmlElementAttr("ignoreInvalidHTTPSCerts", false); Entries.Add(hostEntry); } //for backwards compatibility try old Ping config foreach (XmlElement host in root.SelectNodes("hosts/host")) { PingCollectorHostEntry hostEntry = new PingCollectorHostEntry(); hostEntry.Address = host.Attributes.GetNamedItem("hostName").Value; hostEntry.DescriptionLocal = host.Attributes.GetNamedItem("description").Value; int tmp = 0; if (int.TryParse(host.Attributes.GetNamedItem("maxTime").Value, out tmp)) { hostEntry.MaxTimeMS = tmp; } if (int.TryParse(host.Attributes.GetNamedItem("timeOut").Value, out tmp)) { hostEntry.TimeOutMS = tmp; } Entries.Add(hostEntry); } }