private static string ReadConfig(ConfigXmlDocument cxd, string configname) { string result = ""; XmlNodeList xnx; xnx = cxd.SelectNodes("descendant::configuration/applicationSettings"); if (xnx.Count > 0) { for (int i = 0; i < xnx.Count; i++) { if (xnx[i].ChildNodes.Count > 0) { for (int ix = 0; ix < xnx[i].ChildNodes.Count; ix++) { XmlElement xn = (XmlElement)xnx[i].ChildNodes[ix]; if (xn.Name.Contains("Properties.Settings") || xn.Name.Contains("My.MySettings")) //for c# { for (int iy = 0; iy < xnx[i].ChildNodes[ix].ChildNodes.Count; iy++) { XmlElement xy = (XmlElement)xnx[i].ChildNodes[ix].ChildNodes[iy]; if (xy.Attributes["name"].Value == configname) { result = xy.InnerText; goto end; } } } } } } } end: return(result); }
/// <summary> /// 描画後に文字列を埋める処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WindowGeneralBase_ContentRendered(object sender, EventArgs e) { bool lcflag = false; string lcuser = string.Empty; string lcpass = string.Empty; try { FileInfo fi = new System.IO.FileInfo(GetLocalConfigFilePath()); if (fi.Exists) { ConfigXmlDocument cdoc = new ConfigXmlDocument(); cdoc.Load(fi.FullName); var cfgs = cdoc.SelectNodes("/configuration/settings/add"); foreach (var item in cfgs) { var key = (item as XmlElement).Attributes.GetNamedItem("key").Value; var val = (item as XmlElement).Attributes.GetNamedItem("value").Value; switch (key) { case "LoginCheck": lcflag = string.IsNullOrWhiteSpace(val) ? false : Convert.ToBoolean(val); break; case "TextUr": lcuser = Utility.Decrypt(val); break; case "TextLr": lcpass = Utility.Decrypt(val); break; } } } } catch (Exception) { } finally { this.ライセンス情報記憶 = lcflag; if (lcflag) { this.ユーザーID = lcuser; if (lcpass.Trim() != string.Empty) { this.PASSWORD.SetPassword(lcpass); } } } }
public string GetServiceName() { try { ConfigXmlDocument doc = new ConfigXmlDocument(); doc.Load(Application.StartupPath + "\\HYS.Adapter.Service.exe.config"); System.Xml.XmlNodeList nlist = doc.SelectNodes("/configuration/userSettings/HYS.Adapter.Service.Properties.Settings/setting"); if (nlist == null || nlist.Count < 1) { return("[NULL]"); } foreach (System.Xml.XmlNode n in nlist) { System.Xml.XmlNode ann = n.SelectSingleNode("@name"); string strKey = ann.InnerText; switch (strKey) { case "ServiceName": XmlNode _ServiceNameNode = n.SelectSingleNode("value"); if (_ServiceNameNode != null) { return(_ServiceNameNode.InnerText); } else { return("[NULL]"); } } } return("[NULL]"); } catch (Exception err) { Console.Write(err); return("[NULL]"); } }
private static void AppendConfig(ConfigXmlDocument configDocument, ConfigurationUserLevel userLevel) { var c = ConfigurationManager.OpenExeConfiguration(userLevel); if (c.HasFile) { if (configDocument.DocumentElement == null) { configDocument.Load(c.FilePath); } else { var other = new ConfigXmlDocument(); other.Load(c.FilePath); { XmlElement usg = null; string usgChildren = null; foreach (XmlElement s in other.SelectNodes("/configuration/configSections/sectionGroup[@name=\"userSettings\"]/section")) { if (usg == null) { usg = (XmlElement)configDocument.SelectSingleNode("/configuration/configSections/sectionGroup[@name=\"userSettings\"]"); if (usg == null) { var cs = configDocument.DocumentElement.GetOrPrepend("configSections"); usg = configDocument.CreateElement("sectionGroup"); foreach (XmlAttribute attr in s.ParentNode.Attributes) { usg.SetAttribute(attr.LocalName, attr.NamespaceURI, attr.Value); } usg.InnerXml = s.ParentNode.InnerXml; cs.AppendChild(usg); break; } usgChildren = usg.InnerXml; } usgChildren += s.OuterXml; } if (usgChildren != null) { usg.InnerXml = usgChildren; } } { XmlElement us = null; foreach (XmlElement se in other.SelectNodes("/configuration/userSettings/*/setting")) { if (us == null) { us = configDocument.DocumentElement.GetOrAppend("userSettings"); } var secName = se.ParentNode.LocalName; var ps = us.GetOrAppend(secName); var name = se.GetAttribute("name"); var sete = ps.GetByNameOrAppend("setting", name, "name", name, "serializeAs", se.GetAttribute("serializeAs")); sete.InnerXml = se.InnerXml; } } } } }