using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Threading;
using System.Windows.Forms;
using QC.GlobalVariableManager;
using QC.QsprShared.Trace;
using QC.QsprTestObjects.TestConditions;
using QC.QsprTestObjects.Tests.Base;
using QC.QTMInterface;
using QC.QTMInterface.Business_Objects;

namespace QC.QsprTestObjects.Parameters;

[Serializable]
[TypeConverter(typeof(ParamCollectionConverter))]
public class ParameterCollection : CollectionBase, ICustomTypeDescriptor
{
	public const char ARRAY_SEPARATOR = ',';

	public const char ARRAY_SEPARATOR_FOR_STRING = '^';

	private bool clearOnAdd;

	internal bool ClearOnAdd
	{
		get
		{
			return clearOnAdd;
		}
		set
		{
			clearOnAdd = value;
		}
	}

	public ParameterCls this[int index]
	{
		get
		{
			return (ParameterCls)base.List[index];
		}
		set
		{
			base.List[index] = value;
		}
	}

	public bool OutputParametersInLimits
	{
		get
		{
			try
			{
				foreach (ParameterCls item in base.List)
				{
					if (item.IsOutput && !item.ParameterValueInLimits)
					{
						return false;
					}
				}
			}
			catch
			{
			}
			return true;
		}
	}

	public ParameterCollection Clone()
	{
		try
		{
			ParameterCollection parameterCollection = new ParameterCollection();
			IEnumerator enumerator = GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ParameterCls parameterCls = (ParameterCls)enumerator.Current;
					ParameterCls value = parameterCls.Clone();
					parameterCollection.Add(value);
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			return parameterCollection;
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "Clone " + ex.Message, TraceMessageType.Exception);
		}
		return null;
	}

	public void Copy(ParameterCollection paramColl)
	{
		try
		{
			ClearOnAdd = true;
			foreach (ParameterCls item in paramColl)
			{
				{
					IEnumerator enumerator2 = GetEnumerator();
					try
					{
						while (enumerator2.MoveNext())
						{
							ParameterCls parameterCls2 = (ParameterCls)enumerator2.Current;
							if (parameterCls2.Name == item.Name)
							{
								parameterCls2.Copy(item);
							}
						}
					}
					finally
					{
						IDisposable disposable = enumerator2 as IDisposable;
						if (disposable != null)
						{
							disposable.Dispose();
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "Clone " + ex.Message, TraceMessageType.Exception);
		}
	}

	public ParameterCollection Sort()
	{
		try
		{
			ParameterCollection parameterCollection = new ParameterCollection();
			ArrayList arrayList = new ArrayList();
			IEnumerator enumerator = GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ParameterCls parameterCls = (ParameterCls)enumerator.Current;
					arrayList.Add(parameterCls.Name);
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			arrayList.Sort();
			foreach (string item in arrayList)
			{
				parameterCollection.Add(GetParameter(item).Clone());
			}
			return parameterCollection;
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "Clone " + ex.Message, TraceMessageType.Exception);
		}
		return null;
	}

	public ParameterCollection SelectedParameters()
	{
		try
		{
			ParameterCollection parameterCollection = new ParameterCollection();
			IEnumerator enumerator = GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ParameterCls parameterCls = (ParameterCls)enumerator.Current;
					if (parameterCls.Selected)
					{
						ParameterCls value = parameterCls.Clone();
						parameterCollection.Add(value);
					}
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			return parameterCollection;
		}
		catch
		{
		}
		return null;
	}

	public ParameterCollection()
	{
	}

	public ParameterCollection(object obj)
	{
		try
		{
			object[,] array = (object[,])obj;
			for (int i = 0; i < array.GetLength(1); i++)
			{
				string type = (string)array[1, i];
				DataType typ = StringToDataType(type);
				IOType type2 = StringToIOType((string)array[4, i]);
				bool nULLABLE = false;
				string parentName = "";
				string realNameVal = "";
				bool isDynamicArray = -1 == (int)array[2, i];
				bool isEditableInTestPlan = false;
				bool canEditResultValue = false;
				if (array.GetLength(0) > 13)
				{
					nULLABLE = (bool)array[13, i];
					if (array.GetLength(0) > 14)
					{
						parentName = (string)array[14, i];
					}
					if (array.GetLength(0) > 15)
					{
						isDynamicArray = (bool)array[15, i];
					}
					if (array.GetLength(0) > 16)
					{
						isEditableInTestPlan = (bool)array[16, i];
					}
					if (array.GetLength(0) > 17)
					{
						canEditResultValue = (bool)array[17, i];
					}
					if (array.GetLength(0) > 18)
					{
						realNameVal = (string)array[18, i];
					}
				}
				ParameterCls parameterCls = new ParameterCls(array[0, i].ToString(), typ, (int)array[2, i], array[3, i].ToString(), type2, array[5, i].ToString(), array[6, i].ToString(), array[7, i].ToString(), array[8, i].ToString(), array[9, i].ToString(), (int)array[10, i], (bool)array[11, i], nULLABLE, parentName, isDynamicArray, realNameVal);
				if (parameterCls.IsParamDataTable())
				{
					parameterCls.DataTableValue = (DataTable)array[3, i];
				}
				if (array.GetLength(0) > 12 && !(bool)array[12, i])
				{
					parameterCls.Selected = false;
				}
				parameterCls.IsDynamicArray = isDynamicArray;
				parameterCls.OriginalValue = parameterCls.Value;
				parameterCls.IsEditableInTestPlan = isEditableInTestPlan;
				parameterCls.CanEditResultValue = canEditResultValue;
				Add(parameterCls);
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "ParameterCollection " + ex.Message, TraceMessageType.Exception);
		}
	}

	internal ParameterCollection(ParameterCls[] initialValue)
	{
		AddRange(initialValue);
	}

	public ParameterCollection(List<TestParameter> data)
	{
		base.List.Clear();
		foreach (TestParameter datum in data)
		{
			ParameterCls value = new ParameterCls
			{
				GlobalVariableName = datum.GVGet,
				GlobalVariableNameOther = datum.GVSet,
				Name = datum.Name,
				Description = datum.Description,
				Unit = datum.Unit,
				Value = datum.Value,
				Type = (datum.IsOutput ? IOType.Output : IOType.Input),
				NoOfElements = datum.NoOfElements,
				UpperLimit = datum.UL,
				LowerLimit = datum.LL,
				OriginalValue = datum.Value
			};
			base.List.Add(value);
		}
	}

	public string GetFailedOnLimitsParamString()
	{
		string result = string.Empty;
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.IsOutput && !item.ParameterValueInLimits)
				{
					result = " [ (" + item.Name + ") LL:" + item.LowerLimit.ToString() + "|UL:" + item.UpperLimit.ToString() + "|Actual:" + item.Value.ToString() + " ]";
				}
			}
		}
		catch
		{
		}
		return result;
	}

	public void UpdateFromGlobalVariables(RootTest Root)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				try
				{
					if (item.IsInput)
					{
						if (item.GlobalVariableName.Trim().Length != 0 && Root.Scheduler.Env.GlobalVariable.GetGlobalVariable(item.GlobalVariableName.Trim(), out var gvValue) && item.IsValueValid(gvValue))
						{
							item.Value = item.GetDisplayString(gvValue);
						}
						if (item.GlobalVariableNameOther.Trim().Length != 0)
						{
							Root.Scheduler.Env.GlobalVariable.SetGlobalVariable(item.GlobalVariableNameOther.Trim(), item.Value);
						}
					}
					else
					{
						if (item.GlobalVariableForLL.Trim().Length != 0 && Root.Scheduler.Env.GlobalVariable.GetGlobalVariable(item.GlobalVariableForLL.Trim(), out var gvValue2) && (item.IsValueValid(gvValue2) || gvValue2 == string.Empty))
						{
							item.LowerLimit = gvValue2;
						}
						if (item.GlobalVariableForUL.Trim().Length != 0 && Root.Scheduler.Env.GlobalVariable.GetGlobalVariable(item.GlobalVariableForUL.Trim(), out var gvValue3) && (item.IsValueValid(gvValue3) || gvValue3 == string.Empty))
						{
							item.UpperLimit = gvValue3;
						}
					}
				}
				catch
				{
				}
			}
		}
		catch
		{
		}
	}

	public void UpdateToGlobalVariables(RootTest root)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				try
				{
					if (item.IsOutput)
					{
						if (item.GlobalVariableName.Trim().Length != 0 && root.Scheduler.Env.GlobalVariable.GetGlobalVariable(item.GlobalVariableName.Trim(), out var gvValue) && item.IsValueValid(gvValue))
						{
							item.Value = gvValue;
						}
						if (item.GlobalVariableNameOther.Trim().Length != 0)
						{
							root.Scheduler.Env.GlobalVariable.SetGlobalVariable(item.GlobalVariableNameOther.Trim(), item.Value);
						}
					}
				}
				catch
				{
				}
			}
		}
		catch
		{
		}
	}

	private DataType StringToDataType(string type)
	{
		try
		{
			return type.ToUpper() switch
			{
				"INT" => DataType.Int, 
				"HEX" => DataType.Hex, 
				"STRING" => DataType.String, 
				"DOUBLE" => DataType.Double, 
				"BYTE" => DataType.Byte, 
				"BOOLEAN" => DataType.Boolean, 
				"UINT32" => DataType.UInt32, 
				"UINT16" => DataType.UInt16, 
				"UINT64" => DataType.UInt64, 
				"INT16" => DataType.Int16, 
				"INT64" => DataType.Int64, 
				"CHAR" => DataType.Char, 
				"DECIMAL" => DataType.Decimal, 
				"SBYTE" => DataType.SByte, 
				"SINGLE" => DataType.Single, 
				"DATATABLE" => DataType.DataTable, 
				"NULLABLE`1" => DataType.NULLABLE, 
				_ => DataType.String, 
			};
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "StringToType " + ex.Message, TraceMessageType.Exception);
			return DataType.String;
		}
	}

	private IOType StringToIOType(string ioType)
	{
		try
		{
			string text;
			if ((text = ioType) != null && text == "Output")
			{
				return IOType.Output;
			}
			return IOType.Input;
		}
		catch
		{
			return IOType.Input;
		}
	}

	public bool DataLogging(string paramName, bool bEnableLogging)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (!(item.Name == paramName))
				{
					continue;
				}
				if (bEnableLogging)
				{
					if (item.chkEnableDataLogging != CheckState.Checked)
					{
						item.EnableDataLogging.Clear();
						for (int i = 0; i < item.NoOfElements; i++)
						{
							item.EnableDataLogging.Add(true);
						}
						return true;
					}
				}
				else if (item.chkEnableDataLogging != 0)
				{
					item.EnableDataLogging.Clear();
					for (int j = 0; j < item.NoOfElements; j++)
					{
						item.EnableDataLogging.Add(false);
					}
					return true;
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "DataLogging " + ex.Message, TraceMessageType.Exception);
		}
		return false;
	}

	private DataTable GetUpdateDataTableValue(DataTable dt, string newValue, string array2DIndex)
	{
		try
		{
			string[] array = array2DIndex.Split(',');
			int num = int.Parse(array[0]);
			int num2 = int.Parse(array[1]);
			while (dt.Columns.Count - 1 < num2)
			{
				dt.Columns.Add("Col" + dt.Columns.Count);
			}
			while (dt.Rows.Count - 1 < num)
			{
				dt.Rows.Add(dt.NewRow());
			}
			dt.Rows[num].BeginEdit();
			DataRow dataRow = dt.Rows[num];
			dataRow[num2] = newValue;
			dt.Rows[num].EndEdit();
			return dt;
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "GetUpdateDataTableValue " + ex.Message, TraceMessageType.Exception);
			return dt;
		}
	}

	private string GetUpdatedValues(string oldValue, int NoOfElts, string newValue, int index)
	{
		string text = "";
		try
		{
			switch (index)
			{
			case -1:
			{
				text = "";
				for (int i = 0; i < NoOfElts - 1; i++)
				{
					text = text + newValue + ",";
				}
				text += newValue;
				break;
			}
			case -2:
				text = newValue;
				break;
			}
			if (index > -1 && index < NoOfElts)
			{
				string[] array = oldValue.Split(',');
				array[index] = newValue;
				text = "";
				for (int j = 0; j < NoOfElts - 1; j++)
				{
					text = text + array[j] + ",";
				}
				text += array[NoOfElts - 1];
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "GetUpdatedValues " + ex.Message, TraceMessageType.Exception);
		}
		return text;
	}

	public bool SyncParameters(ParameterCollection oldParams, bool syncDescription)
	{
		try
		{
			foreach (ParameterCls oldParam in oldParams)
			{
				if (SetParamValue(oldParam.Name, oldParam.Value, -2, ""))
				{
					SetParamLowerLimit(oldParam.Name, oldParam.LowerLimit, -2);
					SetParamUpperLimit(oldParam.Name, oldParam.UpperLimit, -2);
					SetDataLogging(oldParam.Name, oldParam.EnableDataLogging);
					SetDataLoggingCondition(oldParam.Name, oldParam.DataLoggingCondition);
					SetChartLogging(oldParam.Name, oldParam.EnableCharting);
					SetParamGlobalVariable(oldParam.Name, oldParam.GlobalVariableName);
					SetParamGlobalVariableOther(oldParam.Name, oldParam.GlobalVariableNameOther);
					SetParamLLGlobalVariable(oldParam.Name, oldParam.GlobalVariableForLL);
					SetParamULGlobalVariable(oldParam.Name, oldParam.GlobalVariableForUL);
					SetParamUOM(oldParam.Name, oldParam.Unit);
					if (!syncDescription)
					{
						SetParamDescription(oldParam.Name, oldParam.Description);
					}
				}
			}
			return true;
		}
		catch
		{
		}
		return false;
	}

	public bool SetDataLogging(string strParamName, ArrayList dList)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName && item.NoOfElements == dList.Count)
				{
					item.EnableDataLogging = dList;
					return true;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public bool SetDataLoggingCondition(string strParamName, ConditionMgr condition)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName)
				{
					item.DataLoggingCondition = condition;
					return true;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public bool SetChartLogging(string strParamName, ArrayList dList)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName && item.NoOfElements == dList.Count)
				{
					item.EnableCharting = dList;
					return true;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public bool SetParamLowerLimit(string strParamName, string ParamLLValue, int index)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName)
				{
					item.LowerLimit = GetUpdatedValues(item.LowerLimit, item.NoOfElements, ParamLLValue, index);
					return true;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public ParameterCls FindParam(string strParamName)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName)
				{
					return item;
				}
			}
			return null;
		}
		catch
		{
			return null;
		}
	}

	public bool SetParamUpperLimit(string strParamName, string ParamULValue, int index)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName)
				{
					item.UpperLimit = GetUpdatedValues(item.UpperLimit, item.NoOfElements, ParamULValue, index);
					return true;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public bool SetParamValue(string strParamName, string ParamValue, int index, string array2DIndex)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName)
				{
					if (item.IsParamDataTable())
					{
						item.DataTableValue = GetUpdateDataTableValue(item.DataTableValue, ParamValue, array2DIndex);
						return true;
					}
					item.Value = GetUpdatedValues(item.Value, item.NoOfElements, ParamValue, index);
					return true;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public bool SetParamGlobalVariable(string strParamName, string gvValue)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName)
				{
					item.GlobalVariableName = gvValue;
					return true;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public bool SetParamLLGlobalVariable(string strParamName, string gvValue)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName && item.Type == IOType.Output)
				{
					item.GlobalVariableForLL = gvValue;
					return true;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public bool SetParamULGlobalVariable(string strParamName, string gvValue)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName && item.Type == IOType.Output)
				{
					item.GlobalVariableForUL = gvValue;
					return true;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public bool SetParamGlobalVariableOther(string strParamName, string gvValue)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName)
				{
					item.GlobalVariableNameOther = gvValue;
					return true;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public bool SetParamUOM(string strParamName, string paramUOM)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName)
				{
					item.Unit = paramUOM;
					return true;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public bool SetParamDescription(string strParamName, string paramDDescription)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName)
				{
					item.Description = paramDDescription;
					return true;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public string GetParamValue(string strParamName)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName)
				{
					return item.Value;
				}
			}
			return "";
		}
		catch
		{
			return "";
		}
	}

	public string GetParamUL(string strParamName)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName)
				{
					return item.UpperLimit;
				}
			}
			return "";
		}
		catch
		{
			return "";
		}
	}

	public string GetParamLL(string strParamName)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == strParamName)
				{
					return item.LowerLimit;
				}
			}
			return "";
		}
		catch
		{
			return "";
		}
	}

	public void RemoveRegistrationInformation()
	{
		foreach (ParameterCls item in base.List)
		{
			item.ParamRID = -1L;
			item.ArrayParameterRIDs.Clear();
			for (int i = 0; i < item.NoOfElements; i++)
			{
				item.ArrayParameterRIDs.Add(-1);
			}
		}
	}

	public bool SetParameterValues(ArrayList parameters)
	{
		try
		{
			if (parameters != null)
			{
				foreach (ParamValue parameter2 in parameters)
				{
					ParameterCls parameter = GetParameter(parameter2.ParamName);
					if (parameter != null)
					{
						if (parameter2.Value != null)
						{
							parameter.Value = ArrayListToString(parameter2.Value);
						}
						if (parameter2.LL != null)
						{
							parameter.LowerLimit = ArrayListToString(parameter2.LL);
						}
						if (parameter2.UL != null)
						{
							parameter.UpperLimit = ArrayListToString(parameter2.UL);
						}
						if (parameter2.Desc != null)
						{
							parameter.Description = parameter2.Desc;
						}
						if (parameter2.Unit != null)
						{
							parameter.Unit = parameter2.Unit;
						}
						if (parameter2.Constraint != null)
						{
							parameter.Constraints = parameter2.Constraint;
						}
						if (parameter2.DispHint != 0)
						{
							parameter.DisplayHint = parameter2.DispHint;
						}
						if (parameter2.EnabledDataLogging != null)
						{
							parameter.EnableDataLogging = parameter2.EnabledDataLogging;
						}
						if (parameter2.EnabledCharting != null)
						{
							parameter.EnableCharting = parameter2.EnabledCharting;
						}
						continue;
					}
					return false;
				}
			}
		}
		catch
		{
			return false;
		}
		return true;
	}

	private string ArrayListToString(ArrayList arrayList)
	{
		string text = "";
		try
		{
			int num = 0;
			foreach (string array in arrayList)
			{
				if (num > 0)
				{
					text += ",";
				}
				text += array;
				num++;
			}
		}
		catch
		{
		}
		return text;
	}

	public void UpdateParameters(object obj, bool addRunTimeParam, Dictionary<string, ArrayList> reportingEnabledInformation = null)
	{
		try
		{
			string val = "";
			DataTable dataTableValue = null;
			string realNameVal = "";
			bool flag = false;
			string parentName = "";
			object[,] array = (object[,])obj;
			new ArrayList();
			bool isDynamicArray = false;
			bool isEditableInTestPlan = false;
			for (int i = 0; i < array.GetLength(1); i++)
			{
				IOType iOType = StringToIOType((string)array[4, i]);
				if (iOType == IOType.Input)
				{
					continue;
				}
				string str = array[0, i].ToString();
				DataType dataType = StringToDataType(array[1, i].ToString());
				int iElts = (int)array[2, i];
				if (dataType == DataType.DataTable)
				{
					dataTableValue = (DataTable)array[3, i];
				}
				else
				{
					val = array[3, i].ToString();
				}
				string uL = array[5, i].ToString();
				string lL = array[6, i].ToString();
				string desc = array[8, i].ToString();
				string constraint = array[9, i].ToString();
				int hint = (int)array[10, i];
				bool bUseRuntimeLimits = (bool)array[11, i];
				string unit = array[7, i].ToString();
				flag = false;
				if (array.GetLength(0) > 13)
				{
					flag = (bool)array[13, i];
					if (array.GetLength(0) > 14)
					{
						parentName = (string)array[14, i];
					}
					if (array.GetLength(0) > 15)
					{
						isDynamicArray = (bool)array[15, i];
					}
					if (array.GetLength(0) > 16)
					{
						isEditableInTestPlan = (bool)array[16, i];
					}
					if (array.GetLength(0) > 18)
					{
						realNameVal = (string)array[18, i];
					}
				}
				ParameterCls parameterCls = new ParameterCls(str, dataType, iElts, val, iOType, uL, lL, unit, desc, constraint, hint, bUseRuntimeLimits, flag, parentName, isDynamicArray, realNameVal);
				if (dataType == DataType.DataTable)
				{
					parameterCls.DataTableValue = dataTableValue;
				}
				parameterCls.IsEditableInTestPlan = isEditableInTestPlan;
				bool flag2 = false;
				foreach (ParameterCls item in base.List)
				{
					if (item.Name == parameterCls.Name)
					{
						flag2 = true;
						parameterCls.IsEditableInTestPlan = item.IsEditableInTestPlan;
						parameterCls.CanEditResultValue = item.CanEditResultValue;
						parameterCls.IsDynamicArray = item.IsDynamicArray;
						parameterCls.EnableCharting = item.EnableCharting;
						parameterCls.EnableDataLogging = item.EnableDataLogging;
						parameterCls.ParamRID = item.ParamRID;
						parameterCls.ArrayParameterRIDs = item.ArrayParameterRIDs;
						parameterCls.OriginalValue = item.OriginalValue;
						parameterCls.GlobalVariableName = item.GlobalVariableName;
						parameterCls.GlobalVariableNameOther = item.GlobalVariableNameOther;
						parameterCls.GlobalVariableForLL = item.GlobalVariableForLL;
						parameterCls.GlobalVariableForUL = item.GlobalVariableForUL;
						parameterCls.Unit = item.Unit;
						parameterCls.Description = item.Description;
						parameterCls.DataLoggingCondition = item.DataLoggingCondition;
						parameterCls.IsNullable = item.IsNullable;
						parameterCls.ParentName = item.ParentName;
						parameterCls.RealName = item.RealName;
						base.List[IndexOf(item)] = parameterCls;
						break;
					}
				}
				if (!flag2 && addRunTimeParam)
				{
					if (reportingEnabledInformation != null)
					{
						parameterCls.EnableCharting = reportingEnabledInformation[parameterCls.Name];
					}
					Add(parameterCls);
				}
			}
		}
		catch
		{
		}
	}

	public ArrayList GetInputLoggedParameter()
	{
		ArrayList arrayList = new ArrayList();
		try
		{
			bool flag = false;
			if (QTMGlobalVariable.Contains("GV_LOG_ALL_INPUT_PARAMETERS"))
			{
				try
				{
					string gvValue = string.Empty;
					QTMGlobalVariable.GetGlobalVariable("GV_LOG_ALL_INPUT_PARAMETERS", out gvValue);
					flag = bool.Parse(gvValue);
				}
				catch
				{
					flag = false;
				}
			}
			foreach (ParameterCls item in base.List)
			{
				if (item.IsInput && flag)
				{
					arrayList.Add(item);
				}
				else if (item.IsInput && (item.chkEnableDataLogging == CheckState.Checked || item.chkEnableDataLogging == CheckState.Indeterminate))
				{
					arrayList.Add(item);
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "GetInputLoggedParameter " + ex.Message, TraceMessageType.Exception);
		}
		return arrayList;
	}

	public object GetParameterExportList(bool onlyLoggedParameters, bool outputOnly, bool ignoreEmptyStringValues)
	{
		try
		{
			ArrayList arrayList = new ArrayList();
			foreach (ParameterCls item in base.List)
			{
				bool flag = item.chkEnableDataLogging == CheckState.Checked || item.chkEnableDataLogging == CheckState.Indeterminate || item.chkEnableCharting == CheckState.Checked || item.chkEnableCharting == CheckState.Indeterminate;
				if ((!ignoreEmptyStringValues || item.DataType != DataType.String || item.Value.Trim().Length != 0) && (!onlyLoggedParameters || flag) && (!outputOnly || !item.IsInput))
				{
					ParamValue p = default(ParamValue);
					item.GetParamValue(this, out p);
					arrayList.Add(p);
				}
			}
			return arrayList;
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "GetParameterExportList " + ex.Message, TraceMessageType.Exception);
		}
		return null;
	}

	private static string ReplaceEx(string original, string pattern, string replacement)
	{
		int num2;
		int num;
		int length = (num2 = (num = 0));
		string text = original.ToUpper();
		string value = pattern.ToUpper();
		int val = original.Length / pattern.Length * (replacement.Length - pattern.Length);
		char[] array = new char[original.Length + Math.Max(0, val)];
		while ((num = text.IndexOf(value, num2)) != -1)
		{
			for (int i = num2; i < num; i++)
			{
				array[length++] = original[i];
			}
			for (int j = 0; j < replacement.Length; j++)
			{
				array[length++] = replacement[j];
			}
			num2 = num + pattern.Length;
		}
		if (num2 == 0)
		{
			return original;
		}
		for (int k = num2; k < original.Length; k++)
		{
			array[length++] = original[k];
		}
		return new string(array, 0, length);
	}

	public static bool CreateNameValueList(string constraints, out ArrayList names, out ArrayList values)
	{
		names = new ArrayList();
		values = new ArrayList();
		if (constraints.Trim().Length == 0)
		{
			return false;
		}
		try
		{
			constraints = constraints.Trim();
			string[] array = constraints.Trim().Split(';');
			int num = array.Length;
			if (array[array.Length - 1] == string.Empty)
			{
				num--;
			}
			int num2 = -1;
			for (int i = 0; i < num; i++)
			{
				int num3 = 1;
				int num4 = 0;
				string[] array2 = array[i].Split('=');
				if (array2.Length < 2)
				{
					array[i] = array[i].Trim();
					char[] anyOf = new char[4] { ' ', ',', '.', ':' };
					array2 = new string[2];
					int num5 = array[i].IndexOfAny(anyOf);
					if (num5 >= 0)
					{
						num3 = 0;
						num4 = 1;
						array2[num3] = array[i].Substring(0, num5);
						array2[num4] = array[i].Substring(num5 + 1);
					}
					else
					{
						array2[num3] = array[i];
						array2[num4] = array[i];
					}
				}
				string value = array[i].Trim();
				if (array2.Length > 1)
				{
					value = array2[num4];
					int result = -1;
					if (!int.TryParse(array2[num3].Trim(), out result))
					{
						value = array[i].Trim();
						num2++;
					}
					else
					{
						num2 = result;
					}
				}
				else
				{
					num2++;
				}
				names.Add(value);
				values.Add(num2);
			}
		}
		catch
		{
		}
		return true;
	}

	public static string GetGvReplacedValue(Scheduler scheduler, string value)
	{
		string text = value;
		if (text.Contains("{") && text.Contains("}"))
		{
			Hashtable copyOfGlobals = GetCopyOfGlobals(scheduler.RootFolder);
			foreach (string key in copyOfGlobals.Keys)
			{
				if (text.ToUpper().Contains("{" + key.ToUpper() + "}"))
				{
					scheduler.Env.GlobalVariable.GetGlobalVariable(key, out var gvValue);
					text = ReplaceEx(text, "{" + key + "}", gvValue);
				}
			}
		}
		return text;
	}

	public object GetParameterObject(Scheduler scheduler)
	{
		try
		{
			object[,] array = new object[base.List.Count, 11];
			int num = 0;
			foreach (ParameterCls item in base.List)
			{
				int num2 = item.NoOfElements;
				if (item.Value != null && item.NoOfElements > 1)
				{
					num2 = item.Value.Split(',').Length;
				}
				array[num, 0] = item.Name;
				string gvReplacedValue = GetGvReplacedValue(scheduler, item.Value);
				array[num, 1] = gvReplacedValue;
				if (item.IsParamDataTable())
				{
					array[num, 1] = item.DataTableValue;
				}
				array[num, 2] = item.LowerLimit;
				array[num, 3] = item.UpperLimit;
				array[num, 4] = num2;
				array[num, 5] = item.IOTypeAsString;
				array[num, 6] = item.Unit;
				array[num, 7] = item.Description;
				array[num, 8] = item.DataTypeAsString;
				array[num, 9] = item.Selected;
				array[num, 10] = item.RealName;
				num++;
			}
			return array;
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "GetParameterObject " + ex.ToString(), TraceMessageType.Exception);
			return null;
		}
	}

	private static Hashtable GetCopyOfGlobals(RootTest root)
	{
		Hashtable result = new Hashtable();
		bool flag = true;
		while (flag)
		{
			try
			{
				result = new Hashtable(QTMGlobalVariable.GetGVariablesById(root.Scheduler.Env.SchedulerID));
				flag = false;
			}
			catch (InvalidOperationException)
			{
				flag = true;
				Thread.Sleep(10);
			}
		}
		return result;
	}

	public object GetParameterObjectInputFormat()
	{
		try
		{
			object[,] array = new object[19, base.List.Count];
			int num = 0;
			foreach (ParameterCls item in base.List)
			{
				array[0, num] = item.Name;
				array[1, num] = item.DataTypeAsString;
				array[2, num] = item.NoOfElements;
				if (item.IsParamDataTable())
				{
					array[3, num] = item.DataTableValue;
				}
				else
				{
					array[3, num] = item.Value;
				}
				array[4, num] = item.IOTypeAsString;
				array[5, num] = item.UpperLimit;
				array[6, num] = item.LowerLimit;
				array[7, num] = item.Unit;
				array[8, num] = item.Description;
				array[9, num] = item.Constraints;
				array[10, num] = item.DisplayHint;
				array[11, num] = true;
				array[12, num] = item.Selected;
				array[13, num] = item.IsNullable;
				array[14, num] = item.ParentName;
				array[15, num] = item.IsDynamicArray;
				array[16, num] = item.IsEditableInTestPlan;
				array[17, num] = item.CanEditResultValue;
				array[18, num] = item.RealName;
				num++;
			}
			return array;
		}
		catch
		{
			return null;
		}
	}

	public ParameterCls GetParameter(string paramName)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (string.Compare(item.Name, paramName, ignoreCase: true) == 0)
				{
					return item;
				}
			}
		}
		catch
		{
		}
		return null;
	}

	public bool HasParameter(string paramName)
	{
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name == paramName)
				{
					return true;
				}
			}
		}
		catch
		{
		}
		return false;
	}

	public bool HasParameter(string paramName, bool exactMatch, out string matchedParamName)
	{
		matchedParamName = "";
		try
		{
			foreach (ParameterCls item in base.List)
			{
				if (item.Name.ToUpper().Contains(paramName.ToUpper()))
				{
					matchedParamName = item.Name;
					if (!exactMatch)
					{
						return true;
					}
					if (item.Name == paramName)
					{
						return true;
					}
				}
			}
		}
		catch
		{
		}
		return false;
	}

	public int Add(ParameterCls value)
	{
		if (ClearOnAdd)
		{
			Clear();
			ClearOnAdd = false;
		}
		return base.List.Add(value);
	}

	public void AddRange(ParameterCls[] value)
	{
		try
		{
			if (value != null && value.Length > 0)
			{
				foreach (ParameterCls value2 in value)
				{
					Add(value2);
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "AddRange " + ex.Message, TraceMessageType.Exception);
		}
	}

	public bool Contains(ParameterCls value)
	{
		return base.List.Contains(value);
	}

	public void CopyTo(ParameterCls[] array, int index)
	{
		base.List.CopyTo(array, index);
	}

	public int IndexOf(ParameterCls value)
	{
		return base.List.IndexOf(value);
	}

	public void Insert(int index, ParameterCls value)
	{
		base.List.Insert(index, value);
	}

	public void Remove(ParameterCls value)
	{
		base.List.Remove(value);
	}

	public string GetClassName()
	{
		return TypeDescriptor.GetClassName(this, noCustomTypeDesc: true);
	}

	public AttributeCollection GetAttributes()
	{
		return TypeDescriptor.GetAttributes(this, noCustomTypeDesc: true);
	}

	public string GetComponentName()
	{
		return TypeDescriptor.GetComponentName(this, noCustomTypeDesc: true);
	}

	public TypeConverter GetConverter()
	{
		return TypeDescriptor.GetConverter(this, noCustomTypeDesc: true);
	}

	public EventDescriptor GetDefaultEvent()
	{
		return TypeDescriptor.GetDefaultEvent(this, noCustomTypeDesc: true);
	}

	public PropertyDescriptor GetDefaultProperty()
	{
		return TypeDescriptor.GetDefaultProperty(this, noCustomTypeDesc: true);
	}

	public object GetEditor(Type editorBaseType)
	{
		return TypeDescriptor.GetEditor(this, editorBaseType, noCustomTypeDesc: true);
	}

	public EventDescriptorCollection GetEvents(Attribute[] attributes)
	{
		return TypeDescriptor.GetEvents(this, attributes, noCustomTypeDesc: true);
	}

	public EventDescriptorCollection GetEvents()
	{
		return TypeDescriptor.GetEvents(this, noCustomTypeDesc: true);
	}

	public object GetPropertyOwner(PropertyDescriptor pd)
	{
		return this;
	}

	public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
	{
		return GetProperties();
	}

	public PropertyDescriptorCollection GetProperties()
	{
		PropertyDescriptorCollection propertyDescriptorCollection = new PropertyDescriptorCollection(null);
		bool flag = false;
		for (int i = 0; i < base.Count; i++)
		{
			if (this[i].ParentName == string.Empty)
			{
				flag = true;
			}
		}
		for (int j = 0; j < base.List.Count; j++)
		{
			ParamCollectionPropertyDescriptor value = new ParamCollectionPropertyDescriptor(this, j);
			if ((flag && string.IsNullOrEmpty(this[j].ParentName)) || (!flag && !string.IsNullOrEmpty(this[j].ParentName)))
			{
				propertyDescriptorCollection.Add(value);
			}
		}
		return propertyDescriptorCollection;
	}

	internal void SetTreeSaving(bool saving)
	{
		foreach (ParameterCls item in base.List)
		{
			item.SavingTree = saving;
		}
	}
}
