using System.Collections;
using System.Xml;

namespace QC.QTMTreeXMLHandler;

public class QTMTreeHandler
{
	private enum SearchState
	{
		state1,
		state2,
		state3,
		state4,
		state5,
		state6,
		state7,
		state8
	}

	public const string FOLDER_TEST = "FolderTest";

	public const string NODE_TEST = "Test";

	public const string NODE_FOLDER = "Folder";

	public const string CTS_TEST = "CTSTest";

	public const string SCRIPT_TEST = "ScriptTest";

	public const string FOLDER_PROPERTY = "FolderProperty";

	public const string FOLDER_PROPERTIES = "FolderProperties";

	public const string TEST_PROPERTY = "TestProperty";

	public const string SCRIPT_PROPERTY = "ScriptProperties";

	public const string PARAMETERS = "Parameters";

	public const string CREATED_BY = "CreatedBy";

	public const string COMMENT = "Comment";

	public const string NODE_RID = "NodeRID";

	public const string NODE_ID = "NodeID";

	public const string TREE_STRING_ID = "TreeStringID";

	public const string ParamRID = "ParamRID";

	public const string PARAMETER_ARRAY = "ArrayParameterRIDsAsString";

	public const string NUMBER_OF_ELEMENTS = "NoOfElements";

	public const string SCENARIOS = "Scenarios";

	public const string LOOP_CONDITION = "LoopConditions";

	public const string CONDITION_CHECK = "ConditionCheckAsString";

	public const string DESCRIPTION = "DescriptionsAsString";

	public const string SCENARIO_ID = "ScenarioID";

	public const string NUMBER_OF_TESTS = "NumberOfTests";

	public const string TREE_RID = "TreeRID";

	public const string LEFT_ID = "LeftID";

	public const string NODE_TYPE = "NodeType";

	public const string SERVER = "Server";

	public const string DATABASE = "Database";

	public const string BREAK_CONDITION = "Condition";

	public const string INDEX = "Index";

	public const string SITE_KEY = "SiteKey";

	public const string SITE_TREEID = "SiteTreeID";

	public const string REGISTERED_MACHINE = "RegisteredMachine";

	public const string VALUE = "Value";

	public const string DATATYPE = "DataType";

	private const string STRING_ARRAY_SEPARATOR = "_\"_";

	private XmlDocument xmlMainDoc;

	private XmlNode RootProperties;

	private XmlNode CurrCategory;

	private XmlNode CurrFolder;

	private XmlNode CurrParameter;

	private XmlNode CurrScenarios;

	private Stack stackFolder = new Stack();

	public int CurrentNodeRID
	{
		set
		{
			if (CurrFolder == null)
			{
				return;
			}
			XmlNodeList childNodes = CurrFolder.ChildNodes;
			for (int i = 0; i < childNodes.Count; i++)
			{
				try
				{
					if (childNodes[i].Attributes.Count > 0)
					{
						string innerText = childNodes[i].Attributes["NodeType"].InnerText;
						if (innerText.Contains("Proper"))
						{
							XmlNode xmlNode = childNodes[i];
							xmlNode["NodeRID"].InnerText = value.ToString();
							break;
						}
					}
				}
				catch
				{
				}
			}
		}
	}

	public bool GetFirstCatagory
	{
		get
		{
			try
			{
				if (xmlMainDoc != null)
				{
					XmlNode documentElement = xmlMainDoc.DocumentElement;
					XmlNodeList xmlNodeList = documentElement.SelectNodes("/SerializeComponents/theRootTest");
					XmlNodeList childNodes = xmlNodeList[0].ChildNodes;
					for (int i = 0; i < childNodes.Count; i++)
					{
						try
						{
							if (childNodes[i].Attributes["NodeType"] != null && childNodes[i].Attributes["NodeType"].InnerText == "Folder")
							{
								CurrCategory = childNodes[i];
								return true;
							}
						}
						catch
						{
						}
					}
					return false;
				}
				return false;
			}
			catch
			{
				return false;
			}
		}
	}

	public string CurrentCatDetails
	{
		get
		{
			string result = "";
			try
			{
				if (CurrCategory != null)
				{
					result = GetDetailsInString(CurrCategory, "FolderProperty");
				}
			}
			catch
			{
			}
			return result;
		}
	}

	public bool GetNextCatagory
	{
		get
		{
			try
			{
				if (CurrCategory != null)
				{
					CurrCategory = CurrCategory.NextSibling;
					if (CurrCategory != null)
					{
						return true;
					}
				}
				return false;
			}
			catch
			{
				return false;
			}
		}
	}

	public bool GetFirstTestFromCatagory
	{
		get
		{
			try
			{
				if (CurrCategory != null)
				{
					XmlNodeList childNodes = CurrCategory.ChildNodes;
					for (int i = 0; i < childNodes.Count; i++)
					{
						try
						{
							if (childNodes[i].Attributes["NodeType"] == null)
							{
								continue;
							}
							string innerText = childNodes[i].Attributes["NodeType"].InnerText;
							if (innerText == "Folder" || innerText == "Test")
							{
								CurrFolder = childNodes[i];
								if (CurrFolder.Name == "FolderTest" && CurrFolder.NextSibling != null)
								{
									PushToStack(CurrFolder.NextSibling);
								}
								else if (CurrFolder.Name == "FolderTest" && CurrFolder.NextSibling == null)
								{
									PushToStack(null);
								}
								return true;
							}
						}
						catch
						{
						}
					}
					return false;
				}
				return false;
			}
			catch
			{
				return false;
			}
		}
	}

	public bool GetFirstTestFromFolder
	{
		get
		{
			try
			{
				if (CurrFolder != null)
				{
					XmlNodeList childNodes = CurrFolder.ChildNodes;
					for (int i = 0; i < childNodes.Count; i++)
					{
						try
						{
							if (childNodes[i].Attributes["NodeType"] == null)
							{
								continue;
							}
							string innerText = childNodes[i].Attributes["NodeType"].InnerText;
							if (innerText == "Folder" || innerText == "Test")
							{
								CurrFolder = childNodes[i];
								if (CurrFolder.Name == "FolderTest" && CurrFolder.NextSibling != null)
								{
									PushToStack(CurrFolder.NextSibling);
								}
								else if (CurrFolder.Name == "FolderTest" && CurrFolder.NextSibling == null)
								{
									PushToStack(null);
								}
								return true;
							}
						}
						catch
						{
						}
					}
					return false;
				}
				return false;
			}
			catch
			{
				return false;
			}
		}
	}

	public bool GetScenarioFromFolder
	{
		get
		{
			try
			{
				if (TestIsFolder)
				{
					XmlNodeList childNodes = CurrFolder.ChildNodes;
					for (int i = 0; i < childNodes.Count; i++)
					{
						if (!(childNodes[i].Name == "FolderProperties"))
						{
							continue;
						}
						XmlNodeList childNodes2 = childNodes[i].ChildNodes;
						for (int j = 0; j < childNodes2.Count; j++)
						{
							if (childNodes2[j].Name == "Scenarios")
							{
								CurrScenarios = childNodes2[j];
								return true;
							}
						}
					}
					return false;
				}
				return false;
			}
			catch
			{
				return false;
			}
		}
	}

	public string CurrentScenario
	{
		get
		{
			string result = "";
			string text = "";
			string text2 = "";
			string text3 = "";
			string text4 = "";
			try
			{
				if (CurrScenarios != null)
				{
					XmlNodeList childNodes = CurrScenarios.ChildNodes;
					for (int i = 0; i < childNodes.Count; i++)
					{
						if (childNodes[i].Name == "LoopConditions")
						{
							string innerXml = childNodes[i].InnerXml;
							text = text + "<LoopConditions>" + innerXml + "</LoopConditions>";
						}
						else if (childNodes[i].Name == "ConditionCheckAsString")
						{
							text2 = childNodes[i].InnerText;
						}
						else if (childNodes[i].Name == "DescriptionsAsString")
						{
							text3 = childNodes[i].InnerText;
						}
						else if (childNodes[i].Name == "Condition")
						{
							text4 = "<Conditions>" + childNodes[i].OuterXml + "</Conditions>";
						}
					}
					string[] array = text2.Split(',');
					string[] array2 = text3.Split(';');
					string text5 = "";
					for (int j = 0; j < array.Length; j++)
					{
						string arg = array[j];
						string arg2 = "";
						string arg3 = j.ToString();
						if (array2.Length > j)
						{
							arg2 = array2[j];
						}
						text5 += $"<Property><ConditionCheck>{arg}</ConditionCheck><Description>{arg2}</Description><ScnRow>{arg3}</ScnRow></Property>";
						string text6 = text5;
						text5 = text6 + "<Property><ConditionCheck>" + array[j] + "</ConditionCheck><Description>" + array2[j] + "</Description><ScnRow>" + j + "</ScnRow></Property>";
					}
					result = string.Format("<{0}>{1}{2}{3}</{0}>", "Scenarios", text, text4, text5);
				}
			}
			catch
			{
			}
			return result;
		}
	}

	public bool GetFirstParameterFromTest
	{
		get
		{
			try
			{
				if (!TestIsFolder)
				{
					XmlNodeList childNodes = CurrFolder.ChildNodes;
					for (int i = 0; i < childNodes.Count; i++)
					{
						try
						{
							if (childNodes[i].Attributes["NodeType"] == null)
							{
								continue;
							}
							string innerText = childNodes[i].Attributes["NodeType"].InnerText;
							if (!(innerText == "TestProperty"))
							{
								continue;
							}
							XmlNodeList childNodes2 = childNodes[i].ChildNodes;
							for (int j = 0; j < childNodes2.Count; j++)
							{
								if (childNodes2[j].Name == "Parameters")
								{
									XmlNodeList childNodes3 = childNodes2[j].ChildNodes;
									int num = 0;
									if (num < childNodes3.Count)
									{
										CurrParameter = childNodes3[num];
										return true;
									}
								}
							}
						}
						catch
						{
						}
					}
					return false;
				}
				return false;
			}
			catch
			{
				return false;
			}
		}
	}

	public bool GetNextParameter
	{
		get
		{
			try
			{
				if (CurrFolder != null && CurrParameter != null)
				{
					CurrParameter = CurrParameter.NextSibling;
				}
				else
				{
					CurrParameter = null;
				}
				if (CurrParameter != null)
				{
					return true;
				}
				return false;
			}
			catch
			{
				return false;
			}
		}
	}

	public bool TestIsFolder
	{
		get
		{
			if (CurrFolder != null && CurrFolder.Name == "FolderTest")
			{
				return true;
			}
			return false;
		}
	}

	public string CurrentTestType
	{
		get
		{
			if (CurrFolder != null)
			{
				return CurrFolder.Name;
			}
			return "";
		}
	}

	public bool GetNextTest
	{
		get
		{
			try
			{
				if (CurrFolder != null)
				{
					CurrFolder = CurrFolder.NextSibling;
					if (CurrFolder != null)
					{
						if (CurrFolder.Name == "FolderTest" && CurrFolder.NextSibling != null)
						{
							PushToStack(CurrFolder.NextSibling);
						}
						else if (CurrFolder.Name == "FolderTest" && CurrFolder.NextSibling == null)
						{
							PushToStack(null);
						}
						return true;
					}
					return false;
				}
				CurrFolder = GetLastTestFromStack();
				if (CurrFolder != null)
				{
					if (CurrFolder.Name == "FolderTest" && CurrFolder.NextSibling != null)
					{
						PushToStack(CurrFolder.NextSibling);
					}
					else if (CurrFolder.Name == "FolderTest" && CurrFolder.NextSibling == null)
					{
						PushToStack(null);
					}
					return true;
				}
				return false;
			}
			catch
			{
				return false;
			}
		}
	}

	public string CurrFolderDetails
	{
		get
		{
			string result = "";
			try
			{
				if (CurrFolder != null)
				{
					result = ((!TestIsFolder) ? GetDetailsInString(CurrFolder, "TestProperty") : GetDetailsInString(CurrFolder, "FolderProperty"));
				}
			}
			catch
			{
			}
			return result;
		}
	}

	public string CurrParameterDetials
	{
		get
		{
			string result = "";
			try
			{
				if (CurrParameter != null)
				{
					result = CurrParameter.OuterXml;
				}
			}
			catch
			{
			}
			return result;
		}
	}

	public XmlDocument XmlDoc => xmlMainDoc;

	public string CurrentTestName
	{
		get
		{
			XmlNode xmlNode = null;
			try
			{
				xmlNode = ((!TestIsFolder) ? CurrFolder.FirstChild.NextSibling.FirstChild.NextSibling : CurrFolder.FirstChild.NextSibling.FirstChild.NextSibling);
			}
			catch
			{
			}
			if (xmlNode != null)
			{
				return xmlNode.InnerText;
			}
			return "";
		}
	}

	public QTMTreeHandler(string treeXml)
	{
		xmlMainDoc = new XmlDocument();
		xmlMainDoc.LoadXml(treeXml);
	}

	public string GetRootProperties(string comment, string createdBy)
	{
		try
		{
			if (xmlMainDoc != null)
			{
				XmlNode documentElement = xmlMainDoc.DocumentElement;
				XmlNode xmlNode = documentElement.SelectSingleNode("/SerializeComponents/theRootTest/RootProperties");
				XmlNodeList childNodes = xmlNode.ChildNodes;
				for (int i = 0; i < childNodes.Count; i++)
				{
					if (childNodes[i].Name == "CreatedBy")
					{
						childNodes[i].InnerText = createdBy;
					}
					else if (childNodes[i].Name == "Comment")
					{
						childNodes[i].InnerText = comment;
					}
					switch (childNodes[i].Name)
					{
					case "CreatedBy":
						childNodes[i].InnerText = createdBy;
						break;
					case "Comment":
						childNodes[i].InnerText = comment;
						break;
					}
				}
				RootProperties = documentElement.SelectSingleNode("/SerializeComponents/theRootTest/RootProperties");
				return RootProperties.OuterXml;
			}
			return "";
		}
		catch
		{
			return "";
		}
	}

	public bool UpdateTreeRID(long treeID, string treeStringID)
	{
		try
		{
			XmlNodeList childNodes = RootProperties.ChildNodes;
			for (int i = 0; i < childNodes.Count; i++)
			{
				switch (childNodes[i].Name)
				{
				case "TreeStringID":
					childNodes[i].InnerText = treeStringID;
					break;
				case "SiteTreeID":
					childNodes[i].InnerText = treeID.ToString();
					break;
				case "NodeRID":
					childNodes[i].InnerText = treeID.ToString();
					break;
				}
			}
			return true;
		}
		catch
		{
			return false;
		}
	}

	public bool UpdateTreeRegistrationInformation(string serverName, string databaseName)
	{
		try
		{
			XmlNodeList childNodes = RootProperties.ChildNodes;
			for (int i = 0; i < childNodes.Count; i++)
			{
				if (childNodes[i].Name == "Server")
				{
					childNodes[i].InnerText = serverName;
				}
				if (childNodes[i].Name == "Database")
				{
					childNodes[i].InnerText = databaseName;
				}
			}
			return true;
		}
		catch
		{
			return false;
		}
	}

	public bool UpdateRegisteredMachine(string machineName)
	{
		try
		{
			XmlNode documentElement = xmlMainDoc.DocumentElement;
			RootProperties = documentElement.SelectSingleNode("/SerializeComponents/theRootTest/RootProperties");
			XmlNodeList childNodes = RootProperties.ChildNodes;
			for (int i = 0; i < childNodes.Count; i++)
			{
				if (childNodes[i].Name == "RegisteredMachine")
				{
					childNodes[i].InnerText = machineName;
				}
			}
			return true;
		}
		catch
		{
			return false;
		}
	}

	public bool UpdateDynamicArraySize()
	{
		try
		{
			XmlNodeList childNodes = CurrParameter.ChildNodes;
			string commaSepArrayValue = "";
			string dataType = "";
			for (int i = 0; i < childNodes.Count; i++)
			{
				if (childNodes[i].Name == "Value")
				{
					commaSepArrayValue = childNodes[i].InnerText;
				}
				if (childNodes[i].Name == "DataType")
				{
					dataType = childNodes[i].InnerText;
				}
			}
			for (int j = 0; j < childNodes.Count; j++)
			{
				if (childNodes[j].Name == "NoOfElements")
				{
					childNodes[j].InnerText = GetArrayElemCount(commaSepArrayValue, dataType).ToString();
					break;
				}
			}
			return true;
		}
		catch
		{
			return false;
		}
	}

	public int GetArrayElemCount(string commaSepArrayValue, string dataType)
	{
		try
		{
			int result = 1;
			if (commaSepArrayValue != null)
			{
				result = ((!(dataType.Trim() == "String") || !commaSepArrayValue.Contains("_\"_")) ? commaSepArrayValue.Split(',').Length : SplitStringArrayParameter(commaSepArrayValue).Length);
			}
			return result;
		}
		catch
		{
			return 1;
		}
	}

	private static string[] SplitStringArrayParameter(string paramString)
	{
		ArrayList arrayList = new ArrayList();
		if (paramString != null && paramString.Length > 0)
		{
			bool flag = false;
			bool flag2 = true;
			string text = paramString;
			SearchState searchState = SearchState.state1;
			int num = 0;
			while (!flag)
			{
				if (num >= text.Length - 1)
				{
					searchState = SearchState.state8;
					flag = true;
				}
				switch (searchState)
				{
				case SearchState.state1:
					if (text[num] == '_')
					{
						searchState = SearchState.state2;
					}
					else if (text[num] == ',')
					{
						searchState = SearchState.state8;
					}
					break;
				case SearchState.state2:
					searchState = ((text[num] != '"') ? ((text[num] == ',') ? SearchState.state8 : SearchState.state1) : SearchState.state3);
					break;
				case SearchState.state3:
					if (text[num] == '_')
					{
						searchState = SearchState.state4;
						flag2 = false;
					}
					else
					{
						searchState = ((text[num] == ',') ? SearchState.state8 : SearchState.state1);
					}
					break;
				case SearchState.state4:
					if (text[num] == '_')
					{
						searchState = SearchState.state5;
					}
					break;
				case SearchState.state5:
					searchState = ((text[num] != '"') ? SearchState.state4 : SearchState.state6);
					break;
				case SearchState.state6:
					if (text[num] == '_')
					{
						searchState = SearchState.state7;
						flag2 = true;
					}
					else
					{
						searchState = SearchState.state4;
					}
					break;
				case SearchState.state7:
					if (text[num] == ',')
					{
						searchState = SearchState.state8;
					}
					break;
				case SearchState.state8:
					if (!flag && num < text.Length - 1)
					{
						string value = text.Substring(0, num).Trim(',').Replace("_\"_", "");
						arrayList.Add(value);
						text = text.Substring(num);
						num = -1;
						searchState = SearchState.state1;
					}
					else
					{
						flag = true;
					}
					if (flag)
					{
						if (text.Length == 0)
						{
							arrayList.Add("");
						}
						else if (text.EndsWith(",") && flag2)
						{
							arrayList.Add(text.Trim(',').Replace("_\"_", ""));
							arrayList.Add("");
						}
						else
						{
							arrayList.Add(text.Replace("_\"_", ""));
						}
					}
					break;
				}
				num++;
			}
		}
		if (arrayList.Count == 0)
		{
			arrayList.Add("");
		}
		string[] array = new string[arrayList.Count];
		for (int i = 0; i < arrayList.Count; i++)
		{
			array[i] = arrayList[i].ToString();
		}
		return array;
	}

	public bool UpdateNodeID(NodeType nType, long nID)
	{
		try
		{
			switch (nType)
			{
			case NodeType.CATEGORY:
			{
				XmlNodeList childNodes = CurrCategory.ChildNodes;
				for (int n = 0; n < childNodes.Count; n++)
				{
					if (childNodes[n].Attributes.Count <= 0)
					{
						continue;
					}
					string innerText2 = childNodes[n].Attributes["NodeType"].InnerText;
					if (!(innerText2 == "FolderProperty"))
					{
						continue;
					}
					XmlNodeList childNodes4 = childNodes[n].ChildNodes;
					for (int num2 = 0; num2 < childNodes4.Count; num2++)
					{
						if (childNodes4[num2].Name == "NodeRID")
						{
							childNodes4[num2].InnerText = nID.ToString();
						}
					}
				}
				break;
			}
			case NodeType.FOLDER:
			{
				XmlNodeList childNodes = CurrFolder.ChildNodes;
				for (int num8 = 0; num8 < childNodes.Count; num8++)
				{
					if (childNodes[num8].Attributes.Count <= 0)
					{
						continue;
					}
					string innerText3 = childNodes[num8].Attributes["NodeType"].InnerText;
					if (!(innerText3 == "FolderProperty"))
					{
						continue;
					}
					XmlNodeList childNodes5 = childNodes[num8].ChildNodes;
					for (int num9 = 0; num9 < childNodes5.Count; num9++)
					{
						if (childNodes5[num9].Name == "NodeRID")
						{
							childNodes5[num9].InnerText = nID.ToString();
						}
					}
				}
				break;
			}
			case NodeType.TEST:
			{
				XmlNodeList childNodes = CurrFolder.ChildNodes;
				for (int l = 0; l < childNodes.Count; l++)
				{
					try
					{
						if (childNodes[l].Attributes.Count <= 0)
						{
							continue;
						}
						string innerText = childNodes[l].Attributes["NodeType"].InnerText;
						if (!(innerText == "TestProperty"))
						{
							continue;
						}
						XmlNodeList childNodes3 = childNodes[l].ChildNodes;
						for (int m = 0; m < childNodes3.Count; m++)
						{
							if (childNodes3[m].Name == "NodeRID")
							{
								childNodes3[m].InnerText = nID.ToString();
							}
						}
					}
					catch
					{
					}
				}
				break;
			}
			case NodeType.PARAMETER:
			{
				XmlNodeList childNodes = CurrParameter.ChildNodes;
				for (int num3 = 0; num3 < childNodes.Count; num3++)
				{
					if (childNodes[num3].Name == "ParamRID")
					{
						childNodes[num3].InnerText = nID.ToString();
					}
				}
				break;
			}
			case NodeType.ARRAY_PARAMETER:
			{
				XmlNodeList childNodes = CurrParameter.ChildNodes;
				int num4 = 1;
				for (int num5 = 0; num5 < childNodes.Count; num5++)
				{
					if (childNodes[num5].Name == "NoOfElements")
					{
						num4 = int.Parse(childNodes[num5].InnerText.Trim());
					}
				}
				for (int num6 = 0; num6 < childNodes.Count; num6++)
				{
					if (childNodes[num6].Name == "ArrayParameterRIDsAsString")
					{
						string text = "";
						for (long num7 = nID - num4 + 1; num7 < nID; num7++)
						{
							text = text + num7 + ",";
						}
						text += nID;
						childNodes[num6].InnerText = text;
					}
				}
				break;
			}
			case NodeType.SCENARIOS:
			{
				XmlNodeList childNodes = CurrScenarios.ChildNodes;
				int num = 0;
				for (int i = 0; i < childNodes.Count; i++)
				{
					if (childNodes[i].Name == "LoopConditions")
					{
						num++;
					}
				}
				nID -= num;
				for (int j = 0; j < childNodes.Count; j++)
				{
					if (!(childNodes[j].Name == "LoopConditions"))
					{
						continue;
					}
					XmlNodeList childNodes2 = childNodes[j].ChildNodes;
					for (int k = 0; k < childNodes2.Count; k++)
					{
						if (childNodes2[k].Name == "ScenarioID")
						{
							nID++;
							childNodes2[k].InnerText = nID.ToString();
						}
					}
				}
				break;
			}
			}
			return true;
		}
		catch
		{
			return false;
		}
	}

	public string TestProperties()
	{
		return "";
	}

	private XmlNode GetLastTestFromStack()
	{
		if (stackFolder.Count > 0)
		{
			return (XmlNode)stackFolder.Pop();
		}
		return null;
	}

	private void PushToStack(XmlNode obj)
	{
		stackFolder.Push(obj);
	}

	private string GetDetailsInString(XmlNode oNode, string TagName)
	{
		try
		{
			if (xmlMainDoc != null)
			{
				string text = "";
				XmlNodeList childNodes = oNode.ChildNodes;
				string text2 = "";
				for (int i = 0; i < childNodes.Count; i++)
				{
					try
					{
						if (childNodes[i].Attributes.Count > 0)
						{
							if (childNodes[i].Attributes["NodeType"] == null)
							{
								continue;
							}
							string innerText = childNodes[i].Attributes["NodeType"].InnerText;
							if (!(innerText == TagName))
							{
								continue;
							}
							string text3;
							if ((text3 = TagName) != null && text3 == "FolderProperty")
							{
								text = childNodes[i].InnerXml;
								break;
							}
							XmlNodeList childNodes2 = childNodes[i].ChildNodes;
							for (int j = 0; j < childNodes2.Count; j++)
							{
								if (childNodes2[j].Name != "Parameters")
								{
									text += childNodes2[j].OuterXml;
								}
							}
							break;
						}
						if (childNodes[i].Name == "Index")
						{
							text2 = childNodes[i].InnerText;
						}
					}
					catch
					{
					}
				}
				if (text.Trim().Length > 0)
				{
					text = "<Root><NodeIndex>" + text2 + "</NodeIndex>" + text + "</Root>";
				}
				return text;
			}
			return "";
		}
		catch
		{
			return "";
		}
	}

	public string GetXmlStringChildValue(string xmlString, string tagName)
	{
		try
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(xmlString);
			XmlNodeList childNodes = xmlDocument.ChildNodes[0].ChildNodes;
			for (int i = 0; i < childNodes.Count; i++)
			{
				if (childNodes[i].Name == tagName)
				{
					return childNodes[i].InnerText;
				}
			}
		}
		catch
		{
		}
		return "";
	}

	public string SetXmlStringChildValue(string xmlString, string tagName, string strValue)
	{
		try
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(xmlString);
			XmlNodeList childNodes = xmlDocument.ChildNodes[0].ChildNodes;
			for (int i = 0; i < childNodes.Count; i++)
			{
				if (childNodes[i].Name == tagName)
				{
					childNodes[i].InnerText = strValue;
					return xmlDocument.OuterXml;
				}
			}
		}
		catch
		{
		}
		return xmlString;
	}

	public string AddXmlStringChildNode(string xmlString, string tagName, string strValue)
	{
		try
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(xmlString);
			XmlNode xmlNode = xmlDocument.ChildNodes[0];
			XmlNode xmlNode2 = xmlDocument.CreateNode(XmlNodeType.Element, tagName, "");
			xmlNode2.InnerText = strValue;
			xmlNode.AppendChild(xmlNode2);
			return xmlDocument.OuterXml;
		}
		catch
		{
			return xmlString;
		}
	}

	public string AddXmlStringSecondChildNodeAll(string xmlString, string tagName, string strValue)
	{
		try
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(xmlString);
			XmlNodeList childNodes = xmlDocument.ChildNodes;
			for (int i = 0; i < childNodes.Count; i++)
			{
				XmlNodeList childNodes2 = childNodes[i].ChildNodes;
				for (int j = 0; j < childNodes2.Count; j++)
				{
					XmlNode xmlNode = xmlDocument.CreateNode(XmlNodeType.Element, tagName, "");
					xmlNode.InnerText = strValue;
					childNodes2[j].AppendChild(xmlNode);
				}
			}
			return xmlDocument.OuterXml;
		}
		catch
		{
			return xmlString;
		}
	}

	public string AddXmlStringSecondChildNodeIncrementedIndex(string xmlString, string tagName, long childIndex)
	{
		try
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(xmlString);
			XmlNodeList childNodes = xmlDocument.ChildNodes;
			for (int i = 0; i < childNodes.Count; i++)
			{
				XmlNodeList childNodes2 = childNodes[i].ChildNodes;
				for (int j = 0; j < childNodes2.Count; j++)
				{
					if (!(childNodes2[j].Name == "Property"))
					{
						continue;
					}
					string text = "";
					long num = childIndex;
					XmlNodeList childNodes3 = childNodes2[j].ChildNodes;
					for (int k = 0; k < childNodes3.Count; k++)
					{
						if (childNodes3[k].Name == "Description")
						{
							string innerText = childNodes3[k].InnerText;
							string[] array = innerText.Split(',');
							for (int l = 0; l < array.Length - 1; l++)
							{
								text = ((!(array[l].Trim() == "")) ? (text + num + ",") : (text + ","));
								num++;
							}
							text = ((!(array[array.Length - 1].Trim() == "")) ? (text + num) : (text ?? ""));
						}
					}
					XmlNode xmlNode = xmlDocument.CreateNode(XmlNodeType.Element, tagName, "");
					xmlNode.InnerText = text;
					childNodes2[j].AppendChild(xmlNode);
				}
			}
			return xmlDocument.OuterXml;
		}
		catch
		{
			return xmlString;
		}
	}
}
