using System.ComponentModel;
using System.Security.Principal;
using System.Xml;
using System.Xml.Serialization;

namespace QC.CompareTestTree;

public class RootTestProperties : FolderTestProperties
{
	public const string ROOT_PROPERTY = "RootProperty";

	private string configFileName = "";

	private TreeTypes treeType;

	private string comment = "";

	private string createdBy = "";

	private string treeFileName = "";

	private string server = "";

	private string database = "";

	private bool enableDatabase = true;

	private long siteTreeID = -1L;

	private string treeStringID = "-1";

	private string registeredMachine = "";

	private bool forceRegistrationOnPlugInChange;

	private bool refreshConfig;

	private bool stopOnFirstTestFailure;

	private string testErrorCodeOnAbort = "";

	private bool alwaysPerformMustRunTests = true;

	[Category("Registration")]
	[ReadOnly(true)]
	[Description("Specifies the location of the tree registration server.")]
	public string Server
	{
		get
		{
			return server;
		}
		set
		{
			server = value;
		}
	}

	[ReadOnly(true)]
	[Category("Registration")]
	[Description("Specifies the database where tree is registered.")]
	public string Database
	{
		get
		{
			return database;
		}
		set
		{
			database = value;
		}
	}

	[Category("Registration")]
	[Description("This warns the user for non registered tree.")]
	public bool EnableDatabase
	{
		get
		{
			return enableDatabase;
		}
		set
		{
			enableDatabase = value;
		}
	}

	[Description("When set to true, In GoNoGo tree type, registration will be requireemd when there is change in plugins configurations.")]
	[Category("Registration")]
	public bool ForceRegistrationOnPlugInChange
	{
		get
		{
			return forceRegistrationOnPlugInChange;
		}
		set
		{
			forceRegistrationOnPlugInChange = value;
		}
	}

	public string ConfigFileName
	{
		get
		{
			return configFileName;
		}
		set
		{
			configFileName = value;
		}
	}

	[Category("Tester")]
	[Description("Specifies whether to reload the Tester Configuration file each time the GoNoGo runs.")]
	public bool RefreshConfig
	{
		get
		{
			return refreshConfig;
		}
		set
		{
			refreshConfig = value;
		}
	}

	[Category("Registration")]
	[Description("Machine name where the test tree got registered.")]
	[ReadOnly(true)]
	public string RegisteredMachine
	{
		get
		{
			return registeredMachine;
		}
		set
		{
			registeredMachine = value;
		}
	}

	[Browsable(false)]
	public long SiteTreeID
	{
		get
		{
			return siteTreeID;
		}
		set
		{
			siteTreeID = value;
		}
	}

	[Browsable(false)]
	public string SiteKey
	{
		get
		{
			string result = "domain\\QTM";
			try
			{
				string name = WindowsIdentity.GetCurrent().Name;
				string text = name.Split('\\')[0];
				result = text + "\\QTM";
			}
			catch
			{
			}
			return result;
		}
		set
		{
		}
	}

	[Browsable(false)]
	public override bool ToolTest => false;

	[Browsable(false)]
	public override StopOnErrorTypes StopOnError => StopOnErrorTypes.None;

	[Browsable(false)]
	public override bool TreeMustRun => false;

	[Browsable(false)]
	public override bool FolderMustRun => false;

	[Browsable(false)]
	public override bool DisableLooping => false;

	[Category("Settings")]
	[Description("Type of testing")]
	public TreeTypes TreeType
	{
		get
		{
			return treeType;
		}
		set
		{
			treeType = value;
		}
	}

	[Category("Settings")]
	[Description("In GoNoGo mode, if any test fails, the testing is stopped.")]
	public bool StopOnFirstTestFailure
	{
		get
		{
			return stopOnFirstTestFailure;
		}
		set
		{
			stopOnFirstTestFailure = value;
		}
	}

	[Category("Settings")]
	[Description("The test error code on abort string will be set when the test tree is aborted and no error code has already been set.")]
	public string TestErrorCodeOnAbort
	{
		get
		{
			return testErrorCodeOnAbort;
		}
		set
		{
			testErrorCodeOnAbort = value;
		}
	}

	[Category("Settings")]
	[Description("Always execute tests that are marked as TreeMustRun even if a tree is aborted or stopped")]
	public bool AlwaysPerformMustRunTests
	{
		get
		{
			return alwaysPerformMustRunTests;
		}
		set
		{
			alwaysPerformMustRunTests = value;
		}
	}

	[Browsable(false)]
	public override string LinkLocation
	{
		get
		{
			return base.LinkLocation;
		}
		set
		{
			base.LinkLocation = value;
		}
	}

	[Browsable(false)]
	public override bool IsSetupFolder
	{
		get
		{
			return false;
		}
		set
		{
		}
	}

	[Browsable(false)]
	public string Comment
	{
		get
		{
			return comment;
		}
		set
		{
			comment = value;
		}
	}

	[Browsable(false)]
	public string CreatedBy
	{
		get
		{
			return createdBy;
		}
		set
		{
			createdBy = value;
		}
	}

	[Browsable(false)]
	public string TreeFileName
	{
		get
		{
			return treeFileName;
		}
		set
		{
			treeFileName = value;
		}
	}

	[ReadOnly(true)]
	[Category("Registration")]
	[Description("Specifies the TreeID for the registered tree.")]
	public long TreeID => nodeRID;

	public string TreeStringID
	{
		get
		{
			if (nodeRID != -1)
			{
				return treeStringID.ToString();
			}
			return "-1";
		}
		set
		{
			treeStringID = value;
		}
	}

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

	[Browsable(false)]
	[XmlIgnore]
	public override string PreConditionEnabled
	{
		get
		{
			return base.PreConditionEnabled;
		}
		set
		{
			base.PreConditionEnabled = value;
		}
	}

	[XmlIgnore]
	[Browsable(false)]
	public override ConditionMgr PreCondition
	{
		get
		{
			return null;
		}
		set
		{
		}
	}

	public void CompareProperties(string XmlTagName, RootTestProperties baseProperties, string overrideAttrib, ref XmlDocument xmlDoc, ref XmlElement parentNode)
	{
		XmlElement xmlElement = xmlDoc.CreateElement(XmlTagName);
		xmlElement.SetAttribute("NodeType", "RootProperty");
		CommonFunctions.RootDoc = xmlDoc;
		CommonFunctions.ParentNode = xmlElement;
		CommonFunctions.AddElement("ConfigFileName", ConfigFileName, baseProperties.ConfigFileName, overrideAttrib);
		CommonFunctions.AddElement("Server", Server, baseProperties.Server, overrideAttrib);
		CommonFunctions.AddElement("DataLoggingOnlyOnFailure", DataLoggingOnlyOnFailure, baseProperties.DataLoggingOnlyOnFailure, overrideAttrib);
		CommonFunctions.AddElement("IgnoreEmptyStringParameters", base.IgnoreEmptyStringParameters, baseProperties.IgnoreEmptyStringParameters, overrideAttrib);
		CommonFunctions.AddElement("RefreshLoopValuesAtLoopStart", base.RefreshLoopValuesAtLoopStart, baseProperties.RefreshLoopValuesAtLoopStart, overrideAttrib);
		CommonFunctions.AddElement("RegisteredMachine", RegisteredMachine, baseProperties.RegisteredMachine, overrideAttrib);
		CommonFunctions.AddElement("EnableDatabase", EnableDatabase, baseProperties.EnableDatabase, overrideAttrib);
		CommonFunctions.AddElement("TestResultBasedOnLimits", TestResultBasedOnLimits, baseProperties.TestResultBasedOnLimits, overrideAttrib);
		CommonFunctions.AddElement("TreeStringID", TreeStringID, baseProperties.TreeStringID, overrideAttrib);
		CommonFunctions.AddElement("Database", Database, baseProperties.Database, overrideAttrib);
		CommonFunctions.AddElement("ForceRegistrationOnPlugInChange", ForceRegistrationOnPlugInChange, baseProperties.ForceRegistrationOnPlugInChange, overrideAttrib);
		CommonFunctions.AddElement("TreeID", TreeID, baseProperties.TreeID, overrideAttrib);
		CommonFunctions.AddElement("TreeType", TreeType.ToString(), baseProperties.TreeType.ToString(), overrideAttrib);
		CommonFunctions.AddElement("RefreshConfig", RefreshConfig, baseProperties.RefreshConfig, overrideAttrib);
		CommonFunctions.AddElement("StopOnFirstTestFailure", StopOnFirstTestFailure, baseProperties.StopOnFirstTestFailure, overrideAttrib);
		CommonFunctions.AddElement("TestErrorCodeOnAbort", TestErrorCodeOnAbort, baseProperties.TestErrorCodeOnAbort, overrideAttrib);
		CommonFunctions.AddElement("AlwaysPerformMustRunTests", AlwaysPerformMustRunTests, baseProperties.AlwaysPerformMustRunTests, overrideAttrib);
		CommonFunctions.AddElement("Database", Database, baseProperties.Database, overrideAttrib);
		CommonFunctions.AddElement("Database", Database, baseProperties.Database, overrideAttrib);
		CommonFunctions.AddElement("CheckStateTest", base.CheckStateTest.ToString(), baseProperties.CheckStateTest.ToString(), overrideAttrib);
		CommonFunctions.AddElement("Notes", Notes, baseProperties.Notes, overrideAttrib);
		XmlElement rootNode = xmlDoc.CreateElement("Statistics");
		Statistics.DetermineStatics(xmlElement, ref xmlDoc, ref rootNode);
		xmlElement.AppendChild(rootNode);
		parentNode.AppendChild(xmlElement);
	}
}
