using System;
using System.Windows.Forms;
using System.Xml.Serialization;
using QC.QsprShared.Dialogs;
using QC.QsprShared.Trace;
using QC.QsprTestObjects.Loops;
using QC.QsprTestObjects.Parameters;
using QC.QsprTestObjects.Tests.Base;
using QC.QTMLabViewKernel;

namespace QC.QsprTestObjects.Tests.LabVIEW;

[Serializable]
public class LabVIEWTest : BaseTest
{
	private LabVIEWTestProperties labVIEWTestProperties = new LabVIEWTestProperties();

	private LabViewKernel labVIEWKernel => Root.Scheduler.KernelMgr.labVIEWKernel;

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

	public LabVIEWTestProperties LabVIEWProperties
	{
		get
		{
			return labVIEWTestProperties;
		}
		set
		{
			labVIEWTestProperties = value;
		}
	}

	public LabVIEWTest()
	{
	}

	public LabVIEWTest(string name, string targetName, RootTest root)
		: base(name, targetName, root)
	{
	}

	public override BaseTest Clone()
	{
		LabVIEWTest labVIEWTest = new LabVIEWTest();
		labVIEWTest.Properties = Properties.Clone();
		base.Copy(labVIEWTest);
		return labVIEWTest;
	}

	public override void GetAllParamInfo(string realName, string containerName, ref object objParameters)
	{
		labVIEWKernel.GetAllParamInfo(containerName, ref objParameters);
	}

	public override bool StartTest()
	{
		TraceMessage.Write(ToString(), "StartTest: " + Properties.TestName, TraceMessageType.Trace);
		try
		{
			if (!LoadContainer())
			{
				AppMessageDialog.Show("LabVIEW VI: " + Properties.TestName + " not found.", "QSPR MessageCenter", MessageBoxButtons.OK, MessageBoxIcon.Hand, DialogResult.OK, MessageDialogType.Exception);
				ExceptionHandle("LabVIEW VI: " + Properties.TestName + " not found.");
				return false;
			}
			object[,] array = new object[Properties.Parameters.Count, 8];
			int num = 0;
			foreach (ParameterCls parameter in Properties.Parameters)
			{
				array[num, 0] = parameter.Name;
				array[num, 1] = parameter.Value;
				array[num, 2] = parameter.LowerLimit;
				array[num, 3] = parameter.UpperLimit;
				array[num, 4] = parameter.NoOfElements;
				array[num, 5] = parameter.IOTypeAsString;
				array[num, 6] = parameter.Unit;
				array[num, 7] = parameter.Description;
				num++;
			}
			object objParameters = array;
			object[] array2 = new object[4];
			if (Properties.DescriptionName.Trim() == "")
			{
				((ScenarioHandler)Root.Scheduler.QTMData.scenarioHandler).Update(Root.Scheduler.GlobalStatus);
				Root.Scheduler.GlobalStatus.LoopDetails = Root.Scheduler.GlobalStatus.LoopDetailsComplete;
			}
			else
			{
				((ScenarioHandler)Root.Scheduler.QTMData.scenarioHandler).Update(Root.Scheduler.GlobalStatus);
			}
			string text = Properties.TestName;
			if (Properties.DescriptionName.Trim() != "")
			{
				text = Properties.DescriptionName.Trim();
			}
			array2[0] = text;
			array2[1] = Properties.TargetName;
			array2[2] = labVIEWTestProperties.CloseVIAfterCall;
			array2[3] = labVIEWTestProperties.DisplayFrontPanel;
			object objProperties = array2;
			RunTest(Properties.RealName.Trim(), ref objParameters, ref objProperties);
		}
		catch
		{
		}
		return true;
	}

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

	public override void StopQTMTest()
	{
	}

	public LabVIEWTest Copy(LabVIEWTest b)
	{
		Properties = b.Properties;
		base.Copy(b);
		return this;
	}

	public static bool Options()
	{
		AppMessageDialog.Show("Options unavaiable.", "QSPR - Message Center", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, DialogResult.OK, MessageDialogType.Information);
		return false;
	}

	public override void Add(BaseTest baseTest)
	{
	}

	public override void Remove(BaseTest baseTest)
	{
	}

	public override void Display(int indent)
	{
	}

	public override void Insert(BaseTest baseTest, int index)
	{
	}
}
