using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Windows.Forms;
using System.Xml.Serialization;
using QC.QsprShared.Dialogs;
using QC.QsprShared.GlobalData;
using QC.QsprTestObjects.Loops;
using QC.QsprTestObjects.Metadata;
using QC.QsprTestObjects.Parameters;
using QC.QsprTestObjects.TestConditions;

namespace QC.QsprTestObjects.Tests.Base;

[Serializable]
public class TestProperties : INotifyPropertyChanged
{
	public const int TOOL = 0;

	public const int FOLDER_MUST_RUN = 1;

	public const int TREE_MUST_RUN = 2;

	private const int RUN_ONCE = 3;

	private const int SERIAL = 4;

	private const int CONCURRENT = 5;

	private const int PAUSE_TREE_ON_COMPLETION = 6;

	private const int TEST_MUST_RUN = 7;

	private const int LAST_UNUSED = 8;

	public const string TEST_PROPERTY = "TestProperty";

	protected string strRealName = "";

	private string strTestName = "Test Name";

	private StopOnErrorTypes typeStopOnError;

	private bool treatExceptionAsError;

	private string desc = "";

	private bool ignoreEmptyParam;

	private string branchOnErrorName = "";

	private string branchOnErrorIndex = "";

	private bool branchOnErrorByName;

	private ConditionMgr postConditionMgr;

	private ConditionMgr preConditionMgr;

	private MetadataItems metadata;

	private bool bookKeeping;

	private int testTimeOut;

	private TimeOutActions timeOutAction;

	protected string testErrorCode = "";

	protected bool skipWhenLinked;

	protected string notes = "";

	private bool linkNode;

	protected ArrayList loopLinks = new ArrayList();

	private BitArray bAttributeArray = new BitArray(8, defaultValue: false);

	protected CheckState checkStateTest = CheckState.Checked;

	protected long nodeRID = -1L;

	protected int numberOfTests = 1;

	protected string descriptionName = "";

	protected ParameterCollection parameters = new ParameterCollection();

	protected string targetName = "This PC";

	protected bool expanded;

	protected bool testResultBasedOnLimits;

	protected bool dataLoggingOnlyOnFailure;

	private BaseTest owner;

	private string testIndex;

	private int retryCount;

	protected bool isSelected;

	private bool refreshLoopValues;

	private string comment;

	protected LoopScenarioValues loopScenario;

	private bool? isLinkActive = null;

	private BreakPointTypes enableBreakPoint;

	private bool enableLogging = true;

	private bool testResult;

	private bool loopingInstance;

	private bool isSetupTestStep;

	private bool isTearDownTestStep;

	private bool canAddToTestPlan;

	private bool isManual;

	[Browsable(false)]
	[XmlIgnore]
	public BaseTest Owner
	{
		get
		{
			return owner;
		}
		set
		{
			owner = value;
		}
	}

	[DefaultValue(false)]
	[Browsable(false)]
	public bool Expanded
	{
		get
		{
			return expanded;
		}
		set
		{
			expanded = value;
			RaisePropertyChanged("Expanded");
		}
	}

	[XmlIgnore]
	[Browsable(false)]
	public string TestIndexCopy
	{
		get
		{
			return testIndex;
		}
		set
		{
			testIndex = value;
		}
	}

	[XmlIgnore]
	[Browsable(false)]
	public virtual bool IsSelected
	{
		get
		{
			return isSelected;
		}
		set
		{
			bool flag = isSelected != value;
			isSelected = value;
			if (flag)
			{
				RaisePropertyChanged("IsSelected");
			}
		}
	}

	[Category("Settings")]
	[Description("Test name used for data collection and display.")]
	public virtual string TestName
	{
		get
		{
			return strTestName;
		}
		set
		{
			if (value != null && (value == null || value.Trim().Length != 0))
			{
				strTestName = value.Trim();
				RaisePropertyChanged("TestName");
			}
		}
	}

	[Description("Notifies scheduler what action to be taken when test fails.")]
	[Category("Attributes")]
	[DefaultValue(StopOnErrorTypes.None)]
	public virtual StopOnErrorTypes StopOnError
	{
		get
		{
			return typeStopOnError;
		}
		set
		{
			if (BranchOnError.Trim() == "" || value == StopOnErrorTypes.None)
			{
				typeStopOnError = value;
				return;
			}
			DialogResult dialogResult = AppMessageDialog.Show("A test cannot have branch on error and stop on error set at the same time.\nBranch On Error will be modified for " + TestName, "QSPR - Message Center", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, DialogResult.OK, MessageDialogType.UIWarning);
			if (dialogResult == DialogResult.OK)
			{
				branchOnErrorIndex = "";
				branchOnErrorName = "";
				typeStopOnError = value;
			}
		}
	}

	[Category("Attributes")]
	[Description("If true, exceptions thrown by the test will result in a standard failure. No popup will display, and all StopOnError/BranchOnError actions will be taken.")]
	[DefaultValue(false)]
	public virtual bool TreatExceptionAsError
	{
		get
		{
			return treatExceptionAsError;
		}
		set
		{
			treatExceptionAsError = value;
		}
	}

	[DefaultValue(false)]
	[Category("Attributes")]
	[Description("Refreshes the Loop values from a file or GV just before starting the Looping")]
	public bool RefreshLoopValuesAtLoopStart
	{
		get
		{
			return refreshLoopValues;
		}
		set
		{
			refreshLoopValues = value;
		}
	}

	[Description("Original name of the test when it was created.")]
	[DefaultValue("")]
	[Category("Settings")]
	[ReadOnly(true)]
	public virtual string RealName
	{
		get
		{
			return strRealName;
		}
		set
		{
			strRealName = value;
		}
	}

	[Category("Target")]
	[DefaultValue("This PC")]
	[ReadOnly(true)]
	[Description("Target name of the test.")]
	public virtual string TargetName
	{
		get
		{
			return targetName;
		}
		set
		{
			targetName = value;
		}
	}

	[Category("Settings")]
	[DefaultValue("")]
	[Description("Additional description about the test.")]
	public virtual string Description
	{
		get
		{
			return desc;
		}
		set
		{
			desc = value;
		}
	}

	[Category("Settings")]
	[DefaultValue("")]
	[Description("Comments for the test.")]
	public virtual string Comment
	{
		get
		{
			return comment;
		}
		set
		{
			comment = value;
		}
	}

	[Category("Settings")]
	[Description("Specifies the number of times to run the test before it passes. Eg. 2 means the test will run a total of 2 times.")]
	[DefaultValue(0)]
	public int RetryCount
	{
		get
		{
			return retryCount;
		}
		set
		{
			if (retryCount == value)
			{
				return;
			}
			if (value < 0)
			{
				AppMessageDialog.Show("Retry count should be greater than 0 or more", DialogResult.OK, MessageDialogType.UIWarning);
				return;
			}
			if (value == 0)
			{
				Scenarios = null;
				retryCount = value;
				return;
			}
			if (retryCount == 0 && loopScenario != null && AppMessageDialog.Show("Test already has looping setup. Changing Retry count will reset looping.. \n  Do You want to continue? ", "Loop Setup", MessageBoxButtons.YesNo, DialogResult.Yes, MessageDialogType.UIWarning) == DialogResult.No)
			{
				retryCount = 0;
				return;
			}
			if (Owner != null)
			{
				loopScenario = LoopScenarioValues.CreateRetyrLoop(TestName, TestIndexCopy, value, Owner.Root);
			}
			retryCount = value;
		}
	}

	[Browsable(false)]
	public LoopScenarioValues Scenarios
	{
		get
		{
			return loopScenario;
		}
		set
		{
			loopScenario = value;
		}
	}

	[Editor(typeof(LoopSetupUITypeEditor), typeof(UITypeEditor))]
	[XmlIgnore]
	[Description("Specifies the looping for the test.\nUse Loop setup dialog to edit this property.")]
	[Category("Settings")]
	public virtual string LoopSetup
	{
		get
		{
			if (Scenarios != null)
			{
				return "True";
			}
			return "False";
		}
		set
		{
		}
	}

	[DefaultValue("")]
	[Browsable(false)]
	public string BranchOnErrorName
	{
		get
		{
			return branchOnErrorName;
		}
		set
		{
			branchOnErrorName = value;
		}
	}

	[DefaultValue("")]
	[Browsable(false)]
	public string BranchOnErrorIndex
	{
		get
		{
			return branchOnErrorIndex;
		}
		set
		{
			branchOnErrorIndex = value;
		}
	}

	[DefaultValue(false)]
	[Browsable(false)]
	public bool BranchOnErrorByName
	{
		get
		{
			return branchOnErrorByName;
		}
		set
		{
			branchOnErrorByName = value;
		}
	}

	[DefaultValue(CheckState.Checked)]
	[Browsable(false)]
	public CheckState CheckStateTest
	{
		get
		{
			return checkStateTest;
		}
		set
		{
			bool flag = checkStateTest != value;
			checkStateTest = value;
			if (flag)
			{
				RaisePropertyChanged("CheckStateTest");
			}
		}
	}

	[DefaultValue(false)]
	[Browsable(false)]
	[XmlIgnore]
	public bool LinkNode
	{
		get
		{
			return linkNode;
		}
		set
		{
			linkNode = value;
		}
	}

	[Browsable(false)]
	[DefaultValue(null)]
	public bool? IsLinkActive
	{
		get
		{
			return isLinkActive;
		}
		set
		{
			isLinkActive = value;
		}
	}

	[Category("Attributes")]
	[DefaultValue("")]
	[Description("Specifies the test to run on error.")]
	[Editor(typeof(BranchTreeUITypeEditor), typeof(UITypeEditor))]
	public virtual string BranchOnError
	{
		get
		{
			return branchOnErrorName;
		}
		set
		{
			string[] array = value.Trim().Split(';');
			if (array.Length >= 2)
			{
				if (typeStopOnError != 0)
				{
					DialogResult dialogResult = AppMessageDialog.Show("A test cannot have branch on error and stop on error set at the same time.\nStopOnError will be modified for " + TestName, "QSPR - Message Center", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, DialogResult.OK, MessageDialogType.UIWarning);
					if (dialogResult != DialogResult.OK)
					{
						return;
					}
					typeStopOnError = StopOnErrorTypes.None;
				}
				branchOnErrorName = array[0];
				branchOnErrorIndex = array[1];
				bool result = false;
				if (array.Length == 3 && bool.TryParse(array[2], out result))
				{
					branchOnErrorByName = result;
				}
				else
				{
					branchOnErrorByName = false;
				}
			}
			else if (value.Trim() == "")
			{
				branchOnErrorName = "";
				branchOnErrorIndex = "";
				branchOnErrorByName = false;
			}
			else if (!(value.Trim() == branchOnErrorName))
			{
				Owner.Root.Scheduler.SetDebugMessage("Choose node from Branch on error UI", Scheduler.SoundLevel.INFO);
			}
		}
	}

	[Editor(typeof(PostConditionUITypeEditor), typeof(UITypeEditor))]
	[XmlIgnore]
	[Description("Specifies the post condition for the test.\nUse Post Condition dialog to edit this property.")]
	[Category("Settings")]
	public virtual string PostConditionAction
	{
		get
		{
			if (postConditionMgr != null && postConditionMgr.Enabled)
			{
				return postConditionMgr.Action.ToString();
			}
			return "None";
		}
		set
		{
		}
	}

	[Category("Attributes")]
	[DefaultValue(false)]
	[Description("Pause Tree On Completion Of Test.")]
	public virtual bool PauseTreeOnCompletion
	{
		get
		{
			return bAttributeArray[6];
		}
		set
		{
			bAttributeArray[6] = value;
		}
	}

	[Browsable(false)]
	public virtual ConditionMgr PostCondition
	{
		get
		{
			return postConditionMgr;
		}
		set
		{
			postConditionMgr = value;
		}
	}

	[Category("Settings")]
	[Description("Specifies the pre condition for the test.\nUse Pre Condition dialog to edit this property.")]
	[XmlIgnore]
	[Editor(typeof(PreConditionUITypeEditor), typeof(UITypeEditor))]
	public virtual string PreConditionEnabled
	{
		get
		{
			if (preConditionMgr != null)
			{
				return preConditionMgr.IsValid.ToString();
			}
			return "False";
		}
		set
		{
		}
	}

	[Browsable(false)]
	public virtual ConditionMgr PreCondition
	{
		get
		{
			return preConditionMgr;
		}
		set
		{
			preConditionMgr = value;
		}
	}

	[Browsable(false)]
	public virtual MetadataItems Metadata
	{
		get
		{
			return metadata;
		}
		set
		{
			metadata = value;
		}
	}

	[Editor(typeof(MetadataUITypeEditor), typeof(UITypeEditor))]
	[Description("Specifies test parameters and/or global variables that should be logged as input conditions for this test.")]
	[XmlIgnore]
	[Category("Settings")]
	public virtual string MetadataEnabled
	{
		get
		{
			if (metadata != null)
			{
				return "True";
			}
			return "False";
		}
		set
		{
		}
	}

	[DefaultValue(false)]
	[Category("Settings")]
	[Description("Always return true as test result")]
	public virtual bool BookKeeping
	{
		get
		{
			return bookKeeping;
		}
		set
		{
			bookKeeping = value;
		}
	}

	[Category("Attributes")]
	[Description("When true, Empty string parameters will not be logged in data collection")]
	[DefaultValue(false)]
	public bool IgnoreEmptyStringParameters
	{
		get
		{
			return ignoreEmptyParam;
		}
		set
		{
			ignoreEmptyParam = value;
		}
	}

	[Browsable(false)]
	[XmlElement(Type = typeof(string))]
	public ArrayList LoopLinks
	{
		get
		{
			return loopLinks;
		}
		set
		{
			loopLinks = value;
		}
	}

	[Category("Attributes")]
	[Description("Test runs only from context menu or if branch on error is set on it.")]
	[DefaultValue(false)]
	public virtual bool ToolTest
	{
		get
		{
			return bAttributeArray[0];
		}
		set
		{
			if ((!bAttributeArray[2] && !bAttributeArray[1]) || !value)
			{
				bAttributeArray[0] = value;
				return;
			}
			DialogResult dialogResult = AppMessageDialog.Show("A test cannot be must run and tool process at the same time.\nMustRun will be modified for " + TestName, "QSPR - Message Center", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, DialogResult.OK, MessageDialogType.UIWarning);
			if (dialogResult == DialogResult.OK)
			{
				bAttributeArray[2] = false;
				bAttributeArray[1] = false;
				bAttributeArray[0] = value;
			}
		}
	}

	[Category("Attributes")]
	[DefaultValue(false)]
	[Description("Test runs if any test in the tree runs.")]
	public virtual bool TreeMustRun
	{
		get
		{
			return bAttributeArray[2];
		}
		set
		{
			if (!bAttributeArray[0] || !value)
			{
				bAttributeArray[2] = value;
				return;
			}
			DialogResult dialogResult = AppMessageDialog.Show("A test cannot be must run and tool process at the same time.\nTool property will be modified for " + TestName, "QSPR - Message Center", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, DialogResult.OK, MessageDialogType.UIWarning);
			if (dialogResult == DialogResult.OK)
			{
				bAttributeArray[0] = false;
				bAttributeArray[2] = value;
			}
		}
	}

	[DefaultValue(false)]
	[Category("Attributes")]
	[Description("Test Must Always Run, even if not selected as well as for each Rerun iteration.")]
	public virtual bool MustRunTest
	{
		get
		{
			return bAttributeArray[7];
		}
		set
		{
			if (!bAttributeArray[0] || !value)
			{
				bAttributeArray[7] = value;
				return;
			}
			DialogResult dialogResult = AppMessageDialog.Show("A test cannot be must run and tool process at the same time.\nTool property will be modified for " + TestName, "QSPR - Message Center", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, DialogResult.OK, MessageDialogType.UIWarning);
			if (dialogResult == DialogResult.OK)
			{
				bAttributeArray[0] = false;
				bAttributeArray[7] = value;
			}
		}
	}

	[Category("Settings")]
	[Description("The error code string will be set when the test fails. The GoNoGo result will reflect the first error code set during the GoNoGo")]
	[DefaultValue("")]
	public string TestErrorCode
	{
		get
		{
			return testErrorCode;
		}
		set
		{
			testErrorCode = value;
		}
	}

	[Description("If true, skip this test when linked to another tree.")]
	[Category("Settings")]
	[DefaultValue(false)]
	public virtual bool SkipWhenLinked
	{
		get
		{
			return skipWhenLinked;
		}
		set
		{
			skipWhenLinked = value;
		}
	}

	[Browsable(false)]
	[DefaultValue("")]
	public virtual string Notes
	{
		get
		{
			return notes;
		}
		set
		{
			notes = value;
		}
	}

	[Category("Debug")]
	[Description("When set, test execution is paused at this test. Click Resume Tree to continue.")]
	[DefaultValue(BreakPointTypes.None)]
	public BreakPointTypes BreakPoint
	{
		get
		{
			return enableBreakPoint;
		}
		set
		{
			enableBreakPoint = value;
		}
	}

	[Description("If enabled, debug messages for this test will be logged.")]
	[Category("Debug")]
	[DefaultValue(true)]
	public bool LoggingEnabled
	{
		get
		{
			return enableLogging;
		}
		set
		{
			enableLogging = value;
		}
	}

	[Category("Attributes")]
	[Description("If TRUE, the Pass result is verified with the Upper and Lower Limits.")]
	[DefaultValue(false)]
	public virtual bool TestResultBasedOnLimits
	{
		get
		{
			return testResultBasedOnLimits;
		}
		set
		{
			testResultBasedOnLimits = value;
		}
	}

	[Description("If TRUE, data is collected only if test FAILs.")]
	[Category("Attributes")]
	[DefaultValue(false)]
	public virtual bool DataLoggingOnlyOnFailure
	{
		get
		{
			return dataLoggingOnlyOnFailure;
		}
		set
		{
			dataLoggingOnlyOnFailure = value;
		}
	}

	[Category("Settings")]
	[Description("Specifies the length of time in seconds before test times out and is stopped.\nA zero value indicates that test will not time out.")]
	[DefaultValue(0)]
	public virtual int TestTimeOut
	{
		get
		{
			return testTimeOut;
		}
		set
		{
			testTimeOut = value;
		}
	}

	[Category("Settings")]
	[Description("Specifies the action to take if the test times out.")]
	[DefaultValue(TimeOutActions.None)]
	public virtual TimeOutActions TimeOutAction
	{
		get
		{
			return timeOutAction;
		}
		set
		{
			timeOutAction = value;
		}
	}

	[Browsable(false)]
	public virtual long NodeRID
	{
		get
		{
			return nodeRID;
		}
		set
		{
			nodeRID = value;
			if (value == -1)
			{
				Parameters.RemoveRegistrationInformation();
			}
		}
	}

	[Browsable(false)]
	public virtual int NumberOfTests
	{
		get
		{
			return numberOfTests;
		}
		set
		{
			numberOfTests = value;
		}
	}

	[Description("Test runs if any test in its parent folder runs.")]
	[DefaultValue(false)]
	[Category("Attributes")]
	public virtual bool FolderMustRun
	{
		get
		{
			return bAttributeArray[1];
		}
		set
		{
			if (!bAttributeArray[0] || !value)
			{
				bAttributeArray[1] = value;
				return;
			}
			DialogResult dialogResult = AppMessageDialog.Show("A test cannot be must run and tool process at the same time.\nTool property will be modified for " + TestName, "QSPR - Message Center", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, DialogResult.OK, MessageDialogType.UIWarning);
			if (dialogResult == DialogResult.OK)
			{
				bAttributeArray[0] = false;
				bAttributeArray[1] = value;
			}
		}
	}

	[XmlIgnore]
	[Browsable(false)]
	public virtual string DescriptionName
	{
		get
		{
			return descriptionName;
		}
		set
		{
			descriptionName = value;
		}
	}

	[Browsable(false)]
	[XmlIgnore]
	public virtual bool TestResult
	{
		get
		{
			return testResult;
		}
		set
		{
			testResult = value;
			if (!testResult)
			{
				if (Owner.Root.Scheduler.GlobalStatus.LoopDetails.Trim() != string.Empty)
				{
					GlobalStatus globalStatus = Owner.Root.Scheduler.GlobalStatus;
					globalStatus.ListOfFailedTests = globalStatus.ListOfFailedTests + Owner.Root.Scheduler.GlobalStatus.LoopDetails + "_";
				}
				GlobalStatus globalStatus2 = Owner.Root.Scheduler.GlobalStatus;
				globalStatus2.ListOfFailedTests = globalStatus2.ListOfFailedTests + TestName + ",";
			}
		}
	}

	[Browsable(false)]
	public virtual ParameterCollection Parameters
	{
		get
		{
			return parameters;
		}
		set
		{
			parameters = value;
		}
	}

	[XmlAttribute("NodeType")]
	[Browsable(false)]
	public virtual string NodeType
	{
		get
		{
			return "TestProperty";
		}
		set
		{
		}
	}

	[DefaultValue(false)]
	[Browsable(false)]
	public bool LoopingInstance
	{
		get
		{
			return loopingInstance;
		}
		set
		{
			loopingInstance = value;
		}
	}

	[DefaultValue(false)]
	[Browsable(false)]
	public bool IsSetupTestStep
	{
		get
		{
			return isSetupTestStep;
		}
		set
		{
			isSetupTestStep = value;
		}
	}

	[Browsable(false)]
	[DefaultValue(false)]
	public bool IsTearDownTestStep
	{
		get
		{
			return isTearDownTestStep;
		}
		set
		{
			isTearDownTestStep = value;
		}
	}

	[Browsable(false)]
	[DefaultValue(false)]
	public bool CanAddToTestPlan
	{
		get
		{
			return canAddToTestPlan;
		}
		set
		{
			canAddToTestPlan = value;
		}
	}

	[DefaultValue(false)]
	[Browsable(false)]
	public bool IsManual
	{
		get
		{
			return isManual;
		}
		set
		{
			isManual = value;
		}
	}

	[Browsable(false)]
	[XmlIgnore]
	public virtual bool HasThreeStateCheckbox => false;

	[field: NonSerialized]
	public event PropertyChangedEventHandler PropertyChanged;

	public TestProperties()
	{
		typeStopOnError = StopOnErrorTypes.None;
	}

	public TestProperties Copy(TestProperties newProp)
	{
		newProp.Description = Description;
		newProp.CheckStateTest = CheckStateTest;
		newProp.RealName = RealName;
		newProp.IgnoreEmptyStringParameters = ignoreEmptyParam;
		newProp.StopOnError = StopOnError;
		newProp.RefreshLoopValuesAtLoopStart = RefreshLoopValuesAtLoopStart;
		newProp.TestName = TestName;
		newProp.LoopLinks = (ArrayList)LoopLinks.Clone();
		newProp.IsLinkActive = IsLinkActive;
		newProp.LinkNode = LinkNode;
		newProp.branchOnErrorName = branchOnErrorName;
		newProp.branchOnErrorIndex = branchOnErrorIndex;
		newProp.ToolTest = ToolTest;
		newProp.TreeMustRun = TreeMustRun;
		newProp.MustRunTest = MustRunTest;
		newProp.FolderMustRun = FolderMustRun;
		newProp.PauseTreeOnCompletion = PauseTreeOnCompletion;
		newProp.TargetName = TargetName;
		newProp.Parameters = Parameters.Clone();
		newProp.Expanded = Expanded;
		newProp.TestResultBasedOnLimits = TestResultBasedOnLimits;
		newProp.BreakPoint = BreakPoint;
		newProp.LoggingEnabled = LoggingEnabled;
		newProp.DataLoggingOnlyOnFailure = DataLoggingOnlyOnFailure;
		newProp.TestTimeOut = TestTimeOut;
		newProp.TimeOutAction = TimeOutAction;
		newProp.TestIndexCopy = TestIndexCopy;
		newProp.RetryCount = RetryCount;
		newProp.LoopingInstance = loopingInstance;
		newProp.TestErrorCode = TestErrorCode;
		newProp.SkipWhenLinked = SkipWhenLinked;
		newProp.notes = notes;
		newProp.Description = Description;
		newProp.TreatExceptionAsError = TreatExceptionAsError;
		newProp.CanAddToTestPlan = CanAddToTestPlan;
		newProp.IsSetupTestStep = IsSetupTestStep;
		newProp.IsTearDownTestStep = IsTearDownTestStep;
		newProp.IsManual = IsManual;
		if (newProp.RetryCount != 0)
		{
			newProp.loopScenario = loopScenario;
		}
		if (postConditionMgr != null)
		{
			newProp.postConditionMgr = postConditionMgr.Clone();
		}
		if (preConditionMgr != null)
		{
			newProp.preConditionMgr = preConditionMgr.Clone();
		}
		newProp.Comment = Comment;
		if (loopScenario != null)
		{
			newProp.loopScenario = loopScenario.Clone();
		}
		if (metadata != null)
		{
			newProp.metadata = metadata.Clone();
		}
		return newProp;
	}

	public virtual TestProperties Clone()
	{
		TestProperties testProperties = new TestProperties();
		Copy(testProperties);
		return testProperties;
	}

	public virtual void OnPropChanged(PropertyValueChangedEventArgs e)
	{
		switch (e.ChangedItem.Label)
		{
		case "StopOnError":
			StopOnError = (StopOnErrorTypes)e.ChangedItem.Value;
			break;
		case "ToolTest":
			ToolTest = (bool)e.ChangedItem.Value;
			break;
		case "IsSetupFolder":
			ToolTest = (bool)e.ChangedItem.Value;
			break;
		case "TreeMustRun":
			TreeMustRun = (bool)e.ChangedItem.Value;
			break;
		case "MustRunTest":
			MustRunTest = (bool)e.ChangedItem.Value;
			break;
		case "FolderMustRun":
			FolderMustRun = (bool)e.ChangedItem.Value;
			break;
		case "PauseTreeOnCompletion":
			PauseTreeOnCompletion = (bool)e.ChangedItem.Value;
			break;
		case "BranchOnError":
			BranchOnError = e.ChangedItem.Value.ToString();
			break;
		case "TestResultBasedOnLimits":
			TestResultBasedOnLimits = (bool)e.ChangedItem.Value;
			break;
		case "BreakPoint":
			BreakPoint = (BreakPointTypes)e.ChangedItem.Value;
			break;
		case "LoggingEnabled":
			LoggingEnabled = (bool)e.ChangedItem.Value;
			break;
		case "DataLoggingOnlyOnFailure":
			DataLoggingOnlyOnFailure = (bool)e.ChangedItem.Value;
			break;
		case "RefreshLoopValuesAtLoopStart":
			RefreshLoopValuesAtLoopStart = (bool)e.ChangedItem.Value;
			break;
		case "TestTimeOut":
			TestTimeOut = (int)e.ChangedItem.Value;
			break;
		case "TimeOutAction":
			TimeOutAction = (TimeOutActions)e.ChangedItem.Value;
			break;
		case "TestErrorCode":
			TestErrorCode = (string)e.ChangedItem.Value;
			break;
		case "SkipWhenLinked":
			SkipWhenLinked = (bool)e.ChangedItem.Value;
			break;
		case "TreatExceptionAsError":
			TreatExceptionAsError = (bool)e.ChangedItem.Value;
			break;
		}
	}

	public void AddLoopLink(string link)
	{
		if (!loopLinks.Contains(link))
		{
			loopLinks.Add(link);
		}
	}

	public void RemoveLoopLink(string link)
	{
		if (LoopLinks.Contains(link))
		{
			loopLinks.Remove(link);
		}
	}

	public virtual void RenameLoopLink(string oldLink, string newLink)
	{
		RemoveLoopLink(oldLink);
		AddLoopLink(newLink);
	}

	public void ReplaceLoopLinkSubString(string oldSubString, string newSubString, string testIndex)
	{
		ArrayList arrayList = new ArrayList();
		foreach (string loopLink in LoopLinks)
		{
			string value = loopLink;
			if (loopLink == testIndex)
			{
				value = loopLink.Replace(oldSubString, newSubString);
			}
			arrayList.Add(value);
		}
		LoopLinks = arrayList;
	}

	public virtual bool SyncParameters(ParameterCollection oldParams)
	{
		foreach (ParameterCls oldParam in oldParams)
		{
			if (parameters.SetParamValue(oldParam.Name, oldParam.Value, -2, ""))
			{
				parameters.SetParamLowerLimit(oldParam.Name, oldParam.LowerLimit, -2);
				parameters.SetParamUpperLimit(oldParam.Name, oldParam.UpperLimit, -2);
				parameters.SetDataLogging(oldParam.Name, oldParam.EnableDataLogging);
				parameters.SetChartLogging(oldParam.Name, oldParam.EnableCharting);
			}
		}
		return true;
	}

	protected virtual void RaisePropertyChanged(string propertyName)
	{
		if (this.PropertyChanged != null)
		{
			this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}
		if (CheckStateTest != CheckState.Indeterminate && Owner != null && string.Compare("CheckStateTest", propertyName, ignoreCase: true) == 0)
		{
			BaseTest baseTest = Owner;
			if (baseTest is FolderTest)
			{
				FolderTest folderTest = (FolderTest)baseTest;
				SetChildTestCheckStateTest(folderTest, CheckStateTest);
			}
			if (baseTest.Parent != null)
			{
				FolderTest parent = baseTest.Parent;
				ResetParentCheckStateTest(parent);
			}
		}
	}

	protected virtual void ResetParentCheckStateTest(FolderTest folderTest)
	{
		if (folderTest.TestList.All((BaseTest t) => t.Properties.CheckStateTest == CheckState.Checked))
		{
			folderTest.Properties.CheckStateTest = CheckState.Checked;
		}
		else if (folderTest.TestList.All((BaseTest t) => t.Properties.CheckStateTest == CheckState.Unchecked))
		{
			folderTest.Properties.CheckStateTest = CheckState.Unchecked;
		}
		else
		{
			folderTest.Properties.CheckStateTest = CheckState.Indeterminate;
		}
		if (folderTest.Parent != null && folderTest.Parent != null)
		{
			FolderTest parent = folderTest.Parent;
			ResetParentCheckStateTest(parent);
		}
	}

	protected virtual void SetChildTestCheckStateTest(FolderTest folderTest, CheckState checkState)
	{
		if (folderTest.FolderProperties.LinkRoot && folderTest.FolderProperties.IsLinkActive == true)
		{
			return;
		}
		foreach (BaseTest test in folderTest.TestList)
		{
			if (!test.IsTestStep)
			{
				test.Properties.CheckStateTest = checkState;
				if (test is FolderTest)
				{
					FolderTest folderTest2 = (FolderTest)test;
					SetChildTestCheckStateTest(folderTest2, checkState);
				}
			}
		}
	}
}
