/// <summary> /// Set the param value in the sub section /// The sub section will be created if not exist. /// </summary> /// <param name="sSubSectionName"></param> /// <param name="sParamName"></param> /// <param name="oValue"></param> public void SetParam(string sSubSectionName, string sParamName, object oValue) { // if section not found create it. if (!IsSubSectionExist(sSubSectionName)) { SubSection oSubSection = new SubSection(sSubSectionName); oSubSection.AddParam(sParamName, oValue.GetType().ToString(), oValue); m_oSubSections[sSubSectionName] = oSubSection; } else { SubSection oSection = (SubSection)m_oSubSections[sSubSectionName]; // find if parameter exists set it's value if (oSection.IsParamExist(sParamName)) { oSection.SetParamValue(sParamName, oValue); } else // create the parameter and set it's value { oSection.AddParam(sParamName, oValue.GetType().ToString(), oValue); } } }
public void InitSubSections(XmlDocument oXmlDoc) { try { XmlNodeList oSections = null; // select all the INISections under the config section name // and build the SubSections collection in memory string xPath = "SECTION" + "[@" + ATTR_NAME + " = \"" + m_sConfigSectionName + "\"]" + "/" + INI_SECTION;; oSections = oXmlDoc.DocumentElement.SelectNodes(xPath); if (oSections != null && oSections.Count > 0) { m_oSubSections.Clear(); string sSectionName = ""; for (int i = 0; i < oSections.Count; i++) { XmlNode oSectionNode = oSections[i]; if (oSectionNode.Attributes[ATTR_NAME] != null) { sSectionName = oSectionNode.Attributes[ATTR_NAME].Value.ToString(); // build the SubSection object with parameters SubSection oSubSection = new SubSection(sSectionName); if (oSectionNode.HasChildNodes) { string sParamName = ""; string sParamType = ""; object oParamValue = null; for (int j = 0; j < oSectionNode.ChildNodes.Count; j++) { XmlNode oParamNode = oSectionNode.ChildNodes[j]; if (oParamNode.Attributes[ATTR_NAME] != null) { sParamName = oParamNode.Attributes[ATTR_NAME].Value.ToString(); } if (oParamNode.Attributes[ATTR_TYPE] != null) { sParamType = oParamNode.Attributes[ATTR_TYPE].Value.ToString(); } if (StringUtil.IsStringInitialized(sParamName) && StringUtil.IsStringInitialized(sParamType)) { Type oParamType = Type.GetType(sParamType); oParamValue = Convert.ChangeType(oParamNode.InnerText.ToString(), oParamType); // add the parameter to the sub section oSubSection.AddParam(sParamName, sParamType, oParamValue); } } } // save the current sub section m_oSubSections[sSectionName] = oSubSection; } } } } // of try catch (Exception e) { // write error to Log File. Log.WriteError("IniXmlElements.InitSubSections initialization failed , Details : {0}", e.Message); throw new TisException( e, "IniXmlElements.InitSubSections initialization failed , Details : {0}", e.Message); } }