using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;
using QC.GlobalVariableManager;
using QC.QsprShared.Config;
using QC.QsprShared.Trace;
using QC.QTMInterface;

namespace QC.QsprShared.GlobalData;

public class QTMData
{
	public delegate ArrayList UpdateGVForLinkedTree(string p, out Dictionary<string, string> overwrittenConfigs);

	public delegate void OnUpdateToolBar(object value);

	public static SupportedKernels Kernels = default(SupportedKernels);

	private ArrayList testerConfigList = new ArrayList();

	private static FeatureConfig fc = new FeatureConfig(loadConfigFile: true);

	private WorkspaceConfig wc = new WorkspaceConfig();

	public UpdateGVForLinkedTree UpdateGVForLinkTree;

	public static OnUpdateToolBar UpdateToolBar = null;

	public ArrayList TesterConfigurationList
	{
		get
		{
			return testerConfigList;
		}
		set
		{
			testerConfigList = value;
		}
	}

	public object theRegistry { get; set; }

	public object scenarioHandler { get; set; }

	public ArrayList messageQueue { get; set; }

	public string SchedulerID { get; set; }

	public static FeatureConfig FeatureConfigInfo
	{
		get
		{
			if (fc == null)
			{
				fc = new FeatureConfig();
			}
			return fc;
		}
		set
		{
			fc = value;
		}
	}

	public WorkspaceConfig WConfig
	{
		get
		{
			return wc;
		}
		set
		{
			wc = value;
		}
	}

	public bool PeekForFailedMessageInQueue()
	{
		foreach (MsgData item in messageQueue)
		{
			if (item.msgType == TestMsgType.OnTestResult && (item.Result == TestResult.Failed || item.Result == TestResult.Exception))
			{
				return true;
			}
		}
		return false;
	}

	public void UpdateGlobalVble(bool GetFromTesterConfig, ArrayList testerConfigListFromPlugins)
	{
		try
		{
			if (GetFromTesterConfig)
			{
				TesterConfigurationList = testerConfigListFromPlugins;
			}
			if (TesterConfigurationList != null)
			{
				object[] array = TesterConfigurationList.ToArray();
				for (int i = 0; i < array.Length; i++)
				{
					TesterConfigurationInfo testerConfigurationInfo = (TesterConfigurationInfo)array[i];
					QTMGlobalVariable.SetGlobalVariable(testerConfigurationInfo.Name, testerConfigurationInfo.Value, SchedulerID);
				}
			}
		}
		catch (Exception ex)
		{
			TraceMessage.Write("QC.QTMApplication.QTM", "UpdateGlobalVble " + ex.Message, TraceMessageType.Exception);
		}
	}

	public static void DoEvents()
	{
		Application.DoEvents();
	}

	public ArrayList UpdateGlobalVbleForLinkedTree(string p, out Dictionary<string, string> overwriteConfigs)
	{
		ArrayList result = null;
		overwriteConfigs = null;
		if (UpdateGVForLinkTree != null)
		{
			result = UpdateGVForLinkTree(p, out overwriteConfigs);
		}
		return result;
	}
}
