| 9 |  | { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 10 |  | private XmlDocument xdoc; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 11 |  | private string posElement, posParentElement; | 
 
 
 
 
 
 
 
 | 12 | + | private bool noBackups; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 13 |  |  | 
 
 
 
 
 
 
 
 
 | 13 | – | /// <summary> | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 14 |  | /// Our constructor | 
 
 
 
 
 
 
 
 | 15 | + | /// <summary> | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 16 |  | /// </summary> | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 17 |  | /// <param name="file"></param> | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 18 |  | /// <param name="posElement"></param> | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 19 |  | /// <param name="posParentElement"></param> | 
 
 
 
 
 
 
 
 
 
 
 | 20 | < | public XmlTools(string posElement, string posParentElement = "") | 
 
 
 
 
 
 
 
 
 | 20 | > | public XmlTools(string posElement, string posParentElement = "", bool noBackups = false) | 
 
 
 
 
 
 
 
 
 
 
 | 21 |  | { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 22 |  | this.posElement = posElement; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 23 |  | this.posParentElement = posParentElement; | 
 
 
 
 
 
 
 
 | 24 | + | this.noBackups = noBackups; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 25 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 26 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 27 |  | /// <summary> | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 31 |  | /// <param name="value"></param> | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 32 |  | public void replaceAll(string file, string value, string valuePositions = "") | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 33 |  | { | 
 
 
 
 
 
 
 
 
 
 
 | 34 | < | Util.backupFile(file); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 34 | > | if (!this.noBackups) | 
 
 
 
 
 | 35 | > | { | 
 
 
 
 
 | 36 | > | Util.backupFile(file); | 
 
 
 
 
 | 37 | > | } | 
 
 
 
 
 
 
 
 
 
 
 | 38 |  | loadXmlFile(file); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 39 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 40 |  | List<XmlNode> myElements = new List<XmlNode>(); | 
 
 
 
 
 
 
 
 
 
 
 | 41 | < | Util.getAllSpecificElements(xdoc.DocumentElement, ref myElements,this.posElement,this.posParentElement); //Returns all after "Oni" element | 
 
 
 
 
 
 
 
 
 | 41 | > | Util.getAllSpecificElements(xdoc.DocumentElement, ref myElements, this.posElement, this.posParentElement); //Returns all after "Oni" element | 
 
 
 
 
 
 
 
 
 
 
 | 42 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 43 |  | if (valuePositions != "") | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 44 |  | { | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 75 |  | /// <param name="value"></param> | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 76 |  | public void addValues(string file, string values) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 77 |  | { | 
 
 
 
 
 
 
 
 
 
 
 | 78 | < | Util.backupFile(file); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 78 | > | if (!this.noBackups) | 
 
 
 
 
 | 79 | > | { | 
 
 
 
 
 | 80 | > | Util.backupFile(file); | 
 
 
 
 
 | 81 | > | } | 
 
 
 
 
 
 
 
 
 
 
 | 82 |  | loadXmlFile(file); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 83 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 84 |  | XmlTextValue myInputValues = new XmlTextValue(values); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 96 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 97 |  | XmlTextValue myXmlSubValues = new XmlTextValue(element.InnerText); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 98 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 99 | < | foreach(String myInputValue in myInputValues.myValues){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 99 | > | foreach (String myInputValue in myInputValues.myValues) | 
 
 
 
 
 | 100 | > | { | 
 
 
 
 
 
 
 
 
 
 
 | 101 |  | bool alreadyExists = false; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 102 |  | foreach (String myXmlSubValue in myXmlSubValues.myValues) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 103 |  | { | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 111 |  | //if it doesn't exists already let's add it | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 112 |  | if (!alreadyExists) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 113 |  | { | 
 
 
 
 
 
 
 
 
 
 
 | 114 | < | element.InnerText += " "+myInputValue; | 
 
 
 
 
 
 
 
 
 | 114 | > | element.InnerText += " " + myInputValue; | 
 
 
 
 
 
 
 
 
 
 
 | 115 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 116 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 117 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 127 |  | /// <param name="replaceValue"></param> | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 128 |  | public void replaceValue(string file, string oldValue, string newValue) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 129 |  | { | 
 
 
 
 
 
 
 
 
 
 
 | 130 | < | Util.backupFile(file); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 130 | > | if (!this.noBackups) | 
 
 
 
 
 | 131 | > | { | 
 
 
 
 
 | 132 | > | Util.backupFile(file); | 
 
 
 
 
 | 133 | > | } | 
 
 
 
 
 
 
 
 
 
 
 | 134 |  | loadXmlFile(file); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 135 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 136 |  | List<XmlNode> myElements = new List<XmlNode>(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 146 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 147 |  | XmlTextValue myXmlSubValues = new XmlTextValue(element.InnerText); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 148 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 149 | < | for(int i=0; i<myXmlSubValues.myValues.Count; i++){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 150 | < | //Found a match with the old value? | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 151 | < | if (myXmlSubValues.myValues[i] == oldValue) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 152 | < | { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 153 | < | //replace with the new match | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 154 | < | myXmlSubValues.myValues[i] = newValue; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 155 | < | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 149 | > | for (int i = 0; i < myXmlSubValues.myValues.Count; i++) | 
 
 
 
 
 | 150 | > | { | 
 
 
 
 
 | 151 | > | //Found a match with the old value? | 
 
 
 
 
 | 152 | > | if (myXmlSubValues.myValues[i] == oldValue) | 
 
 
 
 
 | 153 | > | { | 
 
 
 
 
 | 154 | > | //replace with the new match | 
 
 
 
 
 | 155 | > | myXmlSubValues.myValues[i] = newValue; | 
 
 
 
 
 | 156 | > | } | 
 
 
 
 
 
 
 
 
 
 
 | 157 |  | } | 
 
 
 
 
 
 
 
 
 
 
 | 158 | < | element.InnerText = myXmlSubValues.ToString(); | 
 
 
 
 
 
 
 
 
 | 158 | > | element.InnerText = myXmlSubValues.ToString(); | 
 
 
 
 
 
 
 
 
 
 
 | 159 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 160 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 161 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 169 |  | /// <param name="value"></param> | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 170 |  | public void removeValues(string file, string values) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 171 |  | { | 
 
 
 
 
 
 
 
 
 
 
 | 172 | < | Util.backupFile(file); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 172 | > | if (!this.noBackups) | 
 
 
 
 
 | 173 | > | { | 
 
 
 
 
 | 174 | > | Util.backupFile(file); | 
 
 
 
 
 | 175 | > | } | 
 
 
 
 
 
 
 
 
 
 
 | 176 |  | loadXmlFile(file); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 177 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 178 |  | XmlTextValue myInputValues = new XmlTextValue(values); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 192 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 193 |  | foreach (String myInputValue in myInputValues.myValues) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 194 |  | { | 
 
 
 
 
 
 
 
 
 
 
 | 195 | < | for(int i=0; i<myXmlSubValues.myValues.Count; i++){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 195 | > | for (int i = 0; i < myXmlSubValues.myValues.Count; i++) | 
 
 
 
 
 | 196 | > | { | 
 
 
 
 
 
 
 
 
 
 
 | 197 |  | //It already exists in the xml? | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 198 |  | if (myInputValue == myXmlSubValues.myValues[i]) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 199 |  | { | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 218 |  | /// <param name="valueRelation"></param> | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 219 |  | public void changeValue(string file, string newValue, string valueRelation = "", string valuePositions = "") | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 220 |  | { | 
 
 
 
 
 
 
 
 
 
 
 | 221 | < | Util.backupFile(file); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 221 | > | if (!this.noBackups) | 
 
 
 
 
 | 222 | > | { | 
 
 
 
 
 | 223 | > | Util.backupFile(file); | 
 
 
 
 
 | 224 | > | } | 
 
 
 
 
 
 
 
 
 
 
 | 225 |  | loadXmlFile(file); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 226 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 227 |  | XmlNumberValue xmlLastPos = null, newXmlLastPos = null; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 275 |  | /// <param name="file"></param> | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 276 |  | public void invert(string file) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 277 |  | { | 
 
 
 
 
 
 
 
 
 
 
 | 278 | < | Util.backupFile(file); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 278 | > | if (!this.noBackups) | 
 
 
 
 
 | 279 | > | { | 
 
 
 
 
 | 280 | > | Util.backupFile(file); | 
 
 
 
 
 | 281 | > | } | 
 
 
 
 
 
 
 
 
 
 
 | 282 |  | loadXmlFile(file); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 283 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 284 |  | //Inverting the element order | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 289 |  | //Read all and save to the list | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 290 |  | foreach (XmlNode element in myElements) //Returns all after "Oni" element | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 291 |  | { | 
 
 
 
 
 
 
 
 
 
 
 | 292 | < | invertedOrder.Add(element.InnerText); | 
 
 
 
 
 
 
 
 
 | 292 | > | invertedOrder.Add(element.InnerText); | 
 
 
 
 
 
 
 
 
 
 
 | 293 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 294 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 295 |  | //Let's start taking from the list to new xml file (inverted order) | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 332 |  | { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 333 |  | if (pos > testFirstRealValue.myValues.Count - 1 || pos < 0) //Are positions valid for the current values? //-1 because starts at 0 | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 334 |  | { | 
 
 
 
 
 
 
 
 
 
 
 | 335 | < | Program.printAppError(Program.appErrors.INVALID_POSITIONS_RANGE, "The positions values are not in the range of the value to replace (pos index < 0 or > newValueIndexesNumber).",true); | 
 
 
 
 
 
 
 
 
 | 335 | > | Program.printAppError(Program.appErrors.INVALID_POSITIONS_RANGE, "The positions values are not in the range of the value to replace (pos index < 0 or > newValueIndexesNumber).", true); | 
 
 
 
 
 
 
 
 
 
 
 | 336 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 337 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 338 |  | } |