using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.Serialization;
using System.Threading;
using System.Timers;
using System.Windows;
using System.Windows.Forms;
using System.Xml.Serialization;
using QC.GlobalVariableManager;
using QC.QsprShared.Config;
using QC.QsprShared.Dialogs;
using QC.QsprShared.GlobalData;
using QC.QsprShared.Trace;
using QC.QsprTestObjects.Loops;
using QC.QsprTestObjects.Metadata;
using QC.QsprTestObjects.Parameters;
using QC.QsprTestObjects.TestConditions;
using QC.QsprTestObjects.Tests.DotNet;
using QC.QsprTestObjects.Tests.Hive;
using QC.QsprTestObjects.Tests.LabVIEW;
using QC.QsprTestObjects.Tests.Script;
using QC.QsprTestObjects.Tests.TestCase;
using QC.QTMDotNetKernelInterface.Environment;
using QC.QTMInterface;
using QC.QTMSecurity;

namespace QC.QsprTestObjects.Tests.Base;

[Serializable]
public class FolderTest : BaseTest, ISerializable
{
	public const string FOLDER = "Folder";

	private ObservableCollection<BaseTest> testCollection = new ObservableCollection<BaseTest>();

	private FolderTestProperties folderProperties = new FolderTestProperties();

	private System.Timers.Timer abortTimer;

	private bool abortFolder;

	private bool treeSaving;

	[XmlIgnore]
	public bool AbortFolder
	{
		get
		{
			return abortFolder;
		}
		set
		{
			abortFolder = value;
		}
	}

	[XmlIgnore]
	public override bool TreeSaving
	{
		get
		{
			return treeSaving;
		}
		set
		{
			if (treeSaving == value)
			{
				return;
			}
			treeSaving = value;
			foreach (BaseTest test in TestList)
			{
				test.TreeSaving = treeSaving;
			}
		}
	}

	[XmlIgnore]
	public override RootTest Root
	{
		get
		{
			return root;
		}
		set
		{
			if (root == value)
			{
				return;
			}
			root = value;
			if (FolderProperties.Scenarios != null && FolderProperties.Scenarios.Count > 0 && FolderProperties.Scenarios.Condition != null)
			{
				foreach (BaseCondition condition in FolderProperties.Scenarios.Condition.Conditions)
				{
					condition.root = Root;
				}
			}
			if (FolderProperties.PreCondition != null && FolderProperties.PreCondition.Conditions != null)
			{
				foreach (BaseCondition condition2 in FolderProperties.PreCondition.Conditions)
				{
					condition2.root = Root;
				}
			}
			if (FolderProperties.PostCondition != null && FolderProperties.PostCondition.Conditions != null)
			{
				foreach (BaseCondition condition3 in FolderProperties.PostCondition.Conditions)
				{
					condition3.root = Root;
				}
			}
			foreach (BaseTest test in TestList)
			{
				test.Root = root;
			}
		}
	}

	[Browsable(false)]
	[XmlAttribute("NodeType")]
	public override string NodeType
	{
		get
		{
			return "Folder";
		}
		set
		{
			base.NodeType = value;
		}
	}

	public virtual FolderTestProperties FolderProperties
	{
		get
		{
			return folderProperties;
		}
		set
		{
			folderProperties = value;
		}
	}

	[XmlElement(Type = typeof(HiveTest))]
	[XmlElement(Type = typeof(TestCaseTest))]
	[XmlElement(Type = typeof(FolderTest))]
	[XmlElement(Type = typeof(BaseTest))]
	[XmlElement(Type = typeof(ScriptTest))]
	[XmlElement(Type = typeof(LabVIEWTest))]
	[XmlElement(Type = typeof(DotNetTestEx))]
	[XmlElement(Type = typeof(DotNetTest))]
	public ObservableCollection<BaseTest> TestList
	{
		get
		{
			return testCollection;
		}
		set
		{
			testCollection = value;
		}
	}

	[Browsable(false)]
	[XmlIgnore]
	public List<BaseTest> SelectedTests
	{
		get
		{
			List<BaseTest> list = new List<BaseTest>();
			if (Properties.IsSelected)
			{
				list.Add(this);
			}
			foreach (BaseTest test in TestList)
			{
				if (test is FolderTest)
				{
					list.AddRange(((FolderTest)test).SelectedTests);
				}
				else if (test.Properties.IsSelected)
				{
					list.Add(test);
				}
			}
			return list;
		}
	}

	public override string Index
	{
		get
		{
			return base.Index;
		}
		set
		{
			try
			{
				if (FolderProperties.Scenarios != null)
				{
					foreach (LoopCondition loopCondition in FolderProperties.Scenarios.LoopConditions)
					{
						FindTest(loopCondition.TestIndex)?.Properties.RenameLoopLink(index, value);
					}
				}
				base.Index = value;
			}
			catch (Exception ex)
			{
				TraceMessage.Write(ToString(), "Index " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
			}
		}
	}

	[XmlIgnore]
	public override TestProperties Properties
	{
		get
		{
			folderProperties.Owner = this;
			return folderProperties;
		}
		set
		{
			folderProperties.Owner = this;
			folderProperties = (FolderTestProperties)value;
		}
	}

	public void SetReadOnly(bool isReadOnly)
	{
		bool flag = isReadOnly;
		if (folderProperties.LinkRoot && Properties.IsLinkActive == true)
		{
			base.TestUserInterfaceProperties.IsReadOnly = isReadOnly;
			flag = true;
		}
		else
		{
			bool? isLinkActive = Properties.IsLinkActive;
			if (isLinkActive.GetValueOrDefault() && isLinkActive.HasValue && Properties.LinkNode && !folderProperties.LinkRoot)
			{
				base.TestUserInterfaceProperties.IsReadOnly = true;
				flag = true;
			}
			else
			{
				base.TestUserInterfaceProperties.IsReadOnly = isReadOnly;
			}
		}
		foreach (BaseTest test in TestList)
		{
			if (test is FolderTest)
			{
				(test as FolderTest).SetReadOnly(flag);
			}
			else
			{
				test.TestUserInterfaceProperties.IsReadOnly = flag;
			}
		}
	}

	public override bool IsValidTestCase()
	{
		bool result = false;
		if (TestList.Count == 2)
		{
			return false;
		}
		if (TestList.Count > 1)
		{
			if (TestList[0].Properties.IsSetupTestStep && TestList[TestList.Count - 1].Properties.IsTearDownTestStep)
			{
				result = true;
			}
		}
		else
		{
			result = true;
		}
		return result;
	}

	public FolderTest()
	{
	}

	public FolderTest(string name)
		: base(name)
	{
		folderProperties = new FolderTestProperties();
		folderProperties.RealName = "Folder";
		folderProperties.TestName = name;
		folderProperties.StopOnError = StopOnErrorTypes.None;
	}

	public FolderTest Copy(FolderTest folder)
	{
		for (int i = 0; i < testCollection.Count; i++)
		{
			BaseTest baseTest = testCollection[i];
			folder.Add(baseTest.Clone());
		}
		base.Copy(folder);
		return this;
	}

	public TestCaseTest AsTestCaseTest()
	{
		TestCaseTest testCaseTest = new TestCaseTest();
		testCaseTest.Root = Root;
		for (int i = 0; i < testCollection.Count; i++)
		{
			BaseTest baseTest = testCollection[i];
			testCaseTest.Add(baseTest.Clone());
		}
		return testCaseTest;
	}

	public BaseTest FindTest(string testIndex)
	{
		try
		{
			if (Index == testIndex)
			{
				return this;
			}
			foreach (BaseTest test in TestList)
			{
				if (test.Index == testIndex)
				{
					return test;
				}
				if (test is FolderTest)
				{
					FolderTest folderTest = (FolderTest)test;
					BaseTest baseTest = folderTest.FindTest(testIndex);
					if (baseTest != null)
					{
						return baseTest;
					}
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "FindTest " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
		return null;
	}

	public BaseTest FindTestWithOrigIndex(string originalIndex)
	{
		try
		{
			if (OriginalIndex == originalIndex)
			{
				return this;
			}
			foreach (BaseTest test in TestList)
			{
				if (test.OriginalIndex == originalIndex)
				{
					return test;
				}
				if (test is FolderTest)
				{
					FolderTest folderTest = (FolderTest)test;
					BaseTest baseTest = folderTest.FindTestWithOrigIndex(originalIndex);
					if (baseTest != null)
					{
						return baseTest;
					}
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "FindTestWithOrigIndex " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
		return null;
	}

	public BaseTest FindTestWithParameter(string paramName)
	{
		try
		{
			foreach (BaseTest test in TestList)
			{
				if (test.Properties.Parameters.FindParam(paramName) != null)
				{
					return test;
				}
				if (test is FolderTest)
				{
					FolderTest folderTest = (FolderTest)test;
					BaseTest baseTest = folderTest.FindTestWithParameter(paramName);
					if (baseTest != null)
					{
						return baseTest;
					}
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "FindTest " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
		return null;
	}

	public List<BaseTest> FindAllTestWithParameter(string paramName)
	{
		List<BaseTest> list = new List<BaseTest>();
		try
		{
			foreach (BaseTest test in TestList)
			{
				if (test.Properties.Parameters.FindParam(paramName) != null)
				{
					list.Add(test);
				}
				if (test is FolderTest)
				{
					FolderTest folderTest = (FolderTest)test;
					List<BaseTest> list2 = folderTest.FindAllTestWithParameter(paramName);
					if (list2.Count > 0)
					{
						list.AddRange(list2);
					}
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "FindTest " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
		return list;
	}

	public BaseTest FindTestFromRealName(string strTest, bool isPartialName)
	{
		try
		{
			foreach (BaseTest test in TestList)
			{
				if (!isPartialName)
				{
					if (test.Properties.RealName.ToUpper() == strTest.ToUpper())
					{
						return test;
					}
				}
				else if (test.Properties.RealName.ToUpper().IndexOf(strTest.ToUpper()) != -1)
				{
					return test;
				}
				if (test is FolderTest)
				{
					FolderTest folderTest = (FolderTest)test;
					BaseTest baseTest = folderTest.FindTestFromRealName(strTest, isPartialName);
					if (baseTest != null)
					{
						return baseTest;
					}
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "FindTest " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
		return null;
	}

	public BaseTest FindTestFromTestName(string strTest, bool isPartialName)
	{
		return FindTestFromTestName(strTest, isPartialName, null);
	}

	public BaseTest FindTestFromTestName(string strTest, bool isPartialName, string startingNodeIndex)
	{
		return FindTestByTestName(strTest, isPartialName, ref startingNodeIndex);
	}

	private bool TestNameContainsPath(string testName)
	{
		if (testName.Contains("|"))
		{
			return true;
		}
		return false;
	}

	private BaseTest FindTestByTestName(string strTest, bool isPartialName, ref string startingNodeIndex)
	{
		try
		{
			bool flag = true;
			if (startingNodeIndex != null)
			{
				flag = false;
			}
			foreach (BaseTest test in TestList)
			{
				if (flag)
				{
					if (!isPartialName)
					{
						if (TestNameContainsPath(strTest))
						{
							if (test.UniqueTestPathWithoutIndex.ToUpper().EndsWith(strTest.ToUpper()))
							{
								return test;
							}
						}
						else if (test.Properties.TestName.ToUpper() == strTest.ToUpper())
						{
							return test;
						}
					}
					else if (TestNameContainsPath(strTest))
					{
						if (!strTest.EndsWith("|"))
						{
							string text = strTest.Substring(0, strTest.LastIndexOf('|'));
							strTest.Substring(strTest.LastIndexOf('|') + 1);
							if (test.Parent.UniqueTestPathWithoutIndex.ToUpper().EndsWith(text.ToUpper()) && test.Properties.TestName.ToUpper().Contains(strTest.ToUpper()))
							{
								return test;
							}
						}
					}
					else if (test.Properties.TestName.ToUpper().IndexOf(strTest.ToUpper()) != -1)
					{
						return test;
					}
				}
				if (test.Index == startingNodeIndex)
				{
					flag = true;
					startingNodeIndex = null;
				}
				if (test is FolderTest)
				{
					FolderTest folderTest = (FolderTest)test;
					BaseTest baseTest = folderTest.FindTestByTestName(strTest, isPartialName, ref startingNodeIndex);
					if (startingNodeIndex == null)
					{
						flag = true;
					}
					if (baseTest != null)
					{
						return baseTest;
					}
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "FindTest " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
		return null;
	}

	public BaseTest FindTestFromFullPath(string strTest, bool isPartialName)
	{
		try
		{
			foreach (BaseTest test in TestList)
			{
				string[] array = test.TestPath.Split('.');
				string text = test.TestPath.Replace("." + array[array.Length - 1], "");
				if (!isPartialName)
				{
					if (text.ToUpper() == strTest.ToUpper())
					{
						return test;
					}
				}
				else if (text.ToUpper().IndexOf(strTest.ToUpper()) != -1)
				{
					return test;
				}
				if (test is FolderTest)
				{
					FolderTest folderTest = (FolderTest)test;
					BaseTest baseTest = folderTest.FindTestFromFullPath(strTest, isPartialName);
					if (baseTest != null)
					{
						return baseTest;
					}
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "FindTest " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
		return null;
	}

	public void FindAllLinkedFolders(FolderTest currFolder, ref ArrayList linkedFolders)
	{
		try
		{
			foreach (BaseTest test in currFolder.TestList)
			{
				if (test is FolderTest)
				{
					FolderTest folderTest = (FolderTest)test;
					if (folderTest.FolderProperties.LinkRoot)
					{
						linkedFolders.Add(folderTest);
					}
					else if (!folderTest.FolderProperties.LinkRoot && !string.IsNullOrEmpty(folderTest.FolderProperties.LinkLocation))
					{
						linkedFolders.Add(folderTest);
					}
					else
					{
						FindAllLinkedFolders(folderTest, ref linkedFolders);
					}
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "FindAllLinkedFolders " + ex.Message, TraceMessageType.Exception);
		}
	}

	public override void RemoveRegistrationInformation()
	{
		foreach (BaseTest test in TestList)
		{
			test.RemoveRegistrationInformation();
		}
		folderProperties.NodeRID = -1L;
	}

	public void SetTestDescriptionName(string strDescription)
	{
		if (!(strDescription.Trim() != ""))
		{
			return;
		}
		string[] array = strDescription.Split(",".ToCharArray()[0]);
		int num = 0;
		foreach (BaseTest test in TestList)
		{
			if (num >= array.Length)
			{
				test.Properties.DescriptionName = "";
				num++;
			}
			else if (test is FolderTest)
			{
				string text = "";
				for (int i = num + 1; i < array.Length; i++)
				{
					text = ((i != num + 1) ? (text + "," + array[i].Trim()) : array[i].Trim());
				}
				if (text.Trim().Length > 0)
				{
					((FolderTest)test).SetTestDescriptionName(text);
				}
				num += test.Properties.NumberOfTests;
			}
			else
			{
				if (array[num].Trim() == "")
				{
					test.Properties.DescriptionName = "";
				}
				else
				{
					test.Properties.DescriptionName = array[num].Trim();
				}
				num++;
			}
		}
	}

	public override void Add(BaseTest baseTest)
	{
		TraceMessage.Write(ToString(), "Add " + baseTest.Properties.TestName, TraceMessageType.Trace);
		try
		{
			testCollection.Add(baseTest);
			baseTest.Parent = this;
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "Add " + baseTest.Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void AddDummyTest(BaseTest baseTest)
	{
		TraceMessage.Write(ToString(), "AddDummyTest " + baseTest.Properties.TestName, TraceMessageType.Trace);
		try
		{
			testCollection.Add(baseTest);
			Root = baseTest.Root;
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "AddDummyTest " + baseTest.Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
	}

	public override void Insert(BaseTest baseTest, int index)
	{
		TraceMessage.Write(ToString(), "Insert " + baseTest.Properties.TestName, TraceMessageType.Trace);
		try
		{
			testCollection.Insert(index, baseTest);
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "Insert " + baseTest.Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
	}

	public override void Remove(BaseTest baseTest)
	{
		TraceMessage.Write(ToString(), "Remove " + baseTest.Properties.TestName, TraceMessageType.Trace);
		try
		{
			RemoveLoopLinksFromParents(baseTest);
			testCollection.Remove(baseTest);
			if (testCollection.Count == 0)
			{
				folderProperties.Scenarios = null;
			}
			baseTest.Parent = null;
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "Remove " + baseTest.Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
	}

	public override void StopQTMTest()
	{
		TraceMessage.Write(ToString(), "ENTER: FolderTest.StopQTMTest(" + Properties.TestName + ")", TraceMessageType.Trace);
		runtimeAttributes.StopLoop = true;
		TraceMessage.Write(ToString(), "EXIT: FolderTest.StopQTMTest(" + Properties.TestName + ")", TraceMessageType.Trace);
	}

	private bool RemoveLoopLinksFromParents(BaseTest baseTest)
	{
		try
		{
			if (baseTest is FolderTest)
			{
				foreach (BaseTest test in ((FolderTest)baseTest).TestList)
				{
					RemoveLoopLinksFromParents(test);
				}
			}
			else
			{
				foreach (string loopLink in baseTest.Properties.LoopLinks)
				{
					baseTest.FindLoopParent(loopLink)?.RemoveLoopTests(baseTest.Index);
				}
			}
			return true;
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "RemoveLoopLinksFromParents " + ex.Message, TraceMessageType.Exception);
		}
		return false;
	}

	public override void Clear()
	{
		TraceMessage.Write(ToString(), "Clear " + Properties.TestName, TraceMessageType.Trace);
		try
		{
			testCollection.Clear();
			base.Clear();
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "Clear " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
	}

	public override void RunQTMTest(string testName, string containerName, ref object objParameters, ref object objProperties)
	{
	}

	public override void CreateParent(FolderTest pTest)
	{
		try
		{
			foreach (BaseTest test in TestList)
			{
				test.CreateParent(this);
			}
			base.CreateParent(pTest);
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "CreateParent " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
	}

	public override int GetSetNumberOfTests()
	{
		int num = 1;
		foreach (BaseTest test in TestList)
		{
			num += test.GetSetNumberOfTests();
		}
		Properties.NumberOfTests = num;
		return Properties.NumberOfTests;
	}

	public void GetSelectedManualTests(ref List<TestCaseTest> tests)
	{
		if (Properties.CheckStateTest == CheckState.Unchecked)
		{
			return;
		}
		if (this is TestCaseTest && ((TestCaseTest)this).TestCaseProperties.Type == TestCaseTypes.Manual)
		{
			tests.Add((TestCaseTest)this);
		}
		foreach (BaseTest test in TestList)
		{
			if (test is FolderTest)
			{
				((FolderTest)test).GetSelectedManualTests(ref tests);
			}
		}
	}

	public override void GetSelectedTestCasesCount(ref int count)
	{
		if (Properties.CheckStateTest == CheckState.Unchecked)
		{
			return;
		}
		foreach (BaseTest test in TestList)
		{
			if (test is TestCaseTest && test.Properties.CheckStateTest != 0)
			{
				count++;
			}
			if (test is FolderTest)
			{
				test.GetSelectedTestCasesCount(ref count);
			}
			else
			{
				test.GetSelectedTestCasesCount(ref count);
			}
		}
	}

	public override void GetSelectedTestCount(ref int count)
	{
		if (Properties.CheckStateTest == CheckState.Unchecked)
		{
			return;
		}
		foreach (BaseTest test in TestList)
		{
			if (test is FolderTest)
			{
				test.GetSelectedTestCount(ref count);
			}
			else
			{
				test.GetSelectedTestCount(ref count);
			}
		}
	}

	public override void GetSelectedTests(ref ArrayList testNames, ref ArrayList nodeNames)
	{
		if (Properties.CheckStateTest == CheckState.Unchecked)
		{
			return;
		}
		testNames.Add(Properties.TestName);
		nodeNames.Add(Properties.RealName);
		foreach (BaseTest test in TestList)
		{
			if (test is FolderTest)
			{
				test.GetSelectedTests(ref testNames, ref nodeNames);
			}
			else
			{
				test.GetSelectedTests(ref testNames, ref nodeNames);
			}
		}
	}

	public override int QueueTestCount(int depth, ArrayList list)
	{
		int num = 0;
		try
		{
			if (Properties.CheckStateTest != 0 || depth == 1)
			{
				foreach (BaseTest test in TestList)
				{
					if (!Root.Scheduler.IsInRerunMode || FolderProperties.IsSetupFolder || FolderProperties.IsCleanupFolder || Root.Scheduler.GetFailedTests().Contains(test))
					{
						if (test is FolderTest && !test.RuntimeAttributes.Tool)
						{
							test.RuntimeAttributes.Tool = RuntimeAttributes.Tool;
						}
						num += test.QueueTestCount(depth + 1, list);
					}
				}
				LoopScenarioValues scenarios = FolderProperties.Scenarios;
				if (scenarios != null && !FolderProperties.DisableLooping)
				{
					if (((LoopCondition)scenarios.LoopConditions[0]).LoopType == QC.QsprTestObjects.Loops.LoopTypes.BYCOUNT)
					{
						if ((bool)scenarios.ConditionCheck[0])
						{
							if (((LoopCondition)scenarios.LoopConditions[0]).LoopValues[0].ToString() == "Loop Forever")
							{
								return num;
							}
							num *= int.Parse(((LoopCondition)scenarios.LoopConditions[0]).LoopValues[0].ToString());
						}
						else
						{
							num = 0;
						}
					}
					else
					{
						int num2 = 0;
						foreach (bool item in scenarios.ConditionCheck)
						{
							if (item)
							{
								num2++;
							}
						}
						num *= num2;
					}
				}
				if (num > 0 && depth != 0)
				{
					MsgData msgData = default(MsgData);
					msgData.msgType = TestMsgType.OnEnqueueTest;
					msgData.TestFullPath = base.TestPath;
					msgData.TestIndex = Index;
					list.Add(msgData);
				}
				else if (num > 0 && depth == 0 && !Root.Scheduler.GlobalStatus.Stop)
				{
					TestMessage message = default(TestMessage);
					message.Message = base.TestPath;
					message.NodeRID = Properties.NodeRID;
					message.Object = list;
					message.Result = TestResult.Passed;
					message.TestIndex = Index;
					base.msgDelegate(TestMsgType.OnEnqueueTest, message);
				}
				if (num == 0)
				{
					RemovesTestsFromQueue(list);
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "QueueTests " + ex.Message, TraceMessageType.Exception);
		}
		return num;
	}

	private void RemovesTestsFromQueue(ArrayList list)
	{
		foreach (BaseTest test in TestList)
		{
			if (test is FolderTest)
			{
				((FolderTest)test).RemovesTestsFromQueue(list);
			}
			int num = -1;
			foreach (MsgData item in list)
			{
				if (item.TestIndex == test.Index)
				{
					num = list.IndexOf(item);
				}
			}
			if (num > -1)
			{
				list.RemoveAt(num);
			}
		}
	}

	public override BaseTest Clone()
	{
		TraceMessage.Write(ToString(), "Clone " + Properties.TestName, TraceMessageType.Trace);
		FolderTest folderTest = new FolderTest();
		folderTest.Root = Root;
		try
		{
			folderTest.name = RealName;
			folderTest.index = index;
			folderTest.Properties = Properties.Clone();
			base.Copy(folderTest);
			for (int i = 0; i < testCollection.Count; i++)
			{
				BaseTest baseTest = testCollection[i];
				folderTest.Add(baseTest.Clone());
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "Clone " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
		return folderTest;
	}

	public override bool CanTestRun(TestRuntimeAttributes folderAttributes)
	{
		TraceMessage.Write(ToString(), "ENTER: FolderTest.CanTestRun(" + Properties.TestName + ")", TraceMessageType.Trace);
		TraceMessage.Write(ToString(), "CanTestRun " + Properties.TestName, TraceMessageType.Trace);
		bool flag = false;
		bool flag2 = false;
		try
		{
			if (!FolderProperties.IsSetupFolder && !folderProperties.IsCleanupFolder && Root.Scheduler.IsInRerunMode && !ShouldRerun())
			{
				return false;
			}
			if (preRequisiteFailed && !Root.Scheduler.IsInRerunMode)
			{
				if (FolderProperties.CheckStateTest == CheckState.Checked)
				{
					ArrayList arrayList = new ArrayList();
					MsgData msgData = default(MsgData);
					msgData.TestFullPath = base.TestPath;
					msgData.TestIndex = Index;
					msgData.msgType = TestMsgType.OnTestResult;
					arrayList.Add(msgData);
					TestMessage message = default(TestMessage);
					message.Message = base.TestPath;
					message.Message = Properties.TestName;
					message.NodeRID = Properties.NodeRID;
					message.Object = arrayList;
					message.Result = TestResult.Failed;
					message.ResultDetails.ErrDescription = "Prerequisite Tests Failed.";
					message.TestIndex = Index;
					string gvValue = "";
					QTMGlobalVariable.GetGlobalVariable("SN", out gvValue);
					message.SerialNumber = gvValue;
					RuntimeAttributes.TestStartTime = DateTime.Now;
					RuntimeAttributes.TestStopTime = DateTime.Now;
					base.msgDelegate(TestMsgType.OnTestSkipped, message);
					Root.Scheduler.AddFailedTest(this);
				}
				return false;
			}
			if (preRequisiteFailed && Root.Scheduler.IsInRerunMode && Root.Scheduler.ContainsFailedTests(this))
			{
				ArrayList arrayList2 = new ArrayList();
				MsgData msgData2 = default(MsgData);
				msgData2.TestFullPath = base.TestPath;
				msgData2.TestIndex = Index;
				msgData2.msgType = TestMsgType.OnTestResult;
				arrayList2.Add(msgData2);
				TestMessage message2 = default(TestMessage);
				message2.Message = base.TestPath;
				message2.Message = Properties.TestName;
				message2.NodeRID = Properties.NodeRID;
				message2.Object = arrayList2;
				message2.Result = TestResult.Failed;
				message2.ResultDetails.ErrDescription = "Prerequisite Tests Failed.";
				message2.TestIndex = Index;
				string gvValue2 = "";
				QTMGlobalVariable.GetGlobalVariable("SN", out gvValue2);
				message2.SerialNumber = gvValue2;
				RuntimeAttributes.TestStartTime = DateTime.Now;
				RuntimeAttributes.TestStopTime = DateTime.Now;
				base.msgDelegate(TestMsgType.OnTestSkipped, message2);
				Root.Scheduler.AddFailedTest(this);
				return false;
			}
			if (FolderProperties.MustRunTest)
			{
				FolderProperties.CheckStateTest = CheckState.Checked;
				Root.Scheduler.AddMustRunOnRerunTest(this);
				return true;
			}
			if (Properties.TreeMustRun && Properties.CheckStateTest == CheckState.Checked)
			{
				flag = true;
			}
			if (FolderProperties.PreRequisite)
			{
				if (CheckIfPreRequisiteNeedsToRun())
				{
					FolderProperties.CheckStateTest = CheckState.Checked;
					Root.Scheduler.AddPreRequisiteTest(this);
					return true;
				}
				ArrayList arrayList3 = new ArrayList();
				MsgData msgData3 = default(MsgData);
				msgData3.msgType = TestMsgType.OnTestSkipped;
				msgData3.TestFullPath = base.TestPath;
				msgData3.TestIndex = Index;
				arrayList3.Add(msgData3);
				TestMessage eMessage = default(TestMessage);
				eMessage.Message = base.TestPath;
				eMessage.NodeRID = Properties.NodeRID;
				eMessage.Object = arrayList3;
				eMessage.Result = TestResult.Skipped;
				eMessage.ResultDetails.ErrDescription = "No Dependent Test Selected For Execution, Skipping Prerequisite test.";
				eMessage.TestIndex = Index;
				eMessage.Message = Properties.TestName;
				string gvValue3 = "";
				QTMGlobalVariable.GetGlobalVariable("SN", out gvValue3);
				eMessage.SerialNumber = gvValue3;
				AddTestCaseDataIfApplicable(ref eMessage);
				RuntimeAttributes.TestStartTime = DateTime.Now;
				RuntimeAttributes.TestStopTime = DateTime.Now;
				base.msgDelegate(TestMsgType.OnTestSkipped, eMessage);
				return false;
			}
			if (Properties.CheckStateTest == CheckState.Checked || Properties.CheckStateTest == CheckState.Indeterminate)
			{
				RootTest rootTest = GetRootTest();
				bool alwaysPerformMustRunTests = rootTest.RootProperties.AlwaysPerformMustRunTests;
				bool flag3 = false;
				try
				{
					if (TestList != null && TestList.Count > 0 && TestList[0].Properties != null && !string.IsNullOrEmpty(TestList[0].Properties.TestName) && string.Compare(TestList[0].Properties.TestName, "TestPlanStartup", ignoreCase: true) == 0)
					{
						flag3 = true;
					}
				}
				catch
				{
				}
				if (flag3)
				{
					flag = true;
				}
				else if ((Root.Scheduler.GlobalStatus.Stop || abortFolder) && (!Properties.TreeMustRun || !alwaysPerformMustRunTests))
				{
					flag = false;
				}
				else if (folderAttributes.StopOnError > StopOnErrorTypes.None && folderAttributes.PostConditionAction != PostConditionActions.RestartTestTreeWithoutMustRuns)
				{
					if (Properties.TreeMustRun)
					{
						flag = true;
					}
					else if (Properties.FolderMustRun && folderAttributes.Failed)
					{
						flag = true;
					}
					else if (RuntimeAttributes.StopOnError == StopOnErrorTypes.PauseTestTree)
					{
						flag = true;
					}
					else if (ParentHasRetry(this))
					{
						flag = true;
					}
				}
				else if (Properties.ToolTest)
				{
					if (runtimeAttributes.RightClickTest)
					{
						flag = true;
					}
				}
				else if (folderAttributes.PostConditionAction != PostConditionActions.SkipTheFolder)
				{
					flag = true;
				}
			}
			else if (Properties.CheckStateTest == CheckState.Unchecked && folderAttributes.RightClickTest)
			{
				flag = true;
			}
			if (Properties.PreCondition != null && flag && Properties.PreCondition.IsConditionMet(new ParameterCollection(), TestResult.Passed))
			{
				flag = false;
				flag2 = true;
			}
			bool flag4 = false;
			string empty = string.Empty;
			if (this is TestCaseTest && (Root.Scheduler.GlobalStatus.SkipTCOnOpenIR || Root.Scheduler.GlobalStatus.SkipTCOnOpenSetupIssues || Root.Scheduler.GlobalStatus.SkipTCOnOpenAutomationIssues))
			{
				_ = Properties.CheckStateTest;
			}
			if (flag4 && !string.IsNullOrEmpty(empty))
			{
				flag = false;
				ArrayList arrayList4 = new ArrayList();
				MsgData msgData4 = default(MsgData);
				msgData4.msgType = TestMsgType.OnTestSkipped;
				msgData4.TestFullPath = base.TestPath;
				msgData4.TestIndex = Index;
				arrayList4.Add(msgData4);
				TestMessage eMessage2 = default(TestMessage);
				eMessage2.Message = base.TestPath;
				eMessage2.NodeRID = Properties.NodeRID;
				eMessage2.Object = arrayList4;
				eMessage2.Result = TestResult.Skipped;
				eMessage2.ResultDetails.ErrDescription = "OpenIssue";
				eMessage2.ResultDetails.Comments = empty;
				eMessage2.TestIndex = Index;
				eMessage2.Message = Properties.TestName;
				string gvValue4 = "";
				QTMGlobalVariable.GetGlobalVariable("SN", out gvValue4);
				eMessage2.SerialNumber = gvValue4;
				AddTestCaseDataIfApplicable(ref eMessage2);
				RuntimeAttributes.TestStartTime = DateTime.Now;
				RuntimeAttributes.TestStopTime = DateTime.Now;
				base.msgDelegate(TestMsgType.OnTestSkipped, eMessage2);
			}
			else if (this is TestCaseTest && !string.IsNullOrEmpty(((TestCaseTest)this).TestCaseProperties.BlockedCRNumber))
			{
				ArrayList arrayList5 = new ArrayList();
				MsgData msgData5 = default(MsgData);
				msgData5.msgType = TestMsgType.OnTestSkipped;
				msgData5.TestFullPath = base.TestPath;
				msgData5.TestIndex = Index;
				msgData5.SerialNumber = GetSerialNumbers();
				arrayList5.Add(msgData5);
				TestMessage message3 = default(TestMessage);
				message3.Message = base.TestPath;
				message3.NodeRID = Properties.NodeRID;
				message3.Object = arrayList5;
				message3.Result = TestResult.Passed;
				message3.TestIndex = Index;
				message3.SerialNumber = GetSerialNumbers();
				message3.ErrorCode = ((TestCaseTest)this).TestCaseProperties.BlockedCRNumber;
				RuntimeAttributes.TestStartTime = DateTime.Now;
				RuntimeAttributes.TestStopTime = DateTime.Now;
				base.msgDelegate(TestMsgType.OnTestSkipped, message3);
			}
			else if ((Properties.CheckStateTest == CheckState.Unchecked || CurrentResult == TestResult.Skipped) && (flag2 || Properties.PreCondition == null) && GetRootTest().RootProperties.LogSkippedResults)
			{
				ArrayList arrayList6 = new ArrayList();
				MsgData msgData6 = default(MsgData);
				msgData6.msgType = TestMsgType.OnTestSkipped;
				msgData6.TestFullPath = base.TestPath;
				msgData6.TestIndex = Index;
				arrayList6.Add(msgData6);
				TestMessage eMessage3 = default(TestMessage);
				eMessage3.Message = base.TestPath;
				eMessage3.NodeRID = Properties.NodeRID;
				eMessage3.Object = arrayList6;
				eMessage3.Result = TestResult.Skipped;
				if (Properties.CheckStateTest == CheckState.Unchecked)
				{
					eMessage3.ResultDetails.ErrDescription = "UnChecked";
				}
				eMessage3.TestIndex = Index;
				eMessage3.Message = Properties.TestName;
				string gvValue5 = "";
				Root.Scheduler.Env.GlobalVariable.GetGlobalVariable("SN", out gvValue5);
				eMessage3.SerialNumber = gvValue5;
				AddTestCaseDataIfApplicable(ref eMessage3);
				RuntimeAttributes.TestStartTime = DateTime.Now;
				RuntimeAttributes.TestStopTime = DateTime.Now;
				base.msgDelegate(TestMsgType.OnTestSkipped, eMessage3);
			}
			else if (!flag)
			{
				ArrayList arrayList7 = new ArrayList();
				MsgData msgData7 = default(MsgData);
				msgData7.msgType = TestMsgType.OnDequeueTest;
				msgData7.TestFullPath = base.TestPath;
				msgData7.TestIndex = Index;
				arrayList7.Add(msgData7);
				TestMessage message4 = default(TestMessage);
				message4.Message = base.TestPath;
				message4.NodeRID = Properties.NodeRID;
				message4.Object = arrayList7;
				message4.Result = TestResult.Passed;
				message4.TestIndex = Index;
				base.msgDelegate(TestMsgType.OnDequeueTest, message4);
			}
			if (flag && Properties.TreeMustRun && Properties.CheckStateTest == CheckState.Checked)
			{
				Root.Scheduler.AddMustRunOnRerunTest(this);
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "EXCEPTION: FolderTest.CanTestRun(" + Properties.TestName + ") " + ex.ToString(), TraceMessageType.Trace);
			TraceMessage.Write(ToString(), "CanTestRun  " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
		TraceMessage.Write(ToString(), "EXIT: FolderTest.CanTestRun(" + Properties.TestName + ") returning " + flag, TraceMessageType.Trace);
		return flag;
	}

	private bool CheckIfPreRequisiteNeedsToRun()
	{
		if (!Root.Scheduler.IsInRerunMode)
		{
			if (Parent.TestList != null && Parent.TestList.Count > 0)
			{
				foreach (BaseTest test in parent.TestList)
				{
					try
					{
						if (test != this && test.Properties.CheckStateTest != 0)
						{
							return true;
						}
					}
					catch
					{
					}
				}
			}
		}
		else if (Parent.TestList != null && Parent.TestList.Count > 0)
		{
			try
			{
				return CheckForFailedDependents(Parent);
			}
			catch
			{
			}
		}
		return false;
	}

	public bool CheckForFailedDependents(FolderTest folderTest)
	{
		if (folderTest.Properties.CheckStateTest != 0 && Root.Scheduler.ContainsFailedTests(folderTest))
		{
			return true;
		}
		return false;
	}

	private bool CheckIssueType(List<string> issues, string type)
	{
		foreach (string issue in issues)
		{
			if (issue.StartsWith(type, ignoreCase: true, CultureInfo.CurrentCulture))
			{
				return true;
			}
		}
		return false;
	}

	private string GetSoftwareProduct()
	{
		string gvValue = "";
		Root.Scheduler.Env.GlobalVariable.GetGlobalVariable("Reporting Product", out gvValue);
		return gvValue;
	}

	private string GetCSTVersion()
	{
		string gvValue = "";
		Root.Scheduler.Env.GlobalVariable.GetGlobalVariable("CSTFrameWorkVersion", out gvValue);
		return gvValue;
	}

	private string GetSerialNumbers()
	{
		string gvValue = "";
		Root.Scheduler.Env.GlobalVariable.GetGlobalVariable("SN", out gvValue);
		return gvValue;
	}

	public override bool SyncParameters(ArrayList failedList, bool includeDescription = false)
	{
		for (int i = 0; i < testCollection.Count; i++)
		{
			try
			{
				BaseTest baseTest = testCollection[i];
				if (!baseTest.SyncParameters(failedList, includeDescription))
				{
					return false;
				}
			}
			catch (Exception ex)
			{
				TraceMessage.Write(ToString(), "SyncParameters " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
				return false;
			}
		}
		return true;
	}

	public override bool ResetRetryCount()
	{
		for (int i = 0; i < testCollection.Count; i++)
		{
			try
			{
				BaseTest baseTest = testCollection[i];
				if (!baseTest.ResetRetryCount())
				{
					return false;
				}
			}
			catch (Exception ex)
			{
				TraceMessage.Write(ToString(), "ResetRetryCount " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
				return false;
			}
		}
		base.ResetRetryCount();
		return true;
	}

	public override bool ResetComment()
	{
		for (int i = 0; i < testCollection.Count; i++)
		{
			try
			{
				BaseTest baseTest = testCollection[i];
				if (!baseTest.ResetComment())
				{
					return false;
				}
			}
			catch (Exception ex)
			{
				TraceMessage.Write(ToString(), "ResetComment " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
				return false;
			}
		}
		base.ResetRetryCount();
		return true;
	}

	public bool UpdateBranchOnTestIndex(FolderTest rootFolder, RootTest treeRootFolder)
	{
		try
		{
			foreach (BaseTest test in TestList)
			{
				if (test.Properties.PostCondition != null && test.Properties.PostCondition.Action == PostConditionActions.Branch && test.Properties.PostCondition.BranchOnTestName != null)
				{
					if (test.Properties.PostCondition.BranchOnTestName.Length > 0)
					{
						if (test.Properties.PostCondition.BranchTestIndex == null || (test.Properties.PostCondition.BranchTestIndex != null && test.Properties.PostCondition.BranchTestIndex.Length == 0))
						{
							try
							{
								string branchOnTestName = test.Properties.PostCondition.BranchOnTestName;
								BaseTest baseTest = treeRootFolder.FindTestFromTestName(branchOnTestName, isPartialName: false);
								if (baseTest != null)
								{
									test.Properties.PostCondition.BranchTestIndex = baseTest.Index;
								}
								else
								{
									string text = "The test " + test.Properties.TestName + " has a branch to test " + branchOnTestName + " that is not found in the test tree ";
									AppMessageDialog.Show(text, DialogResult.OK, MessageDialogType.Exception);
									test.Properties.Comment += text;
								}
							}
							catch
							{
							}
						}
					}
					else if (test.Properties.StopOnError != 0)
					{
						test.Properties.PostCondition = null;
					}
					else
					{
						string text2 = "UpdateBranchOnTestIndex - BranchName not set for test " + test.Properties.TestName;
						AppMessageDialog.Show(text2, DialogResult.OK, MessageDialogType.Exception);
					}
				}
				if (test is FolderTest)
				{
					FolderTest folderTest = (FolderTest)test;
					folderTest.UpdateBranchOnTestIndex(rootFolder, treeRootFolder);
				}
			}
			return true;
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "UpdateBranchOnTestIndex " + ex.Message, TraceMessageType.Exception);
			return false;
		}
	}

	public override void OnPropChanged(PropertyValueChangedEventArgs e)
	{
		try
		{
			folderProperties.OnPropChanged(e);
			if (folderProperties.TestName != name)
			{
				name = folderProperties.TestName;
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "OnPropChanged " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
	}

	public override bool StartTest()
	{
		TraceMessage.Write(ToString(), "ENTER: FolderTest.StartTest(" + Properties.TestName + ")", TraceMessageType.Trace);
		if (this is TestCaseTest)
		{
			Root.Scheduler.GlobalStatus.TestCaseRunning = true;
		}
		UpdateLoopIterations();
		bool flag = FolderProperties.IsCleanupFolder && !Root.Scheduler.GlobalStatus.IsDebugMode;
		TraceMessage.Write(ToString(), "StartTest " + Properties.TestName, TraceMessageType.Trace);
		bool flag2 = true;
		bool flag3 = false;
		RuntimeAttributes.TestRan = true;
		RuntimeAttributes.TestStartTime = DateTime.Now;
		if (this is TestCaseTest)
		{
			Root.Scheduler.GlobalStatus.TestCaseRunning = true;
		}
		if (Properties.TestTimeOut > 0 && (Properties.TimeOutAction == TimeOutActions.Abort || Properties.TimeOutAction == TimeOutActions.AbortAndContinue))
		{
			abortTimer = new System.Timers.Timer(Properties.TestTimeOut * 1000);
			abortTimer.Elapsed += abortTimer_Elapsed;
			abortTimer.AutoReset = false;
			abortTimer.Enabled = true;
		}
		if (flag)
		{
			if (FolderProperties.IsLinkActive == true)
			{
				return false;
			}
			Root.Scheduler.EndOfUnitTesting(sentFromCleanup: true);
			bool flag4 = true;
			DateTime now = DateTime.Now;
			object gvValue;
			while (flag4 && !Root.Scheduler.GlobalStatus.Stop && Root.Scheduler.Env.GlobalVariable.GetGlobalVariableObject("XML4DB_WRITING", out gvValue))
			{
				double totalSeconds = (DateTime.Now - now).TotalSeconds;
				Root.Scheduler.Env.GlobalVariable.SetGlobalVariable("XML4DB_WAIT_TIMER", totalSeconds.ToString());
				if (totalSeconds >= (double)FolderProperties.WaitForLogTimeout)
				{
					break;
				}
				flag4 = Convert.ToBoolean(gvValue);
				QTMData.DoEvents();
				Thread.Sleep(10);
			}
		}
		try
		{
			FolderDetails folderDetails = default(FolderDetails);
			folderDetails.StartNewSheet = false;
			folderDetails.NumberOfTests = folderProperties.NumberOfTests;
			TestMessage eMessage = default(TestMessage);
			eMessage.Message = Properties.TestName;
			eMessage.NodeRID = Properties.NodeRID;
			eMessage.Object = folderDetails;
			eMessage.Result = TestResult.Passed;
			eMessage.TestIndex = Index;
			eMessage.IsLinkedRoot = FolderProperties.LinkRoot;
			string gvValue2 = "";
			Root.Scheduler.Env.GlobalVariable.GetGlobalVariable("SN", out gvValue2);
			eMessage.SerialNumber = gvValue2;
			AddTestCaseDataIfApplicable(ref eMessage);
			base.msgDelegate(TestMsgType.OnFolderStart, eMessage);
			Root.Scheduler.GlobalStatus.BranchOnTestIndex.Trim();
			if (Root.Scheduler.GlobalStatus.BranchOnError && Index.Trim() == Root.Scheduler.GlobalStatus.BranchOnTestIndex.Trim())
			{
				Root.Scheduler.GlobalStatus.BranchOnError = false;
				Root.Scheduler.GlobalStatus.BranchOnTestIndex = "";
				if (Properties.ToolTest)
				{
					RuntimeAttributes.Tool = true;
				}
			}
			if (FolderProperties.Scenarios != null && !Root.Scheduler.GlobalStatus.BranchOnError && !FolderProperties.DisableLooping && (IsMustRunFolder() || ((RuntimeAttributes.StopOnError == StopOnErrorTypes.None || RuntimeAttributes.StopOnError == StopOnErrorTypes.PauseTestTree) && (RuntimeAttributes.PostConditionAction == PostConditionActions.None || RuntimeAttributes.PostConditionAction == PostConditionActions.PauseTestTree))))
			{
				flag3 = true;
				flag2 = Root.Scheduler.LoopTest(this);
			}
			else
			{
				if (FolderProperties.LinkRoot)
				{
					Root.Scheduler.StartOfLinkedTesting(this);
				}
				flag2 = RunTestsOnce();
			}
		}
		catch (Exception ex)
		{
			if (FolderProperties.LinkRoot && !flag3)
			{
				Root.Scheduler.EndOfLinkedTesting(this, TestResult.Exception);
			}
			TraceMessage.Write(ToString(), "StartTest " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
			FolderDetails folderDetails2 = default(FolderDetails);
			folderDetails2.NumberOfTests = folderProperties.NumberOfTests;
			if (flag3)
			{
				folderDetails2.isLoopFolder = true;
			}
			TestMessage tMessage = default(TestMessage);
			tMessage.Message = Properties.TestName;
			tMessage.NodeRID = Properties.NodeRID;
			tMessage.Object = folderDetails2;
			tMessage.Result = TestResult.Exception;
			tMessage.TestIndex = Index;
			tMessage.IsLinkedRoot = FolderProperties.LinkRoot;
			string gvValue3 = "";
			Root.Scheduler.Env.GlobalVariable.GetGlobalVariable("CURRENT_UNIT_INDEX", out gvValue3);
			int result = 0;
			int.TryParse(gvValue3, out result);
			tMessage.UnitIndex = result;
			string gvValue4 = "";
			Root.Scheduler.Env.GlobalVariable.GetGlobalVariable("SN", out gvValue4);
			tMessage.SerialNumber = gvValue4;
			SetStartAndStopTimes(ref tMessage);
			base.msgDelegate(TestMsgType.OnFolderEnd, tMessage);
			return false;
		}
		if (abortTimer != null)
		{
			abortTimer.Enabled = false;
			abortTimer.Elapsed -= abortTimer_Elapsed;
			abortTimer = null;
		}
		AbortFolder = false;
		string text = string.Empty;
		TestResult testResult = TestResult.Failed;
		if (RuntimeAttributes.Exception)
		{
			testResult = TestResult.Exception;
		}
		else if (RuntimeAttributes.Failed)
		{
			testResult = TestResult.Failed;
		}
		else if (folderProperties.CheckStateTest == CheckState.Unchecked && GetRootTest().RootProperties.LogSkippedResults)
		{
			testResult = TestResult.Skipped;
		}
		else if (!(this is TestCaseTest) || string.IsNullOrEmpty(((TestCaseTest)this).TestCaseProperties.BlockedCRNumber))
		{
			testResult = ((!(this is TestCaseTest) || !AnyTestsSkipped()) ? TestResult.Passed : TestResult.Skipped);
		}
		else
		{
			testResult = TestResult.Blocked;
			text = ((TestCaseTest)this).TestCaseProperties.BlockedCRNumber;
		}
		if (FolderProperties.LinkRoot && !flag3)
		{
			Root.Scheduler.EndOfLinkedTesting(this, testResult);
		}
		FolderDetails folderDetails3 = default(FolderDetails);
		folderDetails3.NumberOfTests = folderProperties.NumberOfTests;
		if (flag3)
		{
			folderDetails3.isLoopFolder = true;
		}
		TestMessage eMessage2 = default(TestMessage);
		if (!string.IsNullOrEmpty(text))
		{
			eMessage2.ErrorCode = text;
		}
		eMessage2.Message = Properties.TestName;
		eMessage2.NodeRID = Properties.NodeRID;
		eMessage2.Object = folderDetails3;
		eMessage2.Result = testResult;
		eMessage2.TestIndex = Index;
		eMessage2.IsLinkedRoot = FolderProperties.LinkRoot;
		if (testResult == TestResult.Skipped && folderProperties.CheckStateTest == CheckState.Unchecked && GetRootTest().RootProperties.LogSkippedResults)
		{
			eMessage2.ResultDetails.ErrDescription = "UnChecked";
		}
		AddTestCaseDataIfApplicable(ref eMessage2);
		string gvValue5 = "";
		Root.Scheduler.Env.GlobalVariable.GetGlobalVariable("CURRENT_UNIT_INDEX", out gvValue5);
		int result2 = 0;
		int.TryParse(gvValue5, out result2);
		eMessage2.UnitIndex = result2;
		string gvValue6 = "";
		Root.Scheduler.Env.GlobalVariable.GetGlobalVariable("SN", out gvValue6);
		eMessage2.SerialNumber = gvValue6;
		eMessage2.TestPathInTree = base.TestPath;
		AddTestCaseDataIfApplicable(ref eMessage2);
		SetStartAndStopTimes(ref eMessage2);
		base.msgDelegate(TestMsgType.OnFolderEnd, eMessage2);
		if (this is TestCaseTest)
		{
			Root.Scheduler.GlobalStatus.TestCaseRunning = false;
		}
		if (flag)
		{
			Root.Scheduler.OnTreeDone();
		}
		TraceMessage.Write(ToString(), "EXIT: FolderTest.StartTest(" + Properties.TestName + ") returning " + flag2, TraceMessageType.Trace);
		TraceMessage.EndXMLLogging();
		return flag2;
	}

	internal bool IsMustRunFolder()
	{
		if (!FolderProperties.FolderMustRun && !FolderProperties.MustRunTest)
		{
			return FolderProperties.TreeMustRun;
		}
		return true;
	}

	private void SetStartAndStopTimes(ref TestMessage tMessage)
	{
		DateTime? dateTime = null;
		DateTime? dateTime2 = null;
		foreach (BaseTest test in TestList)
		{
			if (test == null)
			{
				continue;
			}
			BaseTest baseTest = test;
			if (baseTest.RuntimeAttributes.TestRan)
			{
				if (dateTime.HasValue)
				{
					DateTime testStartTime = baseTest.RuntimeAttributes.TestStartTime;
					DateTime? dateTime3 = dateTime;
					if (!(testStartTime < dateTime3))
					{
						goto IL_009b;
					}
				}
				dateTime = baseTest.RuntimeAttributes.TestStartTime;
				runtimeAttributes.TestStartTime = baseTest.RuntimeAttributes.TestStartTime;
			}
			goto IL_009b;
			IL_009b:
			if (!baseTest.RuntimeAttributes.TestRan)
			{
				continue;
			}
			if (dateTime2.HasValue)
			{
				DateTime testStopTime = baseTest.RuntimeAttributes.TestStopTime;
				DateTime? dateTime4 = dateTime2;
				if (!(testStopTime > dateTime4))
				{
					continue;
				}
			}
			dateTime2 = baseTest.RuntimeAttributes.TestStopTime;
			runtimeAttributes.TestStopTime = baseTest.RuntimeAttributes.TestStopTime;
		}
		if (dateTime.HasValue)
		{
			tMessage.TestStartTime = dateTime;
		}
		if (dateTime2.HasValue)
		{
			if (dateTime2 != DateTime.MinValue)
			{
				tMessage.TestStopTime = dateTime2;
			}
			else
			{
				tMessage.TestStopTime = dateTime;
			}
		}
	}

	public bool AnyTestsSkipped()
	{
		foreach (BaseTest test in TestList)
		{
			if (test is FolderTest)
			{
				return ((FolderTest)test).AnyTestsSkipped();
			}
			if (test.CurrentResult == TestResult.Skipped)
			{
				return true;
			}
		}
		return false;
	}

	private void AddTestCaseDataIfApplicable(ref TestMessage eMessage)
	{
		if (this is TestCaseTest)
		{
			eMessage.TestCaseID = ((TestCaseTestProperties)Properties).TestCaseID;
			eMessage.TestCaseName = ((TestCaseTestProperties)Properties).TestCaseName;
			eMessage.BlockedCRNumber = ((TestCaseTestProperties)Properties).BlockedCRNumber;
			eMessage.DisplayID = ((TestCaseTestProperties)Properties).DisplayID;
		}
		else
		{
			eMessage.TestCaseID = -1L;
		}
		if (parent is TestCaseTest)
		{
			eMessage.TestCaseRefID = ((TestCaseTestProperties)parent.Properties).TestCaseID;
		}
	}

	private void abortTimer_Elapsed(object sender, ElapsedEventArgs e)
	{
		TraceMessage.Write(ToString(), "ENTER: FolderTest.abortTimer_Elapsed()", TraceMessageType.Trace);
		if (Properties.TimeOutAction == TimeOutActions.Abort)
		{
			Root.Scheduler.GlobalStatus.Abort = true;
		}
		else if (Properties.TimeOutAction == TimeOutActions.AbortAndContinue)
		{
			AbortFolder = true;
		}
		string text = Properties.TestName + " timed out at: " + DateTime.Now.ToString();
		Root.Scheduler.Env.DebugMessage.Write("Temp", text, TraceLevel.Error);
		TraceMessage.Write(ToString(), text, TraceMessageType.Exception);
		TraceMessage.Write(ToString(), "EXIT: FolderTest.abortTimer_Elapsed()", TraceMessageType.Trace);
	}

	public bool RunTestsOnce()
	{
		TraceMessage.Write(ToString(), "ENTER: FolderTest.RunTestsOnce()", TraceMessageType.Trace);
		TraceMessage.Write(ToString(), "RunTestsOnce " + Properties.TestName, TraceMessageType.Trace);
		int num = 0;
		bool flag = true;
		QTMGlobalVariable.SetGlobalVariable("CURRENT_DYNAMIC_RETRY_COUNT", num.ToString());
		for (int i = 0; i < testCollection.Count; i++)
		{
			flag = CheckToRunTest(flag, i);
			if (CheckForDynamicRetry())
			{
				string gvValue = string.Empty;
				if (QTMGlobalVariable.GetGlobalVariable("DYNAMIC_RETRY_COUNT", out gvValue))
				{
					int.TryParse(gvValue, out var result);
					if (result > 0)
					{
						num++;
						QTMGlobalVariable.SetGlobalVariable("CURRENT_DYNAMIC_RETRY_COUNT", num.ToString());
						if (num <= result)
						{
							i--;
							continue;
						}
					}
				}
			}
			num = 0;
			QTMGlobalVariable.SetGlobalVariable("CURRENT_DYNAMIC_RETRY_COUNT", num.ToString());
		}
		if (Properties.StopOnError == StopOnErrorTypes.CompleteStopNoRetry && runtimeAttributes.Failed)
		{
			if (Root.Scheduler.GlobalStatus.TestMsgHold)
			{
				Root.Scheduler.GlobalStatus.TestMsgHold = false;
			}
			Root.Scheduler.GlobalStatus.Abort = true;
		}
		if (Parent is RootTest)
		{
			if (RuntimeAttributes.StopOnError == StopOnErrorTypes.SkipToNextCategory)
			{
				RuntimeAttributes.StopOnError = StopOnErrorTypes.None;
			}
			else if (RuntimeAttributes.StopOnError == StopOnErrorTypes.SkipTheFolder && Properties.StopOnError == StopOnErrorTypes.None)
			{
				runtimeAttributes.StopOnError = StopOnErrorTypes.None;
			}
			if (RuntimeAttributes.PostConditionAction == PostConditionActions.SkipToNextCategory)
			{
				RuntimeAttributes.PostConditionAction = PostConditionActions.None;
			}
			else if (RuntimeAttributes.PostConditionAction == PostConditionActions.SkipTheFolder)
			{
				runtimeAttributes.PostConditionAction = PostConditionActions.None;
			}
		}
		else
		{
			if (RuntimeAttributes.StopOnError == StopOnErrorTypes.SkipTheFolder && Properties.StopOnError == StopOnErrorTypes.None)
			{
				runtimeAttributes.StopOnError = StopOnErrorTypes.None;
			}
			if (RuntimeAttributes.PostConditionAction == PostConditionActions.SkipTheFolder)
			{
				RuntimeAttributes.PostConditionAction = PostConditionActions.None;
			}
		}
		TraceMessage.Write(ToString(), "EXIT: FolderTest.RunTestsOnce() returning " + flag, TraceMessageType.Trace);
		if (this is RootTest)
		{
			TraceMessage.EndXMLLoggingTemp();
		}
		return flag;
	}

	private bool CheckForDynamicRetry()
	{
		bool result = false;
		if (Root.RootProperties.TreeType == TreeTypes.TestPlan)
		{
			try
			{
				result = Root.Scheduler.GlobalStatus.ApplyDynamicRetry;
				Root.Scheduler.GlobalStatus.ApplyDynamicRetry = false;
				if (string.Compare(Root.Scheduler.Env.QTMInfo.GetCurrentErrorReasonCode(), "DynamicRetry", ignoreCase: true) == 0)
				{
					Root.Scheduler.Env.QTMInfo.SetCurrentErrorReasonCode(string.Empty);
				}
			}
			catch
			{
				Root.Scheduler.GlobalStatus.ApplyDynamicRetry = false;
			}
		}
		return result;
	}

	private bool CheckToRunTest(bool bRet, int index)
	{
		try
		{
			BaseTest test = testCollection[index];
			test.TestUserInterfaceProperties.ResetRunTimeAttributes();
			SetFolderAttributes(test);
			if (RuntimeAttributes.RightClickTest && test.Properties.ToolTest)
			{
				test.RuntimeAttributes.Tool = true;
				test.RuntimeAttributes.RightClickTest = true;
			}
			bool loopStartSent = false;
			if (test.CanTestRun(RuntimeAttributes))
			{
				HandleLoggingCondition(index, test);
				HandleBreakPoint(index, test);
				if (Root.Scheduler.GlobalStatus.IsInteractiveMode)
				{
					PreRunSteps(ref test, ref loopStartSent);
					if (test is FolderTest)
					{
						Root.Scheduler.GlobalStatus.NextTestInfo = null;
					}
					else
					{
						Root.Scheduler.GlobalStatus.Pause = true;
						Root.Scheduler.GlobalStatus.InteractiveStatus = GlobalStatus.ExecutionStatus.AwaitingFeedback;
						test.Properties.Parameters.GetParameterExportList(onlyLoggedParameters: false, outputOnly: false, ignoreEmptyStringValues: false);
						Root.Scheduler.GlobalStatus.NextTestInfo = new CurrentTestInfo
						{
							DLLName = test.Root.Scheduler.Registry.GetTestModulePath(test),
							RealName = test.Properties.RealName,
							TestName = test.Properties.TestName,
							TestIndex = test.Index,
							Parameters = test.Properties.Parameters
						};
					}
				}
				while (!Root.Scheduler.GlobalStatus.Abort && !abortFolder && Root.Scheduler.GlobalStatus.Pause)
				{
					Thread.Sleep(30);
					QTMData.DoEvents();
				}
				if ((Root.Scheduler.GlobalStatus.Stop || abortFolder) && (!test.Properties.TreeMustRun || !Root.RootProperties.AlwaysPerformMustRunTests))
				{
					DequeueTest();
					CheckForBranchOnError(test, runtimeAttributes);
				}
				else
				{
					try
					{
						if (test is TestCaseTest)
						{
							if (Root.Scheduler.Env.GlobalVariable.Contains("LastStartedTestCaseID".ToUpper()))
							{
								Root.Scheduler.Env.GlobalVariable.SetGlobalVariable("LastStartedTestCaseID".ToUpper(), test.TestCase.TestCaseProperties.DisplayID.ToString());
							}
							else
							{
								GVData gVData = default(GVData);
								gVData.Name = "LastStartedTestCaseID".ToUpper();
								gVData.Value = test.TestCase.TestCaseProperties.DisplayID.ToString();
								QTMGlobalVariable.GVariables.Add("LastStartedTestCaseID".ToUpper(), gVData);
							}
						}
					}
					catch
					{
					}
					bool flag = true;
					if (Root.Scheduler.GlobalStatus.IsInteractiveMode && !(test is FolderTest) && Root.Scheduler.GlobalStatus.ExternalRunTestStatus != 0)
					{
						object objParameters = test.Properties.Parameters.GetParameterObject(Root.Scheduler);
						Root.Scheduler.GlobalStatus.InteractiveStatus = GlobalStatus.ExecutionStatus.Executing;
						flag = false;
						test.RunTestInteractive(test.Properties.TestName, ref objParameters);
						test.RuntimeAttributes.TestRan = true;
						test.RuntimeAttributes.Exception = false;
						test.RuntimeAttributes.TestStartTime = DateTime.Now;
						test.RuntimeAttributes.TestStopTime = DateTime.Now.AddMilliseconds(100.0);
						switch (Root.Scheduler.GlobalStatus.ExternalRunTestStatus)
						{
						case GlobalStatus.TestStatus.Passed:
							test.RuntimeAttributes.Failed = false;
							test.RuntimeAttributes.HasPassedOnce = true;
							break;
						case GlobalStatus.TestStatus.Failed:
							test.RuntimeAttributes.Failed = true;
							test.RuntimeAttributes.HasFailedOnce = true;
							break;
						case GlobalStatus.TestStatus.Exception:
							test.RuntimeAttributes.Exception = true;
							test.RuntimeAttributes.Failed = true;
							test.RuntimeAttributes.HasFailedOnce = true;
							break;
						}
						Root.Scheduler.GlobalStatus.ExternalRunTestStatus = GlobalStatus.TestStatus.NotSet;
						bRet = PostRunSteps(bRet, test, loopStartSent, abortAndContinue: false, isExternalTestRun: true);
					}
					if (flag)
					{
						SetupMetadata(test);
						Root.Scheduler.GlobalStatus.InteractiveStatus = GlobalStatus.ExecutionStatus.Executing;
						RunCurrentTest(ref bRet, ref test, ref loopStartSent);
						Root.Scheduler.GlobalStatus.InteractiveStatus = GlobalStatus.ExecutionStatus.AwaitingFeedback;
						CleanupMetadata(test);
					}
					if (Root.Scheduler.GlobalStatus.IsInteractiveMode && !(test is FolderTest))
					{
						if (test.RuntimeAttributes.Exception)
						{
							Root.Scheduler.GlobalStatus.InternalRunTestStatus = GlobalStatus.TestStatus.Exception;
						}
						else if (test.RuntimeAttributes.Failed)
						{
							Root.Scheduler.GlobalStatus.InternalRunTestStatus = GlobalStatus.TestStatus.Failed;
						}
						else
						{
							Root.Scheduler.GlobalStatus.InternalRunTestStatus = GlobalStatus.TestStatus.Passed;
						}
						Root.Scheduler.GlobalStatus.InteractiveStatus = GlobalStatus.ExecutionStatus.AwaitingFeedback;
					}
					if (test is TestCaseTest)
					{
						bool flag2 = false;
						try
						{
							if (test.CurrentResult == TestResult.Failed || test.CurrentResult == TestResult.Exception)
							{
								if (!Root.Scheduler.GlobalStatus.FailedTestCases.Contains(test.TestCase.TestCaseProperties.TestCaseMasterID))
								{
									Root.Scheduler.GlobalStatus.FailedTestCases.Add(test.TestCase.TestCaseProperties.TestCaseMasterID);
								}
								if (!Root.Scheduler.GlobalStatus.ConsectiveFailedTestCases.Contains(test.TestCase.TestCaseProperties.TestCaseMasterID))
								{
									Root.Scheduler.GlobalStatus.ConsectiveFailedTestCases.Add(test.TestCase.TestCaseProperties.TestCaseMasterID);
								}
							}
							else if (test.CurrentResult == TestResult.Passed)
							{
								Root.Scheduler.GlobalStatus.ConsectiveFailedTestCases.Clear();
							}
							if (Root.Scheduler.GlobalStatus.BailOutLogic == BailOutLogicSelection.Both || Root.Scheduler.GlobalStatus.BailOutLogic == BailOutLogicSelection.TestCases)
							{
								if ((int)Root.Scheduler.GlobalStatus.BailOutLogicFixedNumber > 0 && Root.Scheduler.GlobalStatus.FailedTestCases.Count >= (int)Root.Scheduler.GlobalStatus.BailOutLogicFixedNumber)
								{
									flag2 = true;
								}
								else if ((int)Root.Scheduler.GlobalStatus.BailOutLogicFixedNumberConsective > 0 && Root.Scheduler.GlobalStatus.ConsectiveFailedTestCases.Count >= (int)Root.Scheduler.GlobalStatus.BailOutLogicFixedNumberConsective)
								{
									flag2 = true;
								}
								else if ((int)Root.Scheduler.GlobalStatus.BailOutLogicFixedPercentage > 0 && Math.Round(Root.Scheduler.GlobalStatus.BailOutLogicFixedPercentage * (double)Root.Scheduler.GlobalStatus.TotalSelectedTestCases / 100.0) >= 1.0 && (double)Root.Scheduler.GlobalStatus.FailedTestCases.Count >= Math.Round(Root.Scheduler.GlobalStatus.BailOutLogicFixedPercentage * (double)Root.Scheduler.GlobalStatus.TotalSelectedTestCases / 100.0))
								{
									flag2 = true;
								}
								else if ((int)Root.Scheduler.GlobalStatus.BailOutLogicFixedPercentageConsective > 0 && Math.Round(Root.Scheduler.GlobalStatus.BailOutLogicFixedPercentageConsective * (double)Root.Scheduler.GlobalStatus.TotalSelectedTestCases / 100.0) >= 1.0 && (double)Root.Scheduler.GlobalStatus.ConsectiveFailedTestCases.Count >= Math.Round(Root.Scheduler.GlobalStatus.BailOutLogicFixedPercentageConsective * (double)Root.Scheduler.GlobalStatus.TotalSelectedTestCases / 100.0))
								{
									flag2 = true;
								}
							}
						}
						catch
						{
							flag2 = false;
						}
						if (flag2)
						{
							Root.Scheduler.GlobalStatus.BailedOut = true;
							GVData gVData2 = default(GVData);
							gVData2.Name = "SessionBailedOut".ToUpper();
							gVData2.Value = Root.Scheduler.GlobalStatus.BailedOut.ToString();
							Root.Scheduler.Env.GlobalVariable.SetGlobalVariable("SessionBailedOut".ToUpper(), gVData2.Value);
							Root.Scheduler.GlobalStatus.Abort = true;
						}
					}
					if (test is FolderTest && test.CurrentResult == TestResult.Failed && ((FolderTest)test).FolderProperties.PreRequisite)
					{
						FlagDependennts(test.Parent, test, preRequisiteFailed: true);
					}
					else if (test is FolderTest && test.CurrentResult == TestResult.Passed && ((FolderTest)test).FolderProperties.PreRequisite)
					{
						FlagDependennts(test.Parent, test, preRequisiteFailed: false);
					}
					if (test.RuntimeAttributes.Failed)
					{
						if (test.Properties.StopOnError == StopOnErrorTypes.CompleteStopNoRetry)
						{
							if (Root.Scheduler.GlobalStatus.TestMsgHold)
							{
								Root.Scheduler.GlobalStatus.TestMsgHold = false;
							}
							Root.Scheduler.GlobalStatus.Abort = true;
						}
						if (test.Properties.StopOnError == StopOnErrorTypes.PauseTestTree || Properties.StopOnError == StopOnErrorTypes.PauseTestTree)
						{
							Root.Scheduler.GlobalStatus.Pause = true;
						}
						else if (Root.Scheduler.GlobalStatus.PauseOnTestFailure && !(test is FolderTest))
						{
							Root.Scheduler.GlobalStatus.Pause = true;
						}
					}
				}
			}
			else
			{
				CheckForBranchOnError(test, runtimeAttributes);
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "RunTestsOnce " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
		return bRet;
	}

	private void FlagDependennts(BaseTest currentTest, BaseTest actualTest, bool preRequisiteFailed)
	{
		if (currentTest.Properties.CheckStateTest == CheckState.Unchecked || currentTest == actualTest)
		{
			return;
		}
		if (currentTest is FolderTest && !(currentTest is TestCaseTest))
		{
			foreach (BaseTest test in ((FolderTest)currentTest).TestList)
			{
				FlagDependennts(test, actualTest, preRequisiteFailed);
			}
			return;
		}
		currentTest.preRequisiteFailed = preRequisiteFailed;
	}

	private void SetupMetadata(BaseTest test)
	{
		if (test.Properties.Metadata == null)
		{
			return;
		}
		try
		{
			foreach (MetadataItem item in test.Properties.Metadata.Items)
			{
				structLoopValues structLoopValues = default(structLoopValues);
				structLoopValues.sLoopName = item.Name;
				structLoopValues.isInputParameter = true;
				if (item.Type == MetadataItem.MetadataType.TestParameter)
				{
					BaseTest baseTest = Root.FindTest(item.TestIndex);
					ParameterCls parameterCls = baseTest.Properties.Parameters.FindParam(item.SourceName);
					if (parameterCls.NoOfElements > 1 || parameterCls.IsDynamicArray)
					{
						string[] array = new string[0];
						array = ((parameterCls.DataType != DataType.String) ? parameterCls.Value.Split(',') : ParameterCls.SplitStringArrayParameter(parameterCls.Value));
						if (array.Length > item.ArrayIndex)
						{
							structLoopValues.sLoopValue = array[item.ArrayIndex];
						}
						else
						{
							structLoopValues.sLoopValue = "";
						}
					}
					else
					{
						structLoopValues.sLoopValue = parameterCls.Value;
					}
				}
				else if (item.Type == MetadataItem.MetadataType.GlobalVariable)
				{
					structLoopValues.sLoopValue = GlobalInformation.GetGlobalVariable(item.SourceName).ToString();
				}
				if (base.msgDelegate != null && !Root.Scheduler.GlobalStatus.Stop)
				{
					TestMessage message = default(TestMessage);
					message.Message = test.TestPath;
					message.NodeRID = test.Properties.NodeRID;
					message.Object = structLoopValues;
					message.Result = TestResult.Passed;
					message.TestIndex = test.Index;
					if (base.msgDelegate != null)
					{
						base.msgDelegate(TestMsgType.OnLoopStart, message);
					}
				}
			}
		}
		catch
		{
		}
	}

	private void CleanupMetadata(BaseTest test)
	{
		if (test.Properties.Metadata == null)
		{
			return;
		}
		foreach (MetadataItem item in test.Properties.Metadata.Items)
		{
			_ = item;
			TestMessage message = default(TestMessage);
			message.Message = "";
			message.NodeRID = -1L;
			message.Object = null;
			message.Result = TestResult.Passed;
			message.TestIndex = "";
			if (base.msgDelegate != null)
			{
				base.msgDelegate(TestMsgType.OnLoopEnd, message);
			}
		}
	}

	private void DequeueTest()
	{
		ArrayList arrayList = new ArrayList();
		MsgData msg = default(MsgData);
		msg.msgType = TestMsgType.OnDequeueTest;
		msg.TestFullPath = base.TestPath;
		msg.TestIndex = Index;
		msg.TestName = RealName;
		msg.TestPathInTree = base.TestPath;
		AddTestCaseDataToMsgDataIfApplicable(ref msg);
		arrayList.Add(msg);
		TestMessage message = default(TestMessage);
		message.Message = base.TestPath;
		message.NodeRID = Properties.NodeRID;
		message.Object = arrayList;
		message.Result = TestResult.Passed;
		message.TestIndex = Index;
		base.msgDelegate(TestMsgType.OnDequeueTest, message);
	}

	private void AddTestCaseDataToMsgDataIfApplicable(ref MsgData msg)
	{
		if (this is TestCaseTest)
		{
			msg.TestCaseInfo.TestCaseID = ((TestCaseTest)this).TestCaseProperties.TestCaseID;
			msg.TestName = ((TestCaseTest)this).TestCaseProperties.TestCaseName;
			msg.TestCaseInfo.TestCaseName = ((TestCaseTest)this).TestCaseProperties.TestCaseName;
			msg.BlockedCRNumber = ((TestCaseTest)this).TestCaseProperties.BlockedCRNumber;
		}
		else if (this is RootTest)
		{
			msg.TestCaseInfo.TestCaseName = ((RootTest)this).name;
		}
		if (parent is TestCaseTest)
		{
			msg.TestCaseInfo.TestCaseRefID = ((TestCaseTest)parent).TestCaseProperties.TestCaseID;
		}
	}

	private void HandleBreakPoint(int index, BaseTest test)
	{
		if (Root.Scheduler.GlobalStatus.SecondaryQueueRunning || (test.Properties.BreakPoint != BreakPointTypes.Enable && !Root.Scheduler.GlobalStatus.Pause) || (test.Properties.CheckStateTest != CheckState.Checked && test.Properties.CheckStateTest != CheckState.Indeterminate) || (!QSecurity.IsEngineer && !QSecurity.IsTechnician))
		{
			return;
		}
		if (RuntimeAttributes.RightClickTest)
		{
			if (index != 0)
			{
				Root.Scheduler.GlobalStatus.Pause = true;
				SendBreakMsg(test);
			}
		}
		else
		{
			Root.Scheduler.GlobalStatus.Pause = true;
			SendBreakMsg(test);
		}
	}

	private void SendBreakMsg(BaseTest test)
	{
		try
		{
			ArrayList arrayList = new ArrayList();
			MsgData msgData = default(MsgData);
			msgData.msgType = TestMsgType.OnBreak;
			msgData.TestFullPath = test.TestPath;
			msgData.TestIndex = test.Index;
			arrayList.Add(msgData);
			TestMessage message = default(TestMessage);
			message.Message = test.TestPath;
			message.NodeRID = test.Properties.NodeRID;
			message.Object = arrayList;
			message.Result = TestResult.Indeterminate;
			message.TestIndex = test.Index;
			base.msgDelegate(TestMsgType.OnBreak, message);
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "SendBreakMsg" + ex.Message, TraceMessageType.Exception);
		}
	}

	private void HandleLoggingCondition(int i, BaseTest test)
	{
		try
		{
			if (!Root.Scheduler.QTMData.WConfig.ShowDebugMessages && test.Properties.LoggingEnabled && (test.Properties.CheckStateTest == CheckState.Checked || test.Properties.CheckStateTest == CheckState.Indeterminate))
			{
				string gvValue = "";
				Root.Scheduler.Env.GlobalVariable.GetGlobalVariable("LOGGING_ENABLED", out gvValue);
				if (string.IsNullOrEmpty(gvValue))
				{
					Root.Scheduler.Env.GlobalVariable.SetGlobalVariable("LOGGING_ENABLED", test.Properties.TestName);
				}
				else
				{
					Root.Scheduler.Env.GlobalVariable.SetGlobalVariable("LOGGING_ENABLED", gvValue + "," + test.Properties.TestName);
				}
			}
			else if (Root.Scheduler.QTMData.WConfig.ShowDebugMessages)
			{
				Root.Scheduler.Env.GlobalVariable.SetGlobalVariable("LOGGING_ENABLED", "All");
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "HandleLoggingCondition" + ex.Message, TraceMessageType.Exception);
		}
	}

	private void SetFolderAttributes(BaseTest test)
	{
		if (test is FolderTest)
		{
			test.RuntimeAttributes.StopOnError = RuntimeAttributes.StopOnError;
			test.RuntimeAttributes.PostConditionAction = RuntimeAttributes.PostConditionAction;
			if (!test.RuntimeAttributes.Tool)
			{
				test.RuntimeAttributes.Tool = RuntimeAttributes.Tool;
			}
		}
	}

	private void RunCurrentTest(ref bool bRet, ref BaseTest test, ref bool loopStartSent)
	{
		TraceMessage.Write(ToString(), "ENTER: FolderTest.RunCurrentTest(" + test.Properties.TestName + ")", TraceMessageType.Trace);
		try
		{
			PreRunSteps(ref test, ref loopStartSent);
			DateTime startTime = DateTime.Now - TimeSpan.FromMilliseconds(10.0);
			int testTimeOut = test.Properties.TestTimeOut;
			bool abortAndContinue = false;
			bool abort = Root.Scheduler.GlobalStatus.Abort;
			Root.Scheduler.GlobalStatus.Abort = false;
			bRet &= test.StartTest();
			WaitForCurrRunningTestDone(test, ref startTime, testTimeOut, out abortAndContinue);
			Root.Scheduler.GlobalStatus.Abort |= abort;
			bRet = PostRunSteps(bRet, test, loopStartSent, abortAndContinue);
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "EXCEPTION: FolderTest.RunCurrentTest(" + test.Properties.TestName + ") " + ex.ToString(), TraceMessageType.Trace);
			throw new Exception(ex.ToString());
		}
		TraceMessage.Write(ToString(), "EXIT: FolderTest.RunCurrentTest(" + test.Properties.TestName + ")", TraceMessageType.Trace);
	}

	private bool PostRunSteps(bool bRet, BaseTest test, bool loopStartSent, bool abortAndContinue, bool isExternalTestRun = false)
	{
		TraceMessage.Write(ToString(), "ENTER: FolderTest.PostRunSteps(" + test.Properties.TestName + ")", TraceMessageType.Trace);
		if (isExternalTestRun)
		{
			int iResult = 1;
			if (test.RuntimeAttributes.Exception)
			{
				iResult = 2;
			}
			else if (test.RuntimeAttributes.Failed)
			{
				iResult = 0;
			}
			else if (test.RuntimeAttributes.Skipped)
			{
				iResult = 7;
			}
			test.Root.Scheduler.TestMsgBroadCaster.OnTestDone(test.Properties.TestName, iResult, test.Properties.Parameters.GetParameterObject(test.Root.Scheduler));
		}
		SendLoopEndMessage(loopStartSent);
		if (Root.Scheduler.GlobalStatus.Abort)
		{
			TreeAborted(test, continueTestRun: false);
		}
		else if (abortAndContinue || abortFolder)
		{
			TreeAborted(test, continueTestRun: true);
		}
		bRet = CheckForTestException(bRet, test);
		bRet = CheckForFailedTest(bRet, test);
		HandlePostConditionAction(test);
		TraceMessage.Write(ToString(), "EXIT: FolderTest.PostRunSteps(" + test.Properties.TestName + ") returning " + bRet, TraceMessageType.Trace);
		return bRet;
	}

	private void PreRunSteps(ref BaseTest test, ref bool loopStartSent)
	{
		TraceMessage.Write(ToString(), "ENTER: FolderTest.PreRunSteps(" + test.Properties.TestName + ")", TraceMessageType.Trace);
		CheckForBranchOnError(test, runtimeAttributes);
		test = CheckForLoops(test);
		loopStartSent = CheckForInputConditions(test, loopStartSent);
		TraceMessage.Write(ToString(), "EXIT: FolderTest.PreRunSteps(" + test.Properties.TestName + ")", TraceMessageType.Trace);
	}

	private void HandlePostConditionAction(BaseTest test)
	{
		if (test.RuntimeAttributes.PostConditionAction == PostConditionActions.IgnoreSession)
		{
			Root.Scheduler.GlobalStatus.GlobalTestResult = TestResult.IgnoreSession;
		}
		if (test.RuntimeAttributes.PostConditionAction != 0 && test.RuntimeAttributes.PostConditionAction != PostConditionActions.Branch)
		{
			RuntimeAttributes.PostConditionAction = test.RuntimeAttributes.PostConditionAction;
		}
	}

	private bool WaitForRunTestMessage(BaseTest test)
	{
		bool flag = false;
		bool result = false;
		while (!Root.Scheduler.GlobalStatus.Abort && !flag && !abortFolder && Root.Scheduler.ListOfTestsRunning.Count > 0)
		{
			Thread.Sleep(30);
			QTMData.DoEvents();
		}
		return result;
	}

	private TimeSpan WaitForCurrRunningTestDone(BaseTest test, ref DateTime startTime, int timeOutSeconds, out bool abortAndContinue)
	{
		TraceMessage.WriteAlways(ToString(), "ENTER: FolderTest.WaitForCurrRunningTestDone(" + test.Properties.TestName + ")", TraceMessageType.Trace);
		TimeSpan timeSpan = default(TimeSpan);
		abortAndContinue = false;
		while (!Root.Scheduler.GlobalStatus.Abort && !abortAndContinue && !abortFolder && Root.Scheduler.ListOfTestsRunning.Count > 0)
		{
			Thread.Sleep(30);
			QTMData.DoEvents();
			if (test.RuntimeAttributes.TestStartTime <= startTime)
			{
				continue;
			}
			if (Root.Scheduler.GlobalStatus.ProcessingTestDone)
			{
				TraceMessage.WriteAlways(test.ToString(), test.Properties.TestName + " is done running and is being processed, ignoring timeouts.", TraceMessageType.Trace);
				continue;
			}
			if (Root.Scheduler.GlobalStatus.Abort || abortAndContinue || abortFolder || Root.Scheduler.ListOfTestsRunning.Count <= 0)
			{
				break;
			}
			DateTime now = DateTime.Now;
			timeSpan = now - test.RuntimeAttributes.TestStartTime;
			if (timeOutSeconds > 0 && timeSpan.TotalSeconds > (double)timeOutSeconds)
			{
				if (test.Properties.TimeOutAction == TimeOutActions.Abort)
				{
					Root.Scheduler.GlobalStatus.Abort = true;
					test.RuntimeAttributes.Exception = true;
				}
				else if (test.Properties.TimeOutAction == TimeOutActions.AbortAndContinue)
				{
					abortAndContinue = true;
					test.RuntimeAttributes.Failed = true;
				}
				test.StopTest();
				string text = string.Concat(test.Properties.TestName, " timed out at: ", now, ", start time according to timer: ", startTime);
				Root.Scheduler.Env.DebugMessage.Write("Temp", text, TraceLevel.Error);
				TraceMessage.WriteAlways(test.ToString(), text, TraceMessageType.Exception);
			}
		}
		if (abortFolder)
		{
			test.RuntimeAttributes.Failed = true;
		}
		TraceMessage.WriteAlways(ToString(), "EXIT: FolderTest.WaitForCurrRunningTestDone(" + test.Properties.TestName + ") returning " + timeSpan, TraceMessageType.Trace);
		return timeSpan;
	}

	private bool CheckForFailedTest(bool bRet, BaseTest test)
	{
		if (test.RuntimeAttributes.Failed)
		{
			bRet = false;
			if (!Root.Scheduler.GlobalStatus.TestMsgHold || Properties.StopOnError == StopOnErrorTypes.CompleteStopNoRetry)
			{
				RuntimeAttributes.Failed = true;
				HandleRunTimeAttributes(test);
			}
		}
		return bRet;
	}

	private bool CheckForTestException(bool bRet, BaseTest test)
	{
		if (test.RuntimeAttributes.Exception)
		{
			bRet = false;
			folderProperties.Exception = true;
			RuntimeAttributes.Exception = true;
			HandleRunTimeAttributes(test);
		}
		return bRet;
	}

	private void TreeAborted(BaseTest test, bool continueTestRun)
	{
		TraceMessage.Write(ToString(), "ENTER: FolderTest.TreeAborted(" + test.Properties.TestName + ")", TraceMessageType.Trace);
		try
		{
			if (!test.RuntimeAttributes.Exception)
			{
				string testErrorCodeOnAbort = GetRootTest().RootProperties.TestErrorCodeOnAbort;
				if (!string.IsNullOrEmpty(testErrorCodeOnAbort))
				{
					Root.Scheduler.Env.GlobalVariable.SetErrorCode(testErrorCodeOnAbort);
				}
			}
			if (Root.Scheduler.ListOfTestsRunning.Count > 0)
			{
				string key = test.Properties.TestName;
				if (test.Properties.DescriptionName.Trim() != "")
				{
					key = test.Properties.DescriptionName.Trim();
				}
				if (Root.Scheduler.ListOfTestsRunning.ContainsKey(key))
				{
					if (!continueTestRun)
					{
						Root.Scheduler.GlobalStatus.GlobalTestResult = TestResult.Exception;
					}
					else
					{
						Root.Scheduler.GlobalStatus.GlobalTestResult = TestResult.Failed;
					}
					test.Properties.DescriptionName = "";
					TestMessage message = default(TestMessage);
					message.Message = test.Properties.TestName;
					message.NodeRID = test.Properties.NodeRID;
					message.Object = new ArrayList();
					message.Result = TestResult.Passed;
					message.TestIndex = test.Index;
					string gvValue = "";
					Root.Scheduler.Env.GlobalVariable.GetGlobalVariable("SN", out gvValue);
					message.SerialNumber = gvValue;
					if (!continueTestRun)
					{
						message.Result = TestResult.Exception;
					}
					else
					{
						message.Result = TestResult.Failed;
					}
					message.TestIndex = test.Index;
					message.TestPathInTree = test.TestPath;
					message.CurrentLoopIteration = test.RuntimeAttributes.CurrentLoopIteration;
					message.MaxLoopIteration = test.RuntimeAttributes.MaxLoopIteration;
					base.msgDelegate(TestMsgType.OnTestResult, message);
					if (test is HiveTest)
					{
						test.StopTest();
					}
					if (continueTestRun)
					{
						Root.Scheduler.ListOfTestsRunning.Remove(key);
					}
				}
			}
			if (!continueTestRun)
			{
				Root.Scheduler.ListOfTestsRunning.Clear();
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "EXCEPTION: FolderTest.TreeAborted(" + test.Properties.TestName + ")" + ex.ToString(), TraceMessageType.Trace);
		}
		TraceMessage.Write(ToString(), "EXIT: FolderTest.TreeAborted(" + test.Properties.TestName + ")", TraceMessageType.Trace);
	}

	private void SendLoopEndMessage(bool loopStartSent)
	{
		if (loopStartSent)
		{
			TestMessage message = default(TestMessage);
			message.Message = "";
			message.NodeRID = -1L;
			message.Object = null;
			message.Result = TestResult.Passed;
			message.TestIndex = "";
			if (base.msgDelegate != null)
			{
				base.msgDelegate(TestMsgType.OnLoopEnd, message);
			}
		}
	}

	private bool CheckForInputConditions(BaseTest test, bool loopStartSent)
	{
		if (!(test is FolderTest))
		{
			test.Properties.Parameters.UpdateFromGlobalVariables(Root);
			ArrayList inputLoggedParameter = test.Properties.Parameters.GetInputLoggedParameter();
			bool bPartOfScenario = false;
			foreach (ParameterCls item in inputLoggedParameter)
			{
				structLoopValues structLoopValues = default(structLoopValues);
				structLoopValues.sLoopName = item.Name;
				structLoopValues.sLoopValue = item.Value;
				structLoopValues.sDesc = "";
				structLoopValues.iRowIndex = 0;
				structLoopValues.ScenarioID = -1;
				structLoopValues.bPartOfScenario = bPartOfScenario;
				structLoopValues.isInputParameter = true;
				TestMessage message = default(TestMessage);
				message.Message = test.TestPath;
				message.NodeRID = test.Properties.NodeRID;
				message.Object = structLoopValues;
				message.Result = TestResult.Passed;
				message.TestIndex = test.Index;
				if (base.msgDelegate != null)
				{
					base.msgDelegate(TestMsgType.OnLoopStart, message);
				}
				bPartOfScenario = true;
				loopStartSent = true;
			}
		}
		return loopStartSent;
	}

	private BaseTest CheckForLoops(BaseTest test)
	{
		if (!(test is FolderTest) && test.Properties.Scenarios != null)
		{
			if (test.Parent != null && test.Parent != null && test.Parent.Properties.TestName == "TempFolder" && test.Parent.FolderProperties.FolderForTestLoop)
			{
				return test;
			}
			FolderTest folderTest = new FolderTest("TempFolder");
			folderTest.FolderProperties.FolderForTestLoop = true;
			folderTest.FolderProperties.RefreshLoopValuesAtLoopStart = test.Properties.RefreshLoopValuesAtLoopStart;
			folderTest.Parent = test.Parent;
			folderTest.Add(test);
			folderTest.Properties.Scenarios = test.Properties.Scenarios;
			folderTest.Properties.LinkNode = test.Properties.LinkNode;
			folderTest.Properties.IsLinkActive = test.Properties.IsLinkActive;
			test = folderTest;
			test.RuntimeAttributes.StopOnError = RuntimeAttributes.StopOnError;
			test.RuntimeAttributes.PostConditionAction = RuntimeAttributes.PostConditionAction;
			if (!test.RuntimeAttributes.Tool)
			{
				test.RuntimeAttributes.Tool = RuntimeAttributes.Tool;
			}
			folderTest.RuntimeAttributes.RightClickTest = RuntimeAttributes.RightClickTest;
		}
		return test;
	}

	public void HandleRunTimeAttributes(BaseTest test)
	{
		bool flag = test.RuntimeAttributes.Failed && !test.IsInRetry();
		if (flag || test.RuntimeAttributes.Exception)
		{
			if (test.Properties.TestErrorCode.Length > 0)
			{
				Root.Scheduler.Env.GlobalVariable.SetErrorCode(test.Properties.TestErrorCode);
			}
			else if (test.RuntimeAttributes.Exception)
			{
				string testErrorCodeOnAbort = GetRootTest().RootProperties.TestErrorCodeOnAbort;
				if (!string.IsNullOrEmpty(testErrorCodeOnAbort))
				{
					Root.Scheduler.Env.GlobalVariable.SetErrorCode(testErrorCodeOnAbort);
				}
			}
			else if (test.RuntimeAttributes.Failed)
			{
				string testErrorCode = GetRootTest().RootProperties.TestErrorCode;
				if (!string.IsNullOrEmpty(testErrorCode))
				{
					Root.Scheduler.Env.GlobalVariable.SetErrorCode(testErrorCode);
				}
			}
		}
		if (!flag)
		{
			return;
		}
		if (test.Properties.BranchOnErrorByName)
		{
			Root.Scheduler.GlobalStatus.BranchOnError = true;
			BaseTest baseTest = Root.FindTestFromTestName(test.Properties.BranchOnErrorName, isPartialName: false, test.Index);
			if (baseTest != null)
			{
				Root.Scheduler.GlobalStatus.BranchOnTestIndex = baseTest.Index;
			}
		}
		else if (test.Properties.BranchOnErrorIndex.Trim() != "")
		{
			Root.Scheduler.GlobalStatus.BranchOnError = true;
			Root.Scheduler.GlobalStatus.BranchOnTestIndex = test.Properties.BranchOnErrorIndex.Trim();
		}
		if (test.RuntimeAttributes.StopOnError == StopOnErrorTypes.IgnoreSession)
		{
			Root.Scheduler.GlobalStatus.GlobalTestResult = TestResult.IgnoreSession;
		}
		if (test.RuntimeAttributes.StopOnError > RuntimeAttributes.StopOnError)
		{
			RuntimeAttributes.StopOnError = test.RuntimeAttributes.StopOnError;
		}
		if (Properties.StopOnError > RuntimeAttributes.StopOnError)
		{
			RuntimeAttributes.StopOnError = Properties.StopOnError;
		}
		if (Root.Scheduler.GlobalStatus.GlobalTestResult != TestResult.IgnoreSession && Root.Scheduler.GlobalStatus.StopOnFirstTestFailure && runtimeAttributes.StopOnError != StopOnErrorTypes.IgnoreSession)
		{
			RuntimeAttributes.StopOnError = StopOnErrorTypes.CompleteStop;
		}
	}

	private void CheckForBranchOnError(BaseTest test, TestRuntimeAttributes folderAttributes)
	{
		if (Root.Scheduler.GlobalStatus.Stop)
		{
			Root.Scheduler.GlobalStatus.BranchOnError = false;
			Root.Scheduler.GlobalStatus.BranchOnTestIndex = "";
		}
		else if (folderAttributes.StopOnError > StopOnErrorTypes.None)
		{
			Root.Scheduler.GlobalStatus.BranchOnError = false;
			Root.Scheduler.GlobalStatus.BranchOnTestIndex = "";
		}
		else if (Root.Scheduler.GlobalStatus.BranchOnError && (test.Index.Trim() == Root.Scheduler.GlobalStatus.BranchOnTestIndex.Trim() || test.OriginalIndex.Trim() == Root.Scheduler.GlobalStatus.BranchOnTestIndex.Trim()))
		{
			Root.Scheduler.GlobalStatus.BranchOnError = false;
			Root.Scheduler.GlobalStatus.BranchOnTestIndex = "";
		}
	}

	protected FolderTest(SerializationInfo info, StreamingContext context)
	{
		name = info.GetString("Name");
	}

	public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
	{
		info.AddValue("Name", name);
	}

	public void UpdateLoopLinks()
	{
		TraceMessage.Write(ToString(), "UpdateLoopLinks " + Properties.TestName, TraceMessageType.Trace);
		try
		{
			foreach (string loopLink in Properties.LoopLinks)
			{
				BaseTest baseTest = FindTest(loopLink);
				baseTest.Properties.RemoveLoopLink(Index);
			}
			Properties.LoopLinks.Clear();
			if (FolderProperties.Scenarios == null)
			{
				return;
			}
			foreach (LoopCondition loopCondition in FolderProperties.Scenarios.LoopConditions)
			{
				if (loopCondition.LoopType != QC.QsprTestObjects.Loops.LoopTypes.BYCOUNT)
				{
					Properties.AddLoopLink(loopCondition.TestIndex);
					BaseTest baseTest2 = FindTest(loopCondition.TestIndex);
					baseTest2.Properties.AddLoopLink(Index);
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "UpdateLoopLinks " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void AddNonQTMLoopLinks()
	{
		foreach (BaseTest test in TestList)
		{
			if (test is FolderTest)
			{
				((FolderTest)test).AddNonQTMLoopLinks();
			}
		}
		if (FolderProperties.Scenarios == null)
		{
			return;
		}
		foreach (LoopCondition loopCondition in FolderProperties.Scenarios.LoopConditions)
		{
			try
			{
				if (loopCondition.LoopType != QC.QsprTestObjects.Loops.LoopTypes.BYCOUNT)
				{
					string testIndex = GetTestIndex(loopCondition.TestName);
					if (testIndex != null)
					{
						BaseTest baseTest = FindTest(testIndex);
						baseTest.Properties.AddLoopLink(Index);
						Properties.AddLoopLink(testIndex);
						loopCondition.TestIndex = testIndex;
					}
					else
					{
						int num = 1;
						num++;
					}
				}
			}
			catch (Exception ex)
			{
				TraceMessage.Write(ToString(), "AddNonQTMLoopLinks " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
			}
		}
	}

	private string GetTestIndex(string tName)
	{
		try
		{
			foreach (BaseTest test in TestList)
			{
				if (test.Properties.TestName == tName)
				{
					return test.Index;
				}
				if (test is FolderTest)
				{
					FolderTest folderTest = (FolderTest)test;
					string testIndex = folderTest.GetTestIndex(tName);
					if (testIndex != null)
					{
						return testIndex;
					}
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "GetTestIndex " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
		return null;
	}

	public void RemoveLoopTests(string strChildIndex)
	{
		TraceMessage.Write(ToString(), "RemoveLoopTests " + Properties.TestName, TraceMessageType.Trace);
		try
		{
			Properties.RemoveLoopLink(strChildIndex);
			if (FolderProperties.Scenarios == null)
			{
				return;
			}
			ArrayList arrayList = new ArrayList();
			foreach (LoopCondition loopCondition in FolderProperties.Scenarios.LoopConditions)
			{
				if (loopCondition.TestIndex == strChildIndex)
				{
					arrayList.Add(loopCondition);
				}
			}
			foreach (LoopCondition item in arrayList)
			{
				FolderProperties.Scenarios.LoopConditions.Remove(item);
			}
			if (FolderProperties.Scenarios.LoopConditions.Count == 0)
			{
				FolderProperties.Scenarios = null;
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "RemoveLoopTests " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
	}

	public override void RemoveLoopLinkTest(string strIndex)
	{
		try
		{
			foreach (BaseTest test in TestList)
			{
				TraceMessage.Write(ToString(), "RemoveLoopLinkTests " + test.Properties.TestName, TraceMessageType.Trace);
				test.RemoveLoopLinkTest(strIndex);
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "RemoveLoopLinkTests " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
	}

	public override void UpdateLoopIterations()
	{
		try
		{
			if (!RuntimeAttributes.CurrentLoopIteration.HasValue)
			{
				RuntimeAttributes.CurrentLoopIteration = 1;
				int result = 1;
				if (Properties.Scenarios != null)
				{
					LoopCondition loopCondition = (LoopCondition)Properties.Scenarios.LoopConditions[0];
					if (loopCondition.LoopType != QC.QsprTestObjects.Loops.LoopTypes.BYCOUNT)
					{
						result = ((loopCondition.LoopType == QC.QsprTestObjects.Loops.LoopTypes.BYTIME) ? 1 : loopCondition.LoopValues.Count);
					}
					else if (!int.TryParse(((LoopCondition)Properties.Scenarios.LoopConditions[0]).LoopValuesAsString, out result))
					{
						result = 1;
					}
				}
				if (Parent != null)
				{
					RuntimeAttributes.MaxLoopIteration = Parent.RuntimeAttributes.MaxLoopIteration * result;
				}
				else
				{
					RuntimeAttributes.MaxLoopIteration = result;
				}
			}
			else
			{
				RuntimeAttributes.CurrentLoopIteration++;
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write("FolderTest.UpdateLoopIterations()", "Failed to update loop iterations, exception: " + ex.ToString(), TraceMessageType.Exception);
		}
	}

	public new virtual bool UpdateLoopValues()
	{
		bool flag = true;
		try
		{
			if (FolderProperties.Scenarios != null)
			{
				int num = 1;
				foreach (LoopCondition loopCondition in FolderProperties.Scenarios.LoopConditions)
				{
					string errorMessage = "";
					if (!loopCondition.UpdateLoopValues(Root, out errorMessage, Root.Scheduler.GlobalStatus.TreeName))
					{
						if (Root.Scheduler.GlobalStatus.TestRunning || !FolderProperties.Scenarios.SuppressWarnings)
						{
							AppMessageDialog.Show("Loop values could not be updated for Folder: " + Properties.TestName + "\n" + errorMessage, "QSPR - Message Center", MessageBoxButtons.OK, MessageBoxIcon.Hand, DialogResult.OK, MessageDialogType.Warning);
						}
						flag = false;
						break;
					}
					if (loopCondition.LoopValues.Count > num)
					{
						num = loopCondition.LoopValues.Count;
					}
				}
				int count = FolderProperties.Scenarios.DontRunCondition.Count;
				int num2 = num;
				if (num2 != count)
				{
					ArrayList arrayList = (ArrayList)FolderProperties.Scenarios.ConditionCheck.Clone();
					ArrayList arrayList2 = (ArrayList)FolderProperties.Scenarios.DontRunCondition.Clone();
					ArrayList arrayList3 = (ArrayList)FolderProperties.Scenarios.Descriptions.Clone();
					FolderProperties.Scenarios.ConditionCheck = new ArrayList();
					FolderProperties.Scenarios.DontRunCondition = new ArrayList();
					FolderProperties.Scenarios.Descriptions = new ArrayList();
					for (int i = 0; i < num2; i++)
					{
						if (i < count)
						{
							FolderProperties.Scenarios.ConditionCheck.Add(arrayList[i]);
							FolderProperties.Scenarios.DontRunCondition.Add(arrayList2[i]);
							FolderProperties.Scenarios.Descriptions.Add(arrayList3[i]);
						}
						else
						{
							FolderProperties.Scenarios.ConditionCheck.Add(true);
							FolderProperties.Scenarios.DontRunCondition.Add("");
							FolderProperties.Scenarios.Descriptions.Add("");
						}
					}
				}
				FolderProperties.Scenarios.ClearBottomEmptyRows();
				if (!flag)
				{
					return flag;
				}
			}
			foreach (BaseTest test in TestList)
			{
				if (test is FolderTest)
				{
					flag = ((FolderTest)test).UpdateLoopValues();
					if (!flag)
					{
						break;
					}
				}
				else
				{
					flag = test.UpdateLoopValues();
					if (!flag)
					{
						break;
					}
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "UpdateLoopValues " + Properties.TestName + " " + ex.Message, TraceMessageType.Exception);
		}
		return flag;
	}

	public override void Display(int indent)
	{
	}

	public List<FolderTest> GetAllFolderTests(string nameToMatch = null)
	{
		List<FolderTest> list = new List<FolderTest>();
		foreach (BaseTest test in TestList)
		{
			if (test is FolderTest)
			{
				if (test.Properties.TestName == nameToMatch || nameToMatch == null)
				{
					list.Add((FolderTest)test);
				}
				list.AddRange(((FolderTest)test).GetAllFolderTests(nameToMatch));
			}
		}
		return list;
	}

	public void UpdateToolTipVisibility(Visibility visibility)
	{
		base.TestUserInterfaceProperties.ToolTipVisibility = visibility;
		foreach (BaseTest test in TestList)
		{
			test.TestUserInterfaceProperties.ToolTipVisibility = visibility;
			if (test is FolderTest)
			{
				((FolderTest)test).UpdateToolTipVisibility(visibility);
			}
		}
	}
}
