using System;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using LabVIEW;

namespace QC.QTMLabViewKernel;

public class LabViewKernel
{
	private struct VIData
	{
		public string VIName;

		public VirtualInstrument viRef;

		public object Parameters;

		public object Properties;
	}

	private struct ParamData
	{
		public string Name;

		public string type;

		public string IOType;

		public string desc;

		public int NumElts;

		public string UL;

		public string LL;

		public string UOM;

		public int DisplayHint;

		public string Constraint;
	}

	public const int iException = 2;

	public const int iFailed = 0;

	public const int iPassed = 1;

	private LabVIEW.Application lv;

	private string EXPORTSTRING_FILE_NAME = "c:\\Qualcomm\\QSPR\\Temp\\ExportString.xml";

	private string EXPORTSTRING_LOG_FILE_NAME = "c:\\Qualcomm\\QSPR\\Temp\\str.log";

	private string EXPORTSTRING_FIXED_FILE_NAME = "c:\\Qualcomm\\QSPR\\Temp\\ExportString_FIXED.xml";

	private string NAME_END_TAG = "\"";

	private string INPUT_PARAM_TAG = "Input";

	private string OUTPUT_PARAM_TAG = "Output";

	private ArrayList ParamArray;

	private object[,] LastTestParamResults;

	private string CLUSTER_SEP = ".";

	public event VIDoneEventHandler OnVIDone;

	public bool CloseKernel()
	{
		if (lv != null)
		{
			lv = null;
		}
		return true;
	}

	public bool ReconnectKernel()
	{
		if (lv != null)
		{
			try
			{
				lv.Quit();
			}
			catch
			{
			}
		}
		lv = new ApplicationClass();
		return true;
	}

	public bool LoadTestDLL(string TestDLL, ref string ListOfTests)
	{
		FileInfo fileInfo = new FileInfo(TestDLL);
		ListOfTests = fileInfo.Name.Remove(fileInfo.Name.IndexOf(fileInfo.Extension), fileInfo.Extension.Length) + ",";
		return true;
	}

	public bool UnloadTestDLL(string VIFullName)
	{
		try
		{
			if (lv == null)
			{
				lv = new ApplicationClass();
			}
			VirtualInstrument vIReference = GetVIReference(VIFullName, resvForCall: true);
			vIReference.CloseFrontPanel();
			vIReference.Abort();
		}
		catch (Exception)
		{
			return false;
		}
		return true;
	}

	public bool RunTest(string VIFullName, ref object parameters, ref object properties)
	{
		try
		{
			VirtualInstrument vIReference = GetVIReference(VIFullName, resvForCall: true);
			VIData vIData = default(VIData);
			vIData.VIName = VIFullName;
			vIData.viRef = vIReference;
			vIData.Parameters = parameters;
			vIData.Properties = properties;
			ThreadPool.QueueUserWorkItem(RunVITest, vIData);
			return true;
		}
		catch (Exception)
		{
			return false;
		}
	}

	public void RunVITest(object stateInfo)
	{
		if (stateInfo == null)
		{
			return;
		}
		VIData vIData = (VIData)stateInfo;
		object[,] array = (object[,])vIData.Parameters;
		string[] array2 = new string[array.GetLength(0)];
		array.GetLength(0);
		ArrayList arrayList = new ArrayList();
		ArrayList arrayList2 = new ArrayList();
		ArrayList arrayList3 = new ArrayList();
		string text = "";
		string text2 = "";
		for (int i = 0; i < array.GetLength(0); i++)
		{
			array2[i] = array[i, 0].ToString();
			text2 = GetClusterName(array2[i]);
			if (text2.Length > 0)
			{
				if (text == "" || text != text2)
				{
					if (text.Length > 0)
					{
						object[] array3 = new object[arrayList3.Count];
						for (int j = 0; j < arrayList3.Count; j++)
						{
							array3[j] = arrayList3[j];
						}
						arrayList2.Add(array3);
						arrayList3.Clear();
					}
					text = text2;
					ParamData paramData = default(ParamData);
					paramData.Name = text2;
					paramData.LL = (string)array[i, 2];
					paramData.UL = (string)array[i, 3];
					paramData.NumElts = (int)array[i, 4];
					paramData.IOType = (string)array[i, 5];
					paramData.UOM = (string)array[i, 6];
					paramData.desc = (string)array[i, 7];
					arrayList.Add(paramData);
					arrayList3.Add(array[i, 1].ToString());
				}
				else if (text == text2)
				{
					arrayList3.Add(array[i, 1].ToString());
				}
				continue;
			}
			if (text.Length > 0)
			{
				object[] array4 = new object[arrayList3.Count];
				for (int k = 0; k < arrayList3.Count; k++)
				{
					array4[k] = arrayList3[k];
				}
				arrayList2.Add(array4);
				arrayList3.Clear();
			}
			text = "";
			ParamData paramData2 = default(ParamData);
			paramData2.Name = array2[i];
			paramData2.LL = (string)array[i, 2];
			paramData2.UL = (string)array[i, 3];
			paramData2.NumElts = (int)array[i, 4];
			paramData2.IOType = (string)array[i, 5];
			paramData2.UOM = (string)array[i, 6];
			paramData2.desc = (string)array[i, 7];
			arrayList.Add(paramData2);
			arrayList2.Add(array[i, 1].ToString());
		}
		if (text.Length > 0)
		{
			object[] array5 = new object[arrayList3.Count];
			for (int l = 0; l < arrayList3.Count; l++)
			{
				array5[l] = arrayList3[l];
			}
			arrayList2.Add(array5);
			arrayList3.Clear();
		}
		text = "";
		string[] array6 = new string[arrayList.Count];
		object[] array7 = new object[arrayList.Count];
		for (int m = 0; m < arrayList.Count; m++)
		{
			ParamData paramData3 = (ParamData)arrayList[m];
			array6[m] = paramData3.Name;
			try
			{
				if (arrayList2[m].GetType().ToString() == "System.Object[]")
				{
					object[] array8 = new object[((object[])arrayList2[m]).Length];
					for (int n = 0; n < ((object[])arrayList2[m]).Length; n++)
					{
						object obj = ((object[])arrayList2[m])[n];
						if (paramData3.NumElts > 1 || ((string)obj).Split(',').Length >= 2)
						{
							string[] array9 = ((string)obj).Split(',');
							object[] array10 = new object[array9.Length];
							for (int num = 0; num < array9.Length; num++)
							{
								array10[num] = array9[num];
							}
							array8[n] = array10;
						}
						else
						{
							array8[n] = obj;
						}
					}
					array7[m] = array8;
				}
				else if (paramData3.NumElts > 1 || ((string)arrayList2[m]).Split(',').Length >= 2)
				{
					string[] array11 = ((string)arrayList2[m]).Split(',');
					object[] array12 = new object[array11.Length];
					for (int num2 = 0; num2 < array11.Length; num2++)
					{
						array12[num2] = array11[num2];
					}
					array7[m] = array12;
				}
				else
				{
					array7[m] = arrayList2[m];
				}
			}
			catch
			{
				array7[m] = arrayList2[m];
			}
		}
		object paramNames = array6;
		object paramVals = array7;
		object[] array13 = (object[])vIData.Properties;
		string vIFullPath = (string)array13[0];
		if ((bool)array13[3])
		{
			vIData.viRef.ShowFPOnCall = true;
		}
		else
		{
			vIData.viRef.ShowFPOnCall = false;
			try
			{
				vIData.viRef.CloseFrontPanel();
			}
			catch
			{
			}
		}
		vIData.viRef.CloseFPAfterCall = false;
		if ((bool)array13[2])
		{
			vIData.viRef.CloseFPAfterCall = true;
		}
		try
		{
			vIData.viRef.Call(ref paramNames, ref paramVals);
			int testResult = (SaveParamOutput(array2, paramNames, paramVals, array, out LastTestParamResults) ? 1 : 0);
			if (this.OnVIDone != null)
			{
				this.OnVIDone(vIFullPath, testResult, LastTestParamResults);
			}
		}
		catch (Exception objParams)
		{
			if (this.OnVIDone != null)
			{
				this.OnVIDone(vIFullPath, 2, objParams);
			}
		}
	}

	public bool LoadVI(string VIFullPath)
	{
		GetVIReference(VIFullPath, resvForCall: true);
		return false;
	}

	private VirtualInstrument GetVIReference(string VIFullPath, bool resvForCall)
	{
		VirtualInstrument virtualInstrument = null;
		if (lv == null)
		{
			lv = new ApplicationClass();
		}
		try
		{
			return lv.GetVIReference(VIFullPath, "", resvForCall, 0);
		}
		catch (COMException)
		{
			lv = new ApplicationClass();
			return lv.GetVIReference(VIFullPath, "", resvForCall, 0);
		}
	}

	public bool GetResultsParamInfo(ref object objResult)
	{
		objResult = LastTestParamResults;
		return true;
	}

	public bool SaveParamOutput(object paramAllNames, object paramName, object paramValue, object[,] refParams, out object[,] ObjOutput)
	{
		_ = (object[])paramName;
		object[] array = (object[])paramValue;
		_ = (string[])paramAllNames;
		ObjOutput = new object[12, refParams.GetLength(0)];
		int i = 0;
		for (int j = 0; j < array.GetLength(0); j++)
		{
			string text = array[j].GetType().ToString();
			if (text.IndexOf("System.Object[]") >= 0)
			{
				object[] array2 = (object[])array[j];
				int length = array2.GetLength(0);
				int num = i + length;
				int num2 = 0;
				if (array2[0].GetType().ToString().IndexOf("System.Object[]") >= 0)
				{
					for (int k = 0; k < GetLengthOfLastCluster(array2); k++)
					{
						PopulateOutputObject(refParams, ref ObjOutput, i++, GetAllClusterInfo(array2, k));
					}
				}
				else
				{
					for (; i < num; i++)
					{
						PopulateOutputObject(refParams, ref ObjOutput, i, array2[num2++]);
					}
				}
			}
			else
			{
				PopulateOutputObject(refParams, ref ObjOutput, i++, array[j]);
			}
		}
		return true;
	}

	private int GetLengthOfLastCluster(object[] cluster)
	{
		int num = 0;
		if (num < cluster.Length)
		{
			object obj = cluster[num];
			if (obj.GetType().ToString().IndexOf("System.Object[]") >= 0)
			{
				return GetLengthOfLastCluster((object[])obj);
			}
			return cluster.Length;
		}
		return -1;
	}

	private object GetAllClusterInfo(object[] cluster, int infoIndex)
	{
		object obj = null;
		foreach (object obj2 in cluster)
		{
			if (obj2.GetType().ToString().IndexOf("System.Object[]") >= 0)
			{
				obj = string.Concat(obj, GetAllClusterInfo((object[])obj2, infoIndex).ToString());
				continue;
			}
			if (infoIndex > cluster.Length - 1)
			{
				return new object();
			}
			return cluster[infoIndex].ToString() + ",";
		}
		return obj.ToString().TrimEnd(',');
	}

	private void PopulateOutputObject(object[,] refParams, ref object[,] objOutput, int objIndex, object paramVIValue)
	{
		try
		{
			objOutput[0, objIndex] = (string)refParams[objIndex, 0];
			objOutput[1, objIndex] = "String";
			objOutput[2, objIndex] = 1;
			objOutput[3, objIndex] = paramVIValue.ToString();
			string text = paramVIValue.GetType().ToString();
			if (refParams[objIndex, 5] == "Output")
			{
				objOutput[4, objIndex] = "Output";
				if (text.IndexOf("Double[") >= 0 || text.IndexOf("Int[") >= 0)
				{
					if (text.IndexOf("Double[,]") >= 0 || text.IndexOf("Int[,]") >= 0)
					{
						double[,] array = (double[,])paramVIValue;
						int length = array.GetLength(0);
						int length2 = array.GetLength(1);
						objOutput[1, objIndex] = "Double";
						objOutput[2, objIndex] = length;
						objOutput[3, objIndex] = "";
						for (int i = 0; i < length; i++)
						{
							for (int j = 0; j < length2; j++)
							{
								object[,] array2;
								object[,] array3 = (array2 = objOutput);
								nint num = objIndex;
								array3[3, objIndex] = string.Concat(array2[3, (int)num], array[i, j].ToString(), "#");
							}
							objOutput[3, objIndex] = objOutput[3, objIndex].ToString().TrimEnd('#') + ",";
						}
						objOutput[3, objIndex] = objOutput[3, objIndex].ToString().TrimEnd(',');
					}
					else
					{
						double[] array4 = (double[])paramVIValue;
						objOutput[1, objIndex] = "Double";
						objOutput[2, objIndex] = array4.Length;
						objOutput[3, objIndex] = "";
						for (int k = 0; k < array4.Length; k++)
						{
							object[,] array5;
							object[,] array6 = (array5 = objOutput);
							nint num2 = objIndex;
							array6[3, objIndex] = string.Concat(array5[3, (int)num2], array4[k].ToString(), ",");
						}
						objOutput[3, objIndex] = objOutput[3, objIndex].ToString().TrimEnd(',');
					}
				}
				else if (text.IndexOf("String[]") >= 0)
				{
					string[] array7 = (string[])paramVIValue;
					objOutput[2, objIndex] = array7.Length;
					objOutput[3, objIndex] = "";
					for (int l = 0; l < array7.Length; l++)
					{
						object[,] array8;
						object[,] array9 = (array8 = objOutput);
						nint num3 = objIndex;
						array9[3, objIndex] = string.Concat(array8[3, (int)num3], array7[l].ToString(), ",");
					}
					objOutput[3, objIndex] = objOutput[3, objIndex].ToString().TrimEnd(',');
				}
				else if (text.IndexOf("Double") >= 0 || text.IndexOf("Int") >= 0)
				{
					objOutput[1, objIndex] = "Double";
				}
			}
			objOutput[5, objIndex] = (string)refParams[objIndex, 3];
			objOutput[6, objIndex] = (string)refParams[objIndex, 2];
			objOutput[7, objIndex] = (string)refParams[objIndex, 6];
			objOutput[8, objIndex] = (string)refParams[objIndex, 7];
			objOutput[9, objIndex] = "";
			objOutput[10, objIndex] = 0;
			objOutput[11, objIndex] = false;
		}
		catch (Exception ex)
		{
			Console.WriteLine(ex.Message);
		}
	}

	private void GetOutputDataBasedOnType(object[] paramValues, int objIndex, ref object[,] objOutput)
	{
		string text = paramValues[objIndex].GetType().ToString();
		if (text.IndexOf("Double[") >= 0 || text.IndexOf("Int[") >= 0)
		{
			if (text.IndexOf("Double[,]") >= 0 || text.IndexOf("Int[,]") >= 0)
			{
				double[,] array = (double[,])paramValues[objIndex];
				int length = array.GetLength(0);
				int length2 = array.GetLength(1);
				objOutput[1, objIndex] = "Double";
				objOutput[2, objIndex] = length;
				objOutput[3, objIndex] = "";
				for (int i = 0; i < length; i++)
				{
					for (int j = 0; j < length2; j++)
					{
						object[,] array2;
						object[,] array3 = (array2 = objOutput);
						nint num = objIndex;
						array3[3, objIndex] = string.Concat(array2[3, (int)num], array[i, j].ToString(), "#");
					}
					objOutput[3, objIndex] = objOutput[3, objIndex].ToString().TrimEnd('#') + ",";
				}
				objOutput[3, objIndex] = objOutput[3, objIndex].ToString().TrimEnd(',');
			}
			else
			{
				double[] array4 = (double[])paramValues[objIndex];
				objOutput[1, objIndex] = "Double";
				objOutput[2, objIndex] = array4.Length;
				objOutput[3, objIndex] = "";
				for (int k = 0; k < array4.Length; k++)
				{
					object[,] array5;
					object[,] array6 = (array5 = objOutput);
					nint num2 = objIndex;
					array6[3, objIndex] = string.Concat(array5[3, (int)num2], array4[k].ToString(), ",");
				}
				objOutput[3, objIndex] = objOutput[3, objIndex].ToString().TrimEnd(',');
			}
		}
		else if (text.IndexOf("String[]") >= 0)
		{
			string[] array7 = (string[])paramValues[objIndex];
			objOutput[2, objIndex] = array7.Length;
			objOutput[3, objIndex] = "";
			for (int l = 0; l < array7.Length; l++)
			{
				object[,] array8;
				object[,] array9 = (array8 = objOutput);
				nint num3 = objIndex;
				array9[3, objIndex] = string.Concat(array8[3, (int)num3], array7[l].ToString(), ",");
			}
			objOutput[3, objIndex] = objOutput[3, objIndex].ToString().TrimEnd(',');
		}
		else if (text.IndexOf("Double") >= 0 || text.IndexOf("Int") >= 0)
		{
			objOutput[1, objIndex] = "Double";
		}
	}

	private bool CreateParamCollection(ArrayList paramsList, out object[,] ObjOutput)
	{
		ObjOutput = new object[12, paramsList.Count];
		int num = 0;
		foreach (ParamData @params in paramsList)
		{
			try
			{
				ObjOutput[0, num] = @params.Name;
				if (@params.type == "Numeric")
				{
					ObjOutput[1, num] = "Double";
				}
				else
				{
					ObjOutput[1, num] = @params.type;
				}
				ObjOutput[2, num] = @params.NumElts;
				ObjOutput[3, num] = -9999;
				ObjOutput[4, num] = @params.IOType;
				ObjOutput[5, num] = "";
				ObjOutput[6, num] = "";
				ObjOutput[7, num] = "unit";
				ObjOutput[8, num] = @params.desc;
				ObjOutput[9, num] = @params.Constraint;
				ObjOutput[10, num] = @params.DisplayHint;
				ObjOutput[11, num] = false;
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.Message);
			}
			num++;
		}
		return true;
	}

	public bool GetAllParamInfo(string VIFullPath, ref object obj)
	{
		try
		{
			VirtualInstrument vIReference = GetVIReference(VIFullPath, resvForCall: false);
			vIReference.EditMode = false;
			File.Delete(EXPORTSTRING_FILE_NAME);
			vIReference.ExportVIStrings(EXPORTSTRING_FILE_NAME, interactive: false, EXPORTSTRING_LOG_FILE_NAME, captions: false, exportDiagram: false);
			CleanXmlFile(EXPORTSTRING_FILE_NAME, EXPORTSTRING_FIXED_FILE_NAME);
			ParamArray = new ArrayList();
			GetParamFromXmlFile(EXPORTSTRING_FIXED_FILE_NAME, ref ParamArray);
			CreateParamCollection(ParamArray, out var ObjOutput);
			obj = ObjOutput;
		}
		catch (Exception)
		{
			return false;
		}
		return true;
	}

	private bool CleanXmlFile(string InputXmlfile, string CleanedXmlFile)
	{
		try
		{
			StreamReader streamReader = File.OpenText(InputXmlfile);
			StreamWriter streamWriter = new StreamWriter(CleanedXmlFile, append: false);
			streamWriter.WriteLine("<VI>");
			streamReader.ReadLine();
			string text;
			while ((text = streamReader.ReadLine()) != null)
			{
				if (!text.StartsWith("<TITLE>"))
				{
					text = Regex.Replace(text, "<LF>", "");
					text = Regex.Replace(text, "<SAME_AS_LABEL>", "");
					text = Regex.Replace(text, "<NON_STRING>", "");
					if (text.IndexOf("ARRAY nElems") >= 0)
					{
						text = Regex.Replace(text, "\\d{1,}", "\"$&\"");
					}
					text = Regex.Replace(text, "ID=\\d{1,}", "");
					text = Regex.Replace(text, "order=\\d{1,}", "");
					text = Regex.Replace(text, "<<B>>", " ");
					text = Regex.Replace(text, "<</B>>", " ");
					text = Regex.Replace(text, "<SEP>", " ");
					for (int num = text.IndexOf("<FONT"); num >= 0; num = text.IndexOf("<FONT"))
					{
						int num2 = text.IndexOf(">", num);
						text = text.Remove(num, num2 - num);
					}
					streamWriter.WriteLine(text);
				}
			}
			streamWriter.Close();
			streamReader.Close();
		}
		catch (Exception)
		{
			return false;
		}
		return true;
	}

	private void GetParamFromXmlFile(string XMLFileName, ref ArrayList paramList)
	{
		try
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(XMLFileName);
			paramList.Clear();
			foreach (XmlNode item in xmlDocument)
			{
				ListChild("", "", IsArray: false, item, ref paramList);
			}
		}
		catch
		{
			MessageBox.Show("                     Non XML characters found on VI.\nPlease remove non XML characters from the VI like &,$,% etc.", "QTM - LabVIEW Kernel", MessageBoxButtons.OK, MessageBoxIcon.Hand);
		}
	}

	private string GetNameAttrib(XmlAttribute attrib, string ParentName, bool TypeDef)
	{
		string text = "";
		if (attrib.Name.ToUpper() == "NAME")
		{
			if (ParentName != "")
			{
				text = ParentName + ".";
			}
			if (TypeDef || attrib.Value.Length < 1)
			{
				text = text.Remove(text.Length - 1);
			}
			text += attrib.Value;
		}
		return text;
	}

	private void ListChildAttributes(string ParentName, string InputType, bool IsArray, XmlNode node1, ref ArrayList paramList)
	{
		ListChildAttributes(ParentName, InputType, IsArray, node1, ref paramList, TypeDef: false);
	}

	private void ListChildAttributes(string ParentName, string InputType, bool IsArray, XmlNode node1, ref ArrayList paramList, bool TypeDef)
	{
		try
		{
			foreach (XmlNode childNode in node1.ChildNodes)
			{
				if (!(childNode.Name == "Control".ToUpper()))
				{
					continue;
				}
				XmlAttributeCollection attributes = childNode.Attributes;
				string text = "";
				string text2 = "";
				foreach (XmlAttribute item in attributes)
				{
					if (item.Name.ToUpper() == "TYPE")
					{
						text = item.Value;
					}
					text2 = GetNameAttrib(item, ParentName, TypeDef);
				}
				if (text.ToUpper() == "CLUSTER")
				{
					string text3 = "";
					try
					{
						text3 = childNode["TIP"].InnerText;
					}
					catch
					{
					}
					if (text3 != "" && (text3.ToUpper().StartsWith(OUTPUT_PARAM_TAG.ToUpper()) || text3.ToUpper().StartsWith(INPUT_PARAM_TAG.ToUpper())))
					{
						ListChild(text2, text3, IsArray, childNode, ref paramList);
					}
				}
				else if (text.ToUpper() == "ARRAY")
				{
					ListChild(text2, InputType, IsArray: true, childNode, ref paramList);
				}
				else if (text.ToUpper() == "TYPE DEFINITION")
				{
					ListChildAttributes(text2, "", IsArray, childNode["PARTS"]["PART"], ref paramList, TypeDef: true);
				}
				else
				{
					if (!(text.ToUpper() == "NUMERIC") && !(text.ToUpper() == "STRING") && !(text.ToUpper() == "RING") && !(text.ToUpper() == "BOOLEAN") && !(text.ToUpper() == "VISA RESOURCE NAME") && !(text.ToUpper() == "DAQ CHANNEL NAME") && !(text.ToUpper() == "PATH") && !(text.ToUpper() == "COMBO BOX"))
					{
						continue;
					}
					ParamData paramData = default(ParamData);
					string text4 = "";
					paramData.Name = text2;
					paramData.DisplayHint = 0;
					if (text.ToUpper() == "PATH")
					{
						paramData.DisplayHint = 1;
					}
					if (text.ToUpper() == "VISA RESOURCE NAME" || text.ToUpper() == "DAQ CHANNEL NAME" || text.ToUpper() == "PATH")
					{
						text = "STRING";
					}
					paramData.type = text;
					paramData.NumElts = 1;
					paramData.Constraint = "";
					if (IsArray)
					{
						string innerXml = childNode.ParentNode.ParentNode.InnerXml;
						string Value = "";
						if (GetTagValue(innerXml, "nElems=\"", NAME_END_TAG, out Value))
						{
							paramData.NumElts = int.Parse(Value);
						}
					}
					if (childNode.ChildNodes[0].Name.ToUpper() == "DESC")
					{
						paramData.desc = childNode.ChildNodes[0].InnerText;
					}
					if (InputType == "")
					{
						try
						{
							text4 = childNode["TIP"].InnerText;
						}
						catch
						{
						}
					}
					else
					{
						text4 = InputType;
					}
					if (text.ToUpper() == "RING" || text.ToUpper() == "BOOLEAN")
					{
						foreach (XmlNode childNode2 in childNode.ChildNodes)
						{
							if (!(childNode2.Name.ToUpper() == "PARTS"))
							{
								continue;
							}
							foreach (XmlNode childNode3 in childNode2.ChildNodes)
							{
								foreach (XmlAttribute attribute in childNode3.Attributes)
								{
									if (!(attribute.Name.ToUpper() == "TYPE") || (!(attribute.Value == "Ring Text") && !(attribute.Value == "Boolean Text")))
									{
										continue;
									}
									foreach (XmlNode childNode4 in childNode3.ChildNodes)
									{
										foreach (XmlNode childNode5 in childNode4.ChildNodes)
										{
											foreach (XmlNode childNode6 in childNode5.ChildNodes)
											{
												paramData.Constraint = paramData.Constraint + childNode6.InnerXml + ";";
											}
											if (paramData.Constraint.EndsWith(";"))
											{
												paramData.Constraint = paramData.Constraint.Substring(0, paramData.Constraint.Length - 1);
											}
											paramData.DisplayHint = 8;
										}
									}
								}
							}
						}
					}
					if (text.ToUpper() == "COMBO BOX")
					{
						paramData.type = "STRING";
						foreach (XmlNode item2 in childNode["PARTS"].ChildNodes[0]["CONTROL"]["PRIV"]["STRINGS"])
						{
							paramData.Constraint = paramData.Constraint + item2.InnerXml + ";";
						}
						if (paramData.Constraint.EndsWith(";"))
						{
							paramData.Constraint = paramData.Constraint.Substring(0, paramData.Constraint.Length - 1);
						}
						paramData.DisplayHint = 256;
					}
					if (text4 != "")
					{
						if (text4.ToUpper().StartsWith(OUTPUT_PARAM_TAG.ToUpper()))
						{
							paramData.IOType = "Output";
							paramList.Add(paramData);
						}
						else if (text4.ToUpper().StartsWith(INPUT_PARAM_TAG.ToUpper()))
						{
							paramData.IOType = "Input";
							paramList.Add(paramData);
						}
					}
				}
			}
		}
		catch (Exception)
		{
		}
	}

	private void ListChild(string ParentName, string InputType, bool IsArray, XmlNode node, ref ArrayList paramList)
	{
		foreach (XmlNode childNode in node.ChildNodes)
		{
			if (childNode.Name == "Content".ToUpper())
			{
				ListChildAttributes(ParentName, InputType, IsArray, childNode, ref paramList);
			}
		}
	}

	private bool GetTagValue(string input, string tagName, string EndString, out string Value)
	{
		Value = "";
		Regex regex = new Regex(tagName);
		Match match = regex.Match(input);
		if (match.Success)
		{
			regex = new Regex(EndString);
			Match match2 = regex.Match(input, match.Index + tagName.Length);
			if (match2.Success)
			{
				Value = input.Substring(match.Index + tagName.Length, match2.Index - (match.Index + tagName.Length));
				return true;
			}
		}
		return false;
	}

	public string GetClusterName(string ParamName)
	{
		if (ParamName.IndexOf(CLUSTER_SEP) > 0)
		{
			return ParamName.Substring(0, ParamName.IndexOf(CLUSTER_SEP));
		}
		return "";
	}
}
