using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;

namespace QDART_MFG_CfgEditor;

public class Common
{
	public enum EditTypes
	{
		TesterName,
		DomainName,
		SeqLogTxt,
		SheetLog,
		XmlLog,
		DLL,
		DeviceGroup,
		Resource,
		DeviceCfg,
		DRIVER_DLL,
		BUS_CONFIG,
		ROUTING_CONFIG,
		SIMULATION_MODE,
		GROUP,
		DUT,
		MULTIPLEXER
	}

	public enum CalTypes
	{
		QTA = 1,
		QRD
	}

	public enum CalPathVbles
	{
		SG1 = 1,
		SG2 = 2,
		SG3 = 3,
		DownlinkCP1 = 4,
		UplinkCP1 = 5,
		GPS = 6,
		DownlinkDivCP2 = 7,
		UplinkDivCP2 = 8,
		DownlinkAuxCP1 = 14,
		DownlinkCP2 = 204,
		UplinkPrimCP2 = 205,
		DownlinkAuxCP2 = 214,
		UplinkAuxCP2 = 215,
		DownlinkCP3 = 304,
		UplinkCP3 = 305,
		DownlinkAuxCP3 = 314
	}

	public const string CONFIG_FILE = "QDART_MFG_CfgEditor_Link.xml";

	public const string TARGET_RFCalVerify = "RFCalVerify";

	public const string TARGET_RFStationCal = "RFStationCal";

	public const string TARGET_BTWLAN = "BTWLAN";

	public const string TARGET_BTWLANStationCal = "BTWLANStationCal";

	public const string TARGET_RFRadiatedVerify = "RFRadiatedVerify";

	public const string TARGET_LossEditorRF = "LossEditorRF";

	public const string TARGET_LossEditorBTWLAN = "LossEditorBTWLAN";

	public const string TARGET_LossEditorRFRadiated = "LossEditorRFRadiated";

	public const string TARGET_StationCfg = "StationCfg";

	public const string TARGET_QSEQ = "QSEQ";

	public const string TARGET_MULTIPLEX = "MultiDUT";

	public const string TARGET_GPS = "GPS";

	public const string TARGET_LogCfg = "LogCfg";

	public const string TARGET_MMICfg = "MMICfg";

	public const string INST_IFR_20XX = "IFR 20XX";

	public const string INST_RS_SMIQ = "RS SMIQ";

	public const string INST_AGILENT_PSG = "Agilent PSG";

	public const string INST_SMA = "SMA";

	public const string INST_SMU_CHAN1 = "SMU Chan1";

	public const string INST_RS_SMBV = "RS SMBV";

	public const string INST_SCPI = "QTI SCPI";

	public const string INST_AG4010 = "AgilentN4010A";

	public const string INST_CMW100 = "CMW100";

	public const string INST_CMW500 = "CMW500";

	public const string INST_IQ2010 = "LPIQ2010";

	public const string INST_IQxel = "LPIQxel";

	public const string INST_NITrident = "NITrident";

	public const string INST_Anritsu8870A = "AnritsuMT8870A";

	public const string INST_SCPI_UP = "COMMONSCPI";

	public const string INST_AG4010_UP = "AGILENTN4010A";

	public const string INST_CMW100_UP = "CMW100";

	public const string INST_CMW500_UP = "CMW500";

	public const string INST_IQ2010_UP = "LPIQ2010";

	public const string INST_IQxel_UP = "LPIQXEL";

	public const string INST_NITrident_UP = "NITRIDENT";

	public const string INST_Anritsu8870A_UP = "ANRITSUMT8870A";

	public const string IHW_GPIB = "GPIB";

	public const string IHW_SWFACADE = "SWFacade";

	public const string IHW_TCPIP = "TcpClient";

	public const string IHW_VISA = "Visa32";

	public const string RT_GPIB = "GPIB";

	public const string RT_IP = "IP";

	public const string RT_USB = "USB";

	public const int IP_SECTION = 4;

	public const int BT_ADDRESS_SECTION = 6;

	public const string DLL_MOBILE = "QSEQ_Device_Qualcomm_Mobile";

	public const string DLL_CMW500 = "QSEQ_Device_RohdeSchwarz_CMW500";

	public const string DLL_MT8820C = "QSEQ_Device_Anritsu_MT8820C";

	public const string DLL_MT8870A = "QSEQ_Device_Anritsu_MT8870A";

	public const string DLL_MSVC10R = "QMSL_MSVC10R";

	public const string DLL_UTILITY = "QSEQ_Utility_Qualcomm";

	public const string DLL_PATHLOSS = "QSEQ_PathLossManager";

	public const string DLL_NSVFS = "QSEQ_Algorithm_Qualcomm_NSVFS";

	public const string DLL_EXT = "QSEQ_Device_Agilent_EXx";

	public const string DLL_IQX = "QSEQ_Device_Litepoint_IQXSTREAM";

	public const string DLL_MCT = "QSEQ_Device_NationalInstrument_MCT";

	public const string DLL_PXI = "QSEQ_Device_Aeroflex_PXI_3000";

	public static Dictionary<string, string> LogSample = new Dictionary<string, string>
	{
		{ "UserDefine", "UserDefine" },
		{ "%PCNAME%", "MyPC" },
		{ "%DATE%", "2017_12_30" },
		{ "%DATE_TIME%", "23_59_59_999" },
		{ "%TECHNOLOGIES%", "GWL" },
		{ "%DUT_ID%", "4" },
		{ "%SN%", "SN123" },
		{ "%TREENAME%", "MyTreeName" }
	};

	public static Dictionary<string, string> CalPathMappingList = new Dictionary<string, string>
	{
		{ "1", "SG1" },
		{ "2", "SG2" },
		{ "3", "SG3" },
		{ "4", "DownlinkCP1" },
		{ "5", "UplinkCP1" },
		{ "6", "GPS" },
		{ "7", "DownlinkDivCP2" },
		{ "8", "UplinkDivCP2" },
		{ "14", "DownlinkAuxCP1" },
		{ "204", "DownlinkCP2" },
		{ "205", "UplinkCP2" },
		{ "214", "DownlinkAuxCP2" },
		{ "215", "UplinkAuxCP2" },
		{ "304", "DownlinkCP3" },
		{ "305", "UplinkCP3" },
		{ "314", "DownlinkAuxCP3" }
	};

	public static string GetProgramFilePath()
	{
		string text = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
		if (!text.EndsWith("\\"))
		{
			text += "\\";
		}
		return text;
	}

	public static string GetPath(string path)
	{
		try
		{
			if (path.Contains(":"))
			{
				return path;
			}
			return Path.GetFullPath(path);
		}
		catch (Exception ex)
		{
			MessageBox.Show(path);
			MessageBox.Show(ex.Message);
			return "";
		}
	}

	public static bool InArray(string item, string[] items)
	{
		foreach (string text in items)
		{
			if (text == item)
			{
				return true;
			}
		}
		return false;
	}

	public static string GetFormatString(string source, string name)
	{
		string[] array = source.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
		if (array.Length > 0)
		{
			string[] array2 = array;
			foreach (string text in array2)
			{
				if (text.Contains(name + ":"))
				{
					return text.Replace(name + ":", "");
				}
			}
		}
		return "Not found";
	}

	public static bool DictionaryCompare(Dictionary<string, string> d1, Dictionary<string, string> d2)
	{
		bool result = true;
		if (d1.Count != d2.Count)
		{
			result = false;
		}
		else
		{
			foreach (string key in d1.Keys)
			{
				bool flag = false;
				foreach (string key2 in d2.Keys)
				{
					if (key == key2)
					{
						flag = true;
						if (d1[key] != d2[key2])
						{
							result = false;
							break;
						}
					}
				}
				if (!flag)
				{
					result = false;
					break;
				}
			}
		}
		return result;
	}

	public static bool DictionaryCompare(Dictionary<double, double> d1, Dictionary<double, double> d2)
	{
		bool result = true;
		if (d1.Count != d2.Count)
		{
			result = false;
		}
		else
		{
			foreach (double key in d1.Keys)
			{
				double num = key;
				bool flag = false;
				foreach (double key2 in d2.Keys)
				{
					double num2 = key2;
					if (num == num2)
					{
						flag = true;
						if (d1[num] != d2[num2])
						{
							result = false;
							break;
						}
					}
				}
				if (!flag)
				{
					result = false;
					break;
				}
			}
		}
		return result;
	}

	public static void FormatXml(string strDocumentPath)
	{
		XmlDocument xmlDocument = new XmlDocument();
		xmlDocument.Load(strDocumentPath);
		string text = "";
		text = xmlDocument.InnerXml;
		XDocument xDocument = XDocument.Parse(text);
		xmlDocument.InnerXml = xDocument.ToString();
		xmlDocument.Save(strDocumentPath);
	}
}
