Exemplo n.º 1
0
 public void EditObjectParamsInXmlEx(TbParamsXml rowData/*string classN, string par, string par2, string template*/)
 {
     foreach (string strF in _allValidXmlFiles)
     {
         ParserXml parseXml = new ParserXml(strF);
         parseXml.ReWritePropertyFromRowData("object", rowData);
         parseXml.Dispose();
     }
 }
Exemplo n.º 2
0
        public bool LoadParamsCollection(string fileName)
        {
            if (string.IsNullOrEmpty(fileName)) return false;

            string[] lines = System.IO.File.ReadAllLines(fileName, Encoding.Default);

            String resParams = "";
            foreach (string itemParams  in lines)
            {
                resParams = itemParams.Trim();
                if (resParams == "")
                    continue;

                TbParamsXml allParams = new TbParamsXml();
                string[] strSeparator = new string[] { "{;}" };
                string[] arrayParams = resParams.Split(strSeparator, StringSplitOptions.RemoveEmptyEntries);
                String resPar = "";
                foreach (string iParam in arrayParams)
                {
                    resPar = iParam.Trim();
                    if (resPar == "")
                        continue;
                    string[] itemValue = resPar.Split('=');
                    if (itemValue.Length != 2)
                        continue;
                    char[] charsTrim = {'"'};
                    string nameParam = itemValue[0].Trim();
                    string valueParam = itemValue[1].Trim().Trim(charsTrim);
                    if (allParams[nameParam]!=null)
                    {
                        allParams[nameParam] = valueParam;
                    }
                    

                }
                _mainCollection.Add(allParams);

            }
            return true;
        }
Exemplo n.º 3
0
        public string GetRowInfoParam(string oTag, TbParamsXml rowData) {
            string result = "";
            XmlNodeList paramXml = _xmlDoc.GetElementsByTagName(oTag);
            bool firstElement = true;
            foreach (XmlNode xmlTag in paramXml)
            {
                if (xmlTag.Attributes["className"].Value == rowData.ClassName)
                {
                    bool validDataParam = false;
                    foreach (XmlNode xmlChild in xmlTag["properties"])
                    {
                        if (xmlChild.Attributes["name"].Value == rowData.Param)
                        {
                            validDataParam = (rowData.Attr == "" || rowData.Attr != "" && (rowData.VRegexp != "" ? ValidStringWithRegExp(rowData.VRegexp, xmlChild.Attributes[rowData.Attr].Value) : (xmlChild.Attributes[rowData.Attr] != null && xmlChild.Attributes[rowData.Attr].Value == rowData.Value)));
                            if (validDataParam)
                            {
                                if (firstElement)
                                {
                                    result += "\r\n\tClassName = \"" + xmlTag.Attributes["className"].Value + "\"  Name = \"" + xmlTag.Attributes["objectName"].Value + "\"";
                                    firstElement = false;
                                }
                                result += "\r\n\t\t" + xmlChild.OuterXml;
                            }
                        }
                    }
                    foreach (XmlNode xmlChild in xmlTag["properties"])
                    {
                        if (rowData.UseP && (xmlChild.Attributes["name"].Value == rowData.Param1 || xmlChild.Attributes["name"].Value == rowData.Param2 || xmlChild.Attributes["name"].Value == rowData.Param3 || xmlChild.Attributes["name"].Value == rowData.Param4))
                        {
                            if (validDataParam)
                                result += "\r\n\t\t" + xmlChild.OuterXml;

                        }
                    }
                    firstElement = true;
                }
            }
                return result; 
        }
Exemplo n.º 4
0
        public bool SetValueTagByParams(XmlNode xmlTag,TbParamsXml rowData){
            bool result = false;
            bool find_property = false;
            if (xmlTag.Attributes != null && xmlTag.Attributes["className"].Value == rowData.ClassName)
            {
                        XmlElement xmlChildren = xmlTag["properties"];
                        if (xmlChildren != null)
                            foreach (XmlNode xmlChild in xmlChildren)
                            {   
                                if (xmlChild.Attributes != null && xmlChild.Attributes["name"].Value == rowData.Param && ValidStringWithRegExp(rowData.VRegexp, xmlChild.Attributes["textValue"].Value))
                                {
                                    find_property = true;
                                    string replaceValue = GetReplaceXmlTagValue(xmlTag, rowData);
                                    if (replaceValue != null)
                                    {
                                        xmlChild.Attributes["textValue"].Value = replaceValue;
                                        result = true;
                                    } 

                                }
                            }
                        if (!find_property)
                        {
                            //if not find property Param, search Param1 and copy and rename to Param
                            if (xmlChildren != null)
                                foreach (XmlNode xmlChild in xmlChildren)
                                {   
                                    if (xmlChild.Attributes != null && xmlChild.Attributes["name"].Value == rowData.Param1)
                                    {
                                        XmlNode xmlChildClone = xmlChild.Clone();
                                        if (xmlChildClone.Attributes != null)
                                        {
                                            xmlChildClone.Attributes["name"].Value = rowData.Param;

                                            string replaceValue = GetReplaceXmlTagValue(xmlTag, rowData);
                                            if (replaceValue != null)
                                            {
                                                xmlChildClone.Attributes["textValue"].Value = replaceValue;
                                            }
                                        }

                                        XmlElement xmlElement = xmlTag["properties"];
                                        xmlElement?.AppendChild(xmlChildClone);
                                        result = true;
                                    }
                                }
                        }
                        find_property = false;
                    }
            return result;
    
        }
Exemplo n.º 5
0
        public string GetReplaceXmlTagValue(XmlNode xmlTag, TbParamsXml rowData)
        {
            string replaceValue = rowData.Value.ToString();

            if (rowData.UseP && replaceValue != null && (rowData.Regexp1 != "" || replaceValue.IndexOf("{param1}")!=-1))
            {
                replaceValue = GetFullValueFromParams(xmlTag["properties"], replaceValue, rowData.Param1, rowData.Attr1, rowData.Regexp1, "{param1}");
                if(replaceValue == rowData.Param2)
                    replaceValue = "{param2}";
                if(replaceValue == rowData.Param3)
                    replaceValue = "{param3}";
                if (replaceValue == rowData.Param4)
                    replaceValue = "{param4}";
            }
            if (rowData.UseP && replaceValue != null && replaceValue != "" && (rowData.Regexp1 != "" || replaceValue.IndexOf("{param1:bool}") != -1))
            {
                replaceValue = GetFullValueFromParams(xmlTag["properties"], replaceValue, rowData.Param1, rowData.Attr1, rowData.Regexp1, "{param1:bool}");
            }
            if (rowData.UseP && replaceValue != null &&  replaceValue != "" && (rowData.Regexp2 != "" || replaceValue.IndexOf("{param2}") != -1))
            {
                replaceValue = GetFullValueFromParams(xmlTag["properties"], replaceValue, rowData.Param2, rowData.Attr2, rowData.Regexp2, "{param2}");
                if (replaceValue == rowData.Param3)
                    replaceValue = "{param3}";
                if (replaceValue == rowData.Param4)
                    replaceValue = "{param4}";
            }
            if (rowData.UseP && replaceValue != null && replaceValue != "" && (rowData.Regexp2 != "" || replaceValue.IndexOf("{param2:bool}") != -1))
            {
                replaceValue = GetFullValueFromParams(xmlTag["properties"], replaceValue, rowData.Param2, rowData.Attr2, rowData.Regexp2, "{param2:bool}");
            }
            if (rowData.UseP && replaceValue != null && replaceValue != "" && (rowData.Regexp3 != "" || replaceValue.IndexOf("{param3}") != -1))
            {
                replaceValue = GetFullValueFromParams(xmlTag["properties"], replaceValue, rowData.Param3, rowData.Attr3, rowData.Regexp3, "{param3}");
                if (replaceValue == rowData.Param4)
                    replaceValue = "{param4}";
            }
            if (rowData.UseP && replaceValue != null && replaceValue != "" && (rowData.Regexp3 != "" || replaceValue.IndexOf("{param3:bool}") != -1))
            {
                replaceValue = GetFullValueFromParams(xmlTag["properties"], replaceValue, rowData.Param3, rowData.Attr3, rowData.Regexp3, "{param3:bool}");
            }
            if (rowData.UseP && replaceValue != null && replaceValue != "" && (rowData.Regexp4 != "" || replaceValue.IndexOf("{param4}") != -1))
            {
                replaceValue = GetFullValueFromParams(xmlTag["properties"], replaceValue, rowData.Param4, rowData.Attr4, rowData.Regexp4, "{param4}");
            }
            if (rowData.UseP && replaceValue != null && replaceValue != "" && (rowData.Regexp4 != "" || replaceValue.IndexOf("{param4:bool}") != -1))
            {
                replaceValue = GetFullValueFromParams(xmlTag["properties"], replaceValue, rowData.Param4, rowData.Attr4, rowData.Regexp4, "{param4:bool}");
            }
            return replaceValue;

        }
Exemplo n.º 6
0
        public void ReWritePropertyFromRowData(string oTag, TbParamsXml rowData)
        {

            XmlNodeList paramXml = _xmlDoc.GetElementsByTagName(oTag); 
            bool useTemplate = rowData.UseTmp;
            bool hasEdit = false;
            foreach (XmlNode xmlTag in paramXml)
            {
                if (rowData.UseTmp)
                {
                    XmlNode curNode = xmlTag;
                    bool findTag = false;
                    string[] listOfElements = rowData.Template.Split('.');
                    for (int i = 0; i < listOfElements.Length; i++)
                    {
                        
                        if (i == 0)
                        {
                            if (curNode.Attributes != null && (curNode.Attributes["objectName"] == null || listOfElements[i] != curNode.Attributes["objectName"].Value))
                                break;
                            else if (i == listOfElements.Length - 1) {

                               hasEdit = SetValueTagByParams(curNode, rowData);
                            }

                        }
                        else
                        {
                            foreach (XmlNode xmlItem in curNode.ChildNodes)
                            {
                                if (xmlItem.Attributes != null && (xmlItem.Name == oTag && xmlItem.Attributes["objectName"] != null && listOfElements[i] == xmlItem.Attributes["objectName"].Value))
                                {
                                    findTag = true;
                                    curNode = xmlItem;
                                    if (i == listOfElements.Length - 1)
                                    {
                                       hasEdit = SetValueTagByParams(xmlItem, rowData);
                                    }
                                }
                            }
                            if (!findTag)
                                break;

                        }
                    }
                }
                else hasEdit = SetValueTagByParams(xmlTag, rowData);

                if (hasEdit)
                    _xmlDoc.Save(_fileNameXml);
               
            }
            
        
        }