using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using QC.CTDS.DM.DataStructures.InputDataStructure;
using QC.GlobalVariableManager;
using QC.QsprShared.Config;
using QC.QsprShared.Dialogs;
using QC.QsprShared.Trace;
using QC.QsprShared.Utilities;
using QC.QsprTestObjects.Parameters;
using QC.QsprTestObjects.Registry;
using QC.QsprTestObjects.Tests.Base;
using QC.QsprTestObjects.Tests.DotNet;
using QC.QsprTestObjects.Tests.Hive;
using QC.QsprTestObjects.Tests.TestCase;
using QC.QTMDotNetKernelInterface.Environment;
using QC.QTMInterface;

namespace QC.QsprTestObjects;

public class TestMessageBroadCaster
{
	public const int iPassed = 1;

	public const int iFailed = 0;

	public const int iException = -1;

	public const int iFakeResult = int.MaxValue;

	public const string TEST = "Test";

	public const string TEST_PATH_SEPARATOR = ".";

	public const string UNIQUE_PATH_SEPARATOR = "|";

	public Scheduler Scheduler;

	protected TextOutDelegate textOutDelegate;

	protected PrintDebugDelegate printDebugDelegate;

	protected GenericMessageDelegate genericMsgDelegate;

	internal GenericParamMessageDelegate genericParamMsgDelegate;

	protected CustomMessageDelegate customMsgDelegate;

	protected Tpl2WindowDelegate tpl2WindowDelegate;

	protected HTMLWindowDelegate htmlWindowDelegate;

	protected ClearDebugMsgDelegate clearDebugDelegate;

	protected SaveDebugMsgDelegate saveDebugDelegate;

	protected ClearAllDebugMsgDelegate clearAllDebugDelegate;

	protected SaveAllDebugMsgDelegate saveAllDebugDelegate;

	protected SetDebugWindowInFocusDelegate setDebugWindowInFocusDelegate;

	internal MessageDelegate msgDelegate;

	public void OnTextOut(string windowName, string windowText)
	{
		OnTextOut(windowName, windowText, TraceLevel.Error, NoEndOfLine: false);
	}

	public void OnTextOut(string windowName, string windowText, int NoEndOfLine)
	{
		OnTextOut(windowName, windowText, TraceLevel.Error, (NoEndOfLine != 0) ? true : false);
	}

	public void OnTextOut(string windowName, string windowText, TraceLevel traceLevel)
	{
		if (textOutDelegate != null)
		{
			textOutDelegate(windowName, windowText, traceLevel, NoEndOfLine: false);
		}
	}

	public void OnTextOut(string windowName, string windowText, TraceLevel traceLevel, bool NoEndOfLine)
	{
		if (textOutDelegate != null)
		{
			textOutDelegate(windowName, windowText, traceLevel, NoEndOfLine);
		}
	}

	public void OnPrintMessages(string windowName, PrintMsgOptions IsHeader, params string[] Values)
	{
		if (printDebugDelegate != null)
		{
			printDebugDelegate(windowName, IsHeader, Values);
		}
	}

	public void OnGenericMsg(string messageType, GenericTestData data = null, byte pluginTypes = 7, string pluginNames = "")
	{
		if (genericMsgDelegate != null)
		{
			genericMsgDelegate(messageType, data, pluginTypes, pluginNames);
		}
	}

	public void OnGenericParamMsg(string messageType, string id, string name = "", string value = "", string units = "", string lowerLimit = "", string upperLimit = "", byte pluginTypes = 7, string pluginNames = "")
	{
		if (genericParamMsgDelegate != null)
		{
			genericParamMsgDelegate(messageType, id, name, value, units, lowerLimit, upperLimit, pluginTypes, pluginNames);
		}
	}

	public void OnCustomMsg(object messageData, byte pluginTypes = 7, string pluginNames = "")
	{
		if (customMsgDelegate != null)
		{
			customMsgDelegate(messageData, pluginTypes, pluginNames);
		}
	}

	public void OnTPL2Window(string windowName, Tpl2Command command, Tpl2Info Values)
	{
		if (tpl2WindowDelegate != null)
		{
			tpl2WindowDelegate(windowName, command, Values);
		}
	}

	public void OnHTMLWindow(string windowName, HTMLCommand command, string txtStr)
	{
		if (htmlWindowDelegate != null)
		{
			htmlWindowDelegate(windowName, command, txtStr);
		}
	}

	public void OnClearDebugMsg(string windowName)
	{
		if (clearDebugDelegate != null)
		{
			clearDebugDelegate(windowName);
		}
	}

	public void OnSaveDebugMsg(string windowName, bool appendText)
	{
		if (saveDebugDelegate != null)
		{
			saveDebugDelegate(windowName, appendText);
		}
	}

	public void OnClearAllDebugMsg()
	{
		if (clearAllDebugDelegate != null)
		{
			clearAllDebugDelegate();
		}
	}

	public void OnSaveAllDebugMsg(bool appendText)
	{
		if (saveAllDebugDelegate != null)
		{
			saveAllDebugDelegate(appendText);
		}
	}

	public void OnSetDebugWindowInFocusMsg(string debugWindowName)
	{
		if (setDebugWindowInFocusDelegate != null)
		{
			setDebugWindowInFocusDelegate(debugWindowName);
		}
	}

	private void LogTestExceptionToEventLogs(string testName, object parameter)
	{
		try
		{
			Exception ex = (Exception)parameter;
			string empty = string.Empty;
			empty = empty + "Exception has been thrown by the test." + Environment.NewLine;
			empty = empty + "Tree Name : " + Scheduler.GlobalStatus.TreeName + Environment.NewLine;
			empty = empty + "Test Name : " + testName + Environment.NewLine;
			empty = empty + "Exception Message : " + ex.Message + Environment.NewLine;
			empty = empty + "InnerException Message : " + ex.InnerException.Message + Environment.NewLine;
			empty = empty + "Stack Trace : " + ex.StackTrace + Environment.NewLine;
			QTMUtility.WriteToEventLog("QSPR Test Level Exception", empty);
		}
		catch
		{
		}
	}

	public void OnTestDone(string testName, int iResult, object parameters)
	{
		TraceMessage.WriteAlways(ToString(), "ENTER: TestMessageBroadCaster.OnTestDone(" + testName + ")", TraceMessageType.Trace);
		Scheduler.GlobalStatus.ProcessingTestDone = true;
		DateTime now = DateTime.Now;
		TraceMessage.WriteAlways(ToString(), "Getting current test result details for " + testName, TraceMessageType.Trace);
		TestResultDetails currentTestDetails = Scheduler.Env.QTMInfo.GetCurrentTestDetails();
		((QTMRegistry)Scheduler.QTMData.theRegistry).SetGlobalVariable("CurrentTestDetails", null);
		if (Scheduler.GlobalStatus.Abort)
		{
			return;
		}
		Scheduler.mutTest.WaitOne();
		BaseTest baseTest = null;
		TestResult testResult = TestResult.Failed;
		try
		{
			if (iResult == 2)
			{
				LogTestExceptionToEventLogs(testName, parameters);
			}
			baseTest = (BaseTest)Scheduler.ListOfTestsRunning[testName.Trim()];
			if (baseTest != null)
			{
				if (iResult == 2 && baseTest.Properties.TreatExceptionAsError)
				{
					string text = "Exception was thrown by " + testName + ": ";
					if (parameters != null)
					{
						try
						{
							Exception ex = (Exception)parameters;
							text = ((ex.InnerException == null) ? (text + ex.Message) : (text + ex.InnerException.Message));
						}
						catch
						{
						}
					}
					else
					{
						text += "Unknown error";
					}
					OnTextOut("Error", text, TraceLevel.Error);
					iResult = 0;
				}
				switch (iResult)
				{
				case 2:
					testResult = TestResult.Exception;
					baseTest.RuntimeAttributes.Exception = true;
					if (parameters != null)
					{
						try
						{
							Exception ex2 = (Exception)parameters;
							ExceptionDialog exceptionDialog = new ExceptionDialog(ex2);
							exceptionDialog.Show();
						}
						catch
						{
						}
					}
					Scheduler.GlobalStatus.GlobalTestResult = TestResult.Exception;
					break;
				case 7:
					testResult = TestResult.Skipped;
					baseTest.RuntimeAttributes.Skipped = true;
					break;
				default:
				{
					TraceMessage.WriteAlways(ToString(), "Test passed, updating parameter info for " + testName, TraceMessageType.Trace);
					bool flag = baseTest is HiveTest;
					baseTest.Properties.Parameters.UpdateParameters(parameters, flag);
					baseTest.Properties.Parameters.UpdateToGlobalVariables(Scheduler.RootFolder);
					if (!flag)
					{
						ArrayList additionalOutputParamaters = Scheduler.Env.QTMInfo.GetAdditionalOutputParamaters();
						if (additionalOutputParamaters.Count > 0)
						{
							flag = true;
						}
						Dictionary<string, ArrayList> dictionary = new Dictionary<string, ArrayList>();
						foreach (ParamValue item in additionalOutputParamaters)
						{
							dictionary.Add(item.ParamName, item.EnabledCharting);
						}
						baseTest.Properties.Parameters.UpdateParameters(baseTest.GetDynamicOutputParametersObjectArray(), flag, dictionary);
					}
					if (!(baseTest is FolderTest))
					{
						Scheduler.RootFolder.UpdateDynamicLimits(baseTest);
					}
					if (iResult > 0 && baseTest.Properties.TestResultBasedOnLimits && !baseTest.Properties.Parameters.OutputParametersInLimits)
					{
						iResult = 0;
					}
					if (iResult > 0)
					{
						testResult = TestResult.Passed;
						baseTest.RuntimeAttributes.HasPassedOnce = true;
						break;
					}
					testResult = TestResult.Failed;
					baseTest.Properties.Parameters.UpdateParameters(parameters, flag);
					Scheduler.SetDebugMessage(baseTest.Properties.TestName + " Failed ", Scheduler.SoundLevel.CRITICAL);
					if (!baseTest.Properties.BookKeeping)
					{
						if (!Scheduler.GlobalStatus.TestMsgHold && Scheduler.GlobalStatus.GlobalTestResult == TestResult.Passed)
						{
							Scheduler.GlobalStatus.GlobalTestResult = TestResult.Failed;
						}
						baseTest.RuntimeAttributes.Failed = true;
						baseTest.RuntimeAttributes.HasFailedOnce = true;
						baseTest.RuntimeAttributes.StopOnError = baseTest.Properties.StopOnError;
						switch (baseTest.RuntimeAttributes.StopOnError)
						{
						case StopOnErrorTypes.CompleteStop:
							((QTMRegistry)Scheduler.QTMData.theRegistry).SetGlobalVariable("QSPR_STOP_ON_ERROR", "CompleteStop");
							break;
						case StopOnErrorTypes.CompleteStopNoRetry:
							((QTMRegistry)Scheduler.QTMData.theRegistry).SetGlobalVariable("QSPR_STOP_ON_ERROR", "CompleteStopNoRetry");
							break;
						}
					}
					Scheduler.AddFailedTest(baseTest);
					break;
				}
				}
				if (baseTest.Properties.DescriptionName == "")
				{
					Scheduler.GlobalStatus.LoopDetails = Scheduler.GlobalStatus.LoopDetailsComplete;
					baseTest.Properties.DescriptionName = baseTest.Properties.TestName;
				}
				TraceMessage.WriteAlways(ToString(), "Creating TestMessage for " + testName, TraceMessageType.Trace);
				TestMessage tMessage = default(TestMessage);
				tMessage.Duration = now - baseTest.RuntimeAttributes.TestStartTime;
				tMessage.Message = baseTest.Properties.DescriptionName;
				tMessage.NodeRID = baseTest.Properties.NodeRID;
				if (baseTest is HiveTest)
				{
					tMessage.Object = new ArrayList();
				}
				else
				{
					tMessage.Object = baseTest.Properties.Parameters.GetParameterExportList(onlyLoggedParameters: true, outputOnly: true, baseTest.Properties.IgnoreEmptyStringParameters);
				}
				if (baseTest.Properties.BookKeeping)
				{
					tMessage.Result = TestResult.Passed;
				}
				else
				{
					tMessage.Result = testResult;
					if (testResult != TestResult.Passed)
					{
						tMessage.ErrorCode = baseTest.Properties.TestErrorCode;
					}
				}
				baseTest.Properties.TestResult = testResult == TestResult.Passed;
				tMessage.TestIndex = baseTest.Index;
				string gvValue = "";
				Scheduler.Env.GlobalVariable.GetGlobalVariable("CURRENT_UNIT_INDEX", out gvValue);
				int result = 0;
				int.TryParse(gvValue, out result);
				tMessage.UnitIndex = result;
				string gvValue2 = "";
				Scheduler.Env.GlobalVariable.GetGlobalVariable("SN", out gvValue2);
				tMessage.SerialNumber = gvValue2;
				if (baseTest.Properties.DataLoggingOnlyOnFailure && testResult == TestResult.Passed)
				{
					tMessage.DoNotSendToPlugins = false;
					tMessage.Object = new ArrayList();
				}
				if (baseTest.Parent is TestCaseTest)
				{
					tMessage.DoNotSendToPlugins = false;
				}
				tMessage.TestPathInTree = baseTest.TestPath;
				tMessage.TestCaseID = -1L;
				tMessage.TestCaseRefID = Scheduler.RootFolder.GetTestCaseRefID(baseTest);
				tMessage.RealName = baseTest.Properties.RealName;
				tMessage.LimitsEnforced = baseTest.Properties.TestResultBasedOnLimits;
				try
				{
					string testModulePath = ((QTMRegistry)Scheduler.QTMData.theRegistry).GetTestModulePath(baseTest);
					FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(testModulePath);
					tMessage.ContainerInfo = new TestContainerInfo
					{
						FileName = Path.GetFileName(testModulePath),
						Version = versionInfo.FileVersion
					};
				}
				catch (Exception ex3)
				{
					TraceMessage.Write("BaseTest.OnTestDone", "Exception caught when trying to get test container info:" + Environment.NewLine + ex3.ToString(), TraceMessageType.Exception);
				}
				tMessage.ResultDetails = currentTestDetails;
				tMessage.IsApprovedTestPlan = Scheduler.GetIsApprovedTestPlan();
				tMessage.TestStopTime = now;
				tMessage.CurrentLoopIteration = baseTest.RuntimeAttributes.CurrentLoopIteration;
				tMessage.MaxLoopIteration = baseTest.RuntimeAttributes.MaxLoopIteration;
				baseTest.SetTestStartAndStopTimes(ref tMessage);
				if (testResult == TestResult.Skipped)
				{
					msgDelegate(TestMsgType.OnTestSkipped, tMessage);
				}
				else
				{
					msgDelegate(TestMsgType.OnTestResult, tMessage);
				}
				baseTest.Properties.DescriptionName = "";
				TraceMessage.WriteAlways(ToString(), "Checking Post Condition for " + testName, TraceMessageType.Trace);
				if (baseTest.Properties.PostCondition != null && baseTest.Properties.PostConditionAction != PostConditionActions.None.ToString() && baseTest.Properties.PostCondition.Enabled && baseTest.Properties.PostCondition.IsConditionMet(baseTest.Properties.Parameters, testResult) && (!Scheduler.GlobalStatus.TestMsgHold || baseTest.Properties.PostCondition.Action == PostConditionActions.CompleteStopNoRetry))
				{
					if (baseTest.Properties.PostCondition.Action == PostConditionActions.Branch)
					{
						Scheduler.GlobalStatus.BranchOnError = true;
						string branchOnTestIndex = baseTest.Properties.PostCondition.BranchTestIndex.Trim();
						if (baseTest.Properties.PostCondition.BranchByTestName)
						{
							BaseTest baseTest2 = baseTest.Root.FindTestFromTestName(baseTest.Properties.PostCondition.BranchOnTestName, isPartialName: false, baseTest.Index);
							if (baseTest2 != null)
							{
								branchOnTestIndex = baseTest2.Index;
							}
						}
						Scheduler.GlobalStatus.BranchOnTestIndex = branchOnTestIndex;
					}
					else
					{
						baseTest.RuntimeAttributes.PostConditionAction = baseTest.Properties.PostCondition.Action;
					}
					if (baseTest.Properties.PostCondition.Action == PostConditionActions.PauseTestTree)
					{
						Scheduler.GlobalStatus.Pause = true;
					}
					if (baseTest.Properties.PostCondition.Action == PostConditionActions.CompleteStopNoRetry)
					{
						if (Scheduler.GlobalStatus.TestMsgHold)
						{
							Scheduler.GlobalStatus.TestMsgHold = false;
						}
						testResult = TestResult.Exception;
					}
				}
			}
			TraceMessage.WriteAlways(ToString(), "Calling CheckToBailOut for " + testName, TraceMessageType.Trace);
			CheckToBailOut(baseTest);
			if (baseTest.Properties.PauseTreeOnCompletion)
			{
				Scheduler.GlobalStatus.Pause = true;
			}
		}
		catch
		{
			testResult = TestResult.Exception;
		}
		finally
		{
			((QTMRegistry)Scheduler.QTMData.theRegistry).SetGlobalVariable("CurrentTestDetails", null);
			if (testResult == TestResult.Exception)
			{
				Scheduler.GlobalStatus.Abort = true;
			}
			if (Scheduler.ListOfTestsRunning.ContainsKey(testName.Trim()))
			{
				Scheduler.ListOfTestsRunning.Remove(testName.Trim());
			}
			Scheduler.mutTest.ReleaseMutex();
			Scheduler.GlobalStatus.ProcessingTestDone = false;
			TraceMessage.WriteAlways(ToString(), "EXIT: TestMessageBroadCaster.OnTestDone(" + testName + ")", TraceMessageType.Trace);
		}
	}

	private void CheckToBailOut(BaseTest currentTest)
	{
		bool flag = false;
		try
		{
			if (currentTest.CurrentResult == TestResult.Failed || currentTest.CurrentResult == TestResult.Exception)
			{
				Scheduler.GlobalStatus.FailedTests++;
				Scheduler.GlobalStatus.ConsectiveFailedTests++;
			}
			else if (currentTest.CurrentResult == TestResult.Passed)
			{
				Scheduler.GlobalStatus.ConsectiveFailedTests = 0;
			}
			if (Scheduler.GlobalStatus.BailOutLogic == BailOutLogicSelection.Both || Scheduler.GlobalStatus.BailOutLogic == BailOutLogicSelection.Tests)
			{
				if ((int)Scheduler.GlobalStatus.BailOutLogicFixedNumber > 0 && Scheduler.GlobalStatus.FailedTests >= (int)Scheduler.GlobalStatus.BailOutLogicFixedNumber)
				{
					flag = true;
				}
				else if ((int)Scheduler.GlobalStatus.BailOutLogicFixedNumberConsective > 0 && Scheduler.GlobalStatus.ConsectiveFailedTests >= (int)Scheduler.GlobalStatus.BailOutLogicFixedNumberConsective)
				{
					flag = true;
				}
				else if ((int)Scheduler.GlobalStatus.BailOutLogicFixedPercentage > 0 && Math.Round(Scheduler.GlobalStatus.BailOutLogicFixedPercentage * (double)Scheduler.GlobalStatus.TotalSelectedTests / 100.0) >= 1.0 && (double)Scheduler.GlobalStatus.FailedTests >= Math.Round(Scheduler.GlobalStatus.BailOutLogicFixedPercentage * (double)Scheduler.GlobalStatus.TotalSelectedTests / 100.0))
				{
					flag = true;
				}
				else if ((int)Scheduler.GlobalStatus.BailOutLogicFixedPercentageConsective > 0 && Math.Round(Scheduler.GlobalStatus.BailOutLogicFixedPercentageConsective * (double)Scheduler.GlobalStatus.TotalSelectedTests / 100.0) >= 1.0 && (double)Scheduler.GlobalStatus.ConsectiveFailedTests >= Math.Round(Scheduler.GlobalStatus.BailOutLogicFixedPercentageConsective * (double)Scheduler.GlobalStatus.TotalSelectedTests / 100.0))
				{
					flag = true;
				}
			}
		}
		catch
		{
			flag = false;
		}
		if (flag)
		{
			Scheduler.GlobalStatus.BailedOut = true;
			GVData gVData = default(GVData);
			gVData.Name = "SessionBailedOut".ToUpper();
			gVData.Value = Scheduler.GlobalStatus.BailedOut.ToString();
			if (QTMGlobalVariable.GVariables.ContainsKey("SessionBailedOut".ToUpper()))
			{
				QTMGlobalVariable.SetGlobalVariable("SessionBailedOut".ToUpper(), gVData.Value);
			}
			else
			{
				QTMGlobalVariable.GVariables.Add("SessionBailedOut".ToUpper(), gVData);
			}
			Scheduler.GlobalStatus.Abort = true;
		}
	}

	private static void GetInputParamInfoFromTestParameters(BaseTest test, out Dictionary<string, QC.CTDS.DM.DataStructures.InputDataStructure.ParamInfo> inputParamInfos, out List<string> outputParamNames)
	{
		inputParamInfos = new Dictionary<string, QC.CTDS.DM.DataStructures.InputDataStructure.ParamInfo>(StringComparer.Ordinal);
		outputParamNames = new List<string>();
		foreach (ParameterCls parameter in test.Properties.Parameters)
		{
			ParameterCls.GetIsArray(parameter, test is DotNetTest, test.RealName, "");
			if (parameter.Type == IOType.Input)
			{
				QC.CTDS.DM.DataStructures.InputDataStructure.ParamInfo paramInfo = new QC.CTDS.DM.DataStructures.InputDataStructure.ParamInfo();
				paramInfo.StrVal = parameter.Value;
				paramInfo.ParamUnit = parameter.Unit;
				QC.CTDS.DM.DataStructures.InputDataStructure.ParamInfo paramInfo2 = paramInfo;
				if (double.TryParse(parameter.Value, out var result))
				{
					paramInfo2.Val = result;
				}
				inputParamInfos.Add(parameter.Name, paramInfo2);
			}
			else if (parameter.Type == IOType.Output)
			{
				outputParamNames.Add(parameter.Name);
			}
		}
	}

	public void SetTextOutDelegate(TextOutDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetTextOutDelegate", TraceMessageType.Trace);
		try
		{
			textOutDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetTextOutDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void SetPrintDebugDelegate(PrintDebugDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetPrintDebugDelegate", TraceMessageType.Trace);
		try
		{
			printDebugDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetPrintDebugDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void SetOnGenericMessageDelegate(GenericMessageDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetOnGenericMessageDelegate", TraceMessageType.Trace);
		try
		{
			genericMsgDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetOnGenericMessageDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void SetOnGenericParamMessageDelegate(GenericParamMessageDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetOnGenericParamMessageDelegate", TraceMessageType.Trace);
		try
		{
			genericParamMsgDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetOnGenericParamMessageDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void SetOnCustomMessageDelegate(CustomMessageDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetOnCustomMessageDelegate", TraceMessageType.Trace);
		try
		{
			customMsgDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetOnCustomMessageDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void SetOnTpl2WindowDelegate(Tpl2WindowDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetOnTpl2WindowDelegate", TraceMessageType.Trace);
		try
		{
			tpl2WindowDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetOnTpl2WindowDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void SetOnHTMLWindowDelegate(HTMLWindowDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetOnHTMLWindowDelegate", TraceMessageType.Trace);
		try
		{
			htmlWindowDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetOnHTMLWindowDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void SetClearDebugMessageDelegate(ClearDebugMsgDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetClearDebugDelegate", TraceMessageType.Trace);
		try
		{
			clearDebugDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetClearDebugDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void SetSaveDebugMessageDelegate(SaveDebugMsgDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetSaveDebugDelegate", TraceMessageType.Trace);
		try
		{
			saveDebugDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetSaveDebugDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void SetClearAllDebugDelegate(ClearAllDebugMsgDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetClearAllDebugDelegate", TraceMessageType.Trace);
		try
		{
			clearAllDebugDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetClearAllDebugDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void SetSaveAllDebugDelegate(SaveAllDebugMsgDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetSaveAllDebugDelegate", TraceMessageType.Trace);
		try
		{
			saveAllDebugDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetSaveAllDebugDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void SetDebugWindowInFocusDelegate(SetDebugWindowInFocusDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetDebugWindowInFocusDelegate", TraceMessageType.Trace);
		try
		{
			setDebugWindowInFocusDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetDebugWindowInFocusDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	public void SetMessageDelegate(MessageDelegate SomeFunction)
	{
		TraceMessage.Write("QC.QTMApp.BaseTest", "SetMessageDelegate", TraceMessageType.Trace);
		try
		{
			msgDelegate = SomeFunction;
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApp.BaseTest", "SetMessageDelegate " + ex.Message, TraceMessageType.Exception);
		}
	}

	internal void SetDebugMessage(string msg)
	{
		TraceMessage.Write(ToString(), "SetDebugMessage " + msg, TraceMessageType.Trace);
		try
		{
			if (msgDelegate != null)
			{
				TestMessage message = default(TestMessage);
				message.Message = msg;
				message.Object = null;
				message.Result = TestResult.Passed;
				msgDelegate(TestMsgType.OnDebugMsg, message);
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "SetDebugMessage " + msg + " " + ex.Message, TraceMessageType.Exception);
		}
	}
}
