using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Serialization;
using QC.QTMXmlSchema;

namespace QC.CorpTest.Libraries.QsprSchemaLibrary;

public class QsprConvertor : IDisposable
{
	private const string TIMESTAMP_FORMAT = "M/d/yy HH:mm:ss:fff";

	private const string DURATION_FORMAT = "c";

	private int dataSetId;

	private string defaultResult = "PASS";

	private string loopConditions = string.Empty;

	private string testerID = string.Empty;

	private string treeID = string.Empty;

	private string workstation = string.Empty;

	private string comments = string.Empty;

	private string machineNamefromXML = string.Empty;

	private string siteTreeID = string.Empty;

	private string mcn = string.Empty;

	private int extendedData;

	private string treeType = string.Empty;

	private string registeredMachine = string.Empty;

	private string machineName = Environment.MachineName;

	private string siteKey = string.Empty;

	private string database = string.Empty;

	private string server = string.Empty;

	private string runTitle = string.Empty;

	private string currentQsprToQtmXmlFilePath = string.Empty;

	private string currentQsprToCsvFilePath = string.Empty;

	private static string errorMessageParameterName = "QSPR_ERROR_MESSAGE";

	private List<string> addedQSPRExceptions = new List<string>();

	private bool appendDataSetCollectionName;

	private bool useRealNamesAsDefault;

	private CultureInfo stringFormatProvider = CultureInfo.InvariantCulture;

	public bool includeParametricData = true;

	public bool useNamedLogProcessing;

	public List<string> runtitleLogNames = new List<string>();

	public List<string> configLogNames = new List<string>();

	public string testTreeIDOverride;

	public bool AppendDataSetCollectionName
	{
		get
		{
			return appendDataSetCollectionName;
		}
		set
		{
			appendDataSetCollectionName = value;
		}
	}

	public string LoopConditions
	{
		get
		{
			return loopConditions;
		}
		set
		{
			loopConditions = value;
		}
	}

	public string TesterID
	{
		get
		{
			return testerID;
		}
		set
		{
			testerID = value;
		}
	}

	public string TreeID
	{
		get
		{
			return treeID;
		}
		set
		{
			treeID = value;
		}
	}

	public string Workstation
	{
		get
		{
			return workstation;
		}
		set
		{
			workstation = value;
		}
	}

	public string Comments
	{
		get
		{
			return comments;
		}
		set
		{
			comments = value;
		}
	}

	public string MachineNameFromXML
	{
		get
		{
			return machineNamefromXML;
		}
		set
		{
			machineNamefromXML = value;
		}
	}

	public string MCN
	{
		get
		{
			return mcn;
		}
		set
		{
			mcn = value;
		}
	}

	public int ExtendedData
	{
		get
		{
			return extendedData;
		}
		set
		{
			extendedData = value;
		}
	}

	public string TreeType
	{
		get
		{
			return treeType;
		}
		set
		{
			treeType = value;
		}
	}

	public string RegisteredMachine
	{
		get
		{
			return registeredMachine;
		}
		set
		{
			registeredMachine = value;
		}
	}

	public string MachineName
	{
		get
		{
			return machineName;
		}
		set
		{
			machineName = value;
		}
	}

	public string SiteKey
	{
		get
		{
			return siteKey;
		}
		set
		{
			siteKey = value;
		}
	}

	public string Database
	{
		get
		{
			return database;
		}
		set
		{
			database = value;
		}
	}

	public string Server
	{
		get
		{
			return server;
		}
		set
		{
			server = value;
		}
	}

	public string SiteTreeID
	{
		get
		{
			return siteTreeID;
		}
		set
		{
			siteTreeID = value;
		}
	}

	public string RunTitle
	{
		get
		{
			return runTitle;
		}
		set
		{
			runTitle = value;
		}
	}

	public string CurrentQsprToQtmXmlFilePath => currentQsprToQtmXmlFilePath;

	public string CurrentQsprToCsvFilePath => currentQsprToCsvFilePath;

	public bool IgnoreInvalidResults { get; set; }

	public event EventHandler<QsprFileToConvertEventArgs> GeneratingQsprOutput;

	public event EventHandler QsprOutputGenerated;

	public int ExportToQtmXmlAndCsv(string qsprFilePath, string qtmXmlFolderPath, string csvFolderPath, out string errormessage)
	{
		return ExportToQtmXmlAndCsv(GetQSPRSource(qsprFilePath), qsprFilePath, qtmXmlFolderPath, csvFolderPath, out errormessage);
	}

	public int ExportToQtmXmlAndCsv(string qsprFilePath, string qtmXmlFolderPath, string csvFolderPath, bool onlySessionData, out string errormessage)
	{
		return ExportToQtmXmlAndCsv(GetQSPRSource(qsprFilePath), qsprFilePath, qtmXmlFolderPath, csvFolderPath, onlySessionData, out errormessage);
	}

	public int ExportToQtmXmlAndCsv(source qsprFileSource, string qsprFilePath, string qtmXmlFolderPath, string csvFolderPath, out string errormessage)
	{
		return ExportToQtmXmlAndCsv(qsprFileSource, qsprFilePath, qtmXmlFolderPath, csvFolderPath, onlySessionData: false, out errormessage);
	}

	public int ExportToQtmXmlAndCsv(source qsprFileSource, string qsprFilePath, string qtmXmlFolderPath, string csvFolderPath, bool onlySessionData, out string errormessage)
	{
		errormessage = string.Empty;
		new Hashtable();
		QTMFormatUnitData qTMFormatUnitData = null;
		ClearOutputFilePaths();
		try
		{
			try
			{
				qTMFormatUnitData = GenerateQtmXmlUnitData(qsprFileSource, null, null, onlySessionData, string.Empty);
			}
			catch (QsprConversionException ex)
			{
				errormessage = ex.Message;
				return ex.ErrorCode;
			}
			QsprFileToConvertEventArgs qsprFileToConvertEventArgs = new QsprFileToConvertEventArgs();
			qsprFileToConvertEventArgs.CancelConversion = false;
			qsprFileToConvertEventArgs.QtmData = qTMFormatUnitData;
			if (this.GeneratingQsprOutput != null)
			{
				this.GeneratingQsprOutput(this, qsprFileToConvertEventArgs);
			}
			if (!qsprFileToConvertEventArgs.CancelConversion)
			{
				if (!string.IsNullOrEmpty(qtmXmlFolderPath))
				{
					DateTime result = DateTime.MinValue;
					if (!DateTime.TryParse(qTMFormatUnitData.Config.StartTime, out result))
					{
						result = DateTime.ParseExact(qTMFormatUnitData.Config.StartTime, "M/d/yy HH:mm:ss:fff", stringFormatProvider);
					}
					string text = result.ToString("%M") + "_" + result.ToString("%d") + "_" + result.ToString("%y") + "__" + result.ToString("%H") + "_" + result.ToString("%m") + "_" + result.ToString("%s");
					string text2 = qTMFormatUnitData.Config.UUT_SN + "-" + text + ".xml";
					if (onlySessionData)
					{
						qTMFormatUnitData.WriteXml(qtmXmlFolderPath, text2);
					}
					else
					{
						qTMFormatUnitData.WriteXmlWithDataIdentifier(qtmXmlFolderPath, text2, processDataIdentifier: true);
					}
					currentQsprToQtmXmlFilePath = Path.Combine(qtmXmlFolderPath, text2);
				}
				if (!string.IsNullOrEmpty(csvFolderPath))
				{
					qTMFormatUnitData.WriteCSV(csvFolderPath, null, "", "");
					currentQsprToCsvFilePath = Path.Combine(csvFolderPath, Path.GetFileName(qsprFilePath));
				}
				if (this.QsprOutputGenerated != null)
				{
					this.QsprOutputGenerated(this, EventArgs.Empty);
				}
			}
			return 0;
		}
		catch (Exception ex2)
		{
			errormessage = "Error generating output - " + ex2.Message;
			return -8019;
		}
	}

	public QTMFormatUnitData GenerateQtmXmlUnitData(string qsprFilePath, List<string> selectedTestNamesCollection, List<string> selectedParameterNamesCollection, string aliasFilePath)
	{
		return GenerateQtmXmlUnitData(GetQSPRSource(qsprFilePath), selectedTestNamesCollection, selectedParameterNamesCollection, onlySessionData: false, aliasFilePath);
	}

	public QTMFormatUnitData GenerateQtmXmlUnitData(string qsprFilePath, List<string> selectedTestNamesCollection, List<string> selectedParameterNamesCollection, bool onlySessionData, string aliasFilePath)
	{
		return GenerateQtmXmlUnitData(GetQSPRSource(qsprFilePath), selectedTestNamesCollection, selectedParameterNamesCollection, onlySessionData, aliasFilePath);
	}

	public QTMFormatUnitData GenerateQtmXmlUnitData(source qsprDataSource, List<string> selectedTestNamesCollection, List<string> selectedParameterNamesCollection, string aliasFilePath)
	{
		return GenerateQtmXmlUnitData(qsprDataSource, selectedTestNamesCollection, selectedParameterNamesCollection, onlySessionData: false, aliasFilePath);
	}

	public string GetFormattedXmlName(string qsprFilePath)
	{
		source qSPRSource = GetQSPRSource(qsprFilePath);
		TestColl validQSPRTestCollection = GetValidQSPRTestCollection(qSPRSource);
		QTMFormatUnitData qtmData = new QTMFormatUnitData();
		CreateQtmDataConfiguration(validQSPRTestCollection, qtmData);
		string iD = validQSPRTestCollection.UUT.ID;
		string name = validQSPRTestCollection.Tester.Name;
		string text = new DateTime(validQSPRTestCollection.Date.YYYY, validQSPRTestCollection.Date.MM, validQSPRTestCollection.Date.DD).ToString("ddMMMyyyy");
		string text2 = validQSPRTestCollection.Time.Stop.HH + "h" + validQSPRTestCollection.Time.Stop.MM + "m" + validQSPRTestCollection.Time.Stop.SS + "s";
		string text3 = "";
		string text4 = "";
		string v = validQSPRTestCollection.PassFail.DI.V;
		double num = 0.0;
		double num2 = 0.0;
		Dictionary<string, Dictionary<string, string>> dictionary = new Dictionary<string, Dictionary<string, string>>();
		List<string> list = CreateConfigurationLoopCollection();
		foreach (Tests item in validQSPRTestCollection.Test)
		{
			try
			{
				DIValue dIValue = (DIValue)item.PassFail.DI[0];
				if (dIValue.V.Equals("PASS"))
				{
					num += 1.0;
				}
				else
				{
					num2 += 1.0;
				}
			}
			catch
			{
			}
			try
			{
				foreach (DataSetColl item2 in item.DataSetCollection)
				{
					try
					{
						foreach (DataSets item3 in item2.DataSet)
						{
							try
							{
								GetQsprTestName(item, item2);
								Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
								List<string> list2 = ProcessParameters(item3, list, dictionary2);
								if (list2 == null || list2.Count <= 0)
								{
									continue;
								}
								GetLoopConditionsFromCurrentQSPRDataSet(list, item, item3, dictionary2);
								GetLoopConditionsFromReferencedQSPRDataSets(list, dictionary, item, item3, dictionary2);
								if (!dictionary.ContainsKey(item3.id))
								{
									dictionary.Add(item3.id, dictionary2);
								}
								if (!(text4 == "") && !(text3 == ""))
								{
									break;
								}
								Input inputs = item3.Inputs;
								if (inputs == null)
								{
									continue;
								}
								for (int i = 0; i < inputs.DI.Count; i++)
								{
									if (text4 != "" && text3 != "")
									{
										break;
									}
									DIValue dIValue2 = (DIValue)inputs.DI[i];
									string text5 = dIValue2.N.Trim();
									string text6 = dIValue2.V.Trim();
									if (text5.Equals("Band"))
									{
										text4 = text6;
									}
									if (text5.Equals("Temp"))
									{
										text3 = text6;
									}
								}
								continue;
							}
							catch
							{
							}
						}
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
		}
		try
		{
			string text7 = "";
			text7 = ((num + num2 == 0.0) ? (0 + "pcPass") : ((int)(num / (num + num2) * 100.0) + "pcPass"));
			string text8 = iD + "__" + name + "__" + text + "_" + text2 + "_Temp" + text3 + "_Band" + text4 + "_" + text7 + "_" + v;
			return text8 + ".xml";
		}
		catch
		{
			return null;
		}
	}

	public string GetShortFormattedXmlName(string qsprFilePath)
	{
		source qSPRSource = GetQSPRSource(qsprFilePath);
		TestColl validQSPRTestCollection = GetValidQSPRTestCollection(qSPRSource);
		QTMFormatUnitData qtmData = new QTMFormatUnitData();
		CreateQtmDataConfiguration(validQSPRTestCollection, qtmData);
		string iD = validQSPRTestCollection.UUT.ID;
		string text = validQSPRTestCollection.Tester.Name.Replace("Superstation", "SS");
		new DateTime(validQSPRTestCollection.Date.YYYY, validQSPRTestCollection.Date.MM, validQSPRTestCollection.Date.DD).ToString("ddMMMyyyy");
		_ = validQSPRTestCollection.Time.Stop.HH + "h" + validQSPRTestCollection.Time.Stop.MM + "m" + validQSPRTestCollection.Time.Stop.SS + "s";
		string text2 = validQSPRTestCollection.Time.Duration.HH + "h" + validQSPRTestCollection.Time.Duration.MM + "m" + validQSPRTestCollection.Time.Duration.SS + "s";
		string text3 = "";
		List<string> list = new List<string>();
		string v = validQSPRTestCollection.PassFail.DI.V;
		double num = 0.0;
		double num2 = 0.0;
		Dictionary<string, Dictionary<string, string>> dictionary = new Dictionary<string, Dictionary<string, string>>();
		List<string> list2 = CreateConfigurationLoopCollection();
		foreach (Tests item in validQSPRTestCollection.Test)
		{
			try
			{
				DIValue dIValue = (DIValue)item.PassFail.DI[0];
				if (dIValue.V.Equals("PASS"))
				{
					num += 1.0;
				}
				else
				{
					num2 += 1.0;
				}
			}
			catch
			{
			}
			try
			{
				foreach (DataSetColl item2 in item.DataSetCollection)
				{
					try
					{
						foreach (DataSets item3 in item2.DataSet)
						{
							try
							{
								GetQsprTestName(item, item2);
								Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
								List<string> list3 = ProcessParameters(item3, list2, dictionary2);
								if ((list3 == null || list3.Count <= 0) && (from DIValue x in item3.Inputs.DI
									where x.N == "Agg_Band"
									select x).Count() <= 0)
								{
									continue;
								}
								GetLoopConditionsFromCurrentQSPRDataSet(list2, item, item3, dictionary2);
								GetLoopConditionsFromReferencedQSPRDataSets(list2, dictionary, item, item3, dictionary2);
								if (!dictionary.ContainsKey(item3.id))
								{
									dictionary.Add(item3.id, dictionary2);
								}
								Input inputs = item3.Inputs;
								if (inputs == null)
								{
									break;
								}
								for (int i = 0; i < inputs.DI.Count; i++)
								{
									DIValue dIValue2 = (DIValue)inputs.DI[i];
									string text4 = dIValue2.N.Trim();
									string text5 = dIValue2.V.Trim();
									if ((text4.Equals("Band") || text4.Equals("Agg_Band") || (text4.StartsWith("Vic_") && text4.EndsWith("Band"))) && !list.Contains(text5))
									{
										list.Add(text5);
									}
									if (text4.Equals("Temp") && text3 == "")
									{
										text3 = text5;
									}
								}
								continue;
							}
							catch
							{
							}
						}
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
		}
		try
		{
			string text6 = "";
			text6 = ((num + num2 == 0.0) ? (0 + "pcPass") : ((int)(num / (num + num2) * 100.0) + "pcPass"));
			string text7 = "B" + string.Join("-B", list.ToArray());
			string text8 = iD + "__" + text + "_" + text7 + "_" + text3 + "C_" + text2 + "_" + text6 + "_" + v;
			return text8 + ".xml";
		}
		catch
		{
			return null;
		}
	}

	public QTMFormatUnitData GenerateQtmXmlUnitData(source qsprDataSource, List<string> selectedTestNamesCollection, List<string> selectedParameterNamesCollection, bool onlySessionData, string aliasFilePath)
	{
		ClearOutputFilePaths();
		addedQSPRExceptions.Clear();
		QTMFormatUnitData qTMFormatUnitData = new QTMFormatUnitData();
		TestColl validQSPRTestCollection = GetValidQSPRTestCollection(qsprDataSource);
		DataTable aliasData = GetAliasData(aliasFilePath);
		if (!onlySessionData)
		{
			AddQSPRTestsToQtmData(validQSPRTestCollection, qTMFormatUnitData, selectedTestNamesCollection, selectedParameterNamesCollection, aliasData);
		}
		CreateQtmDataConfiguration(validQSPRTestCollection, qTMFormatUnitData);
		return qTMFormatUnitData;
	}

	public long WriteSuiteFileToDatabase(string suiteFilePath, List<string> selectedTestNamesCollection, List<string> selectedParameterNamesCollection, string connectionString, string treeType)
	{
		if (!File.Exists(suiteFilePath))
		{
			throw new ArgumentException("Suite file path specified is not valid");
		}
		if (string.IsNullOrEmpty(connectionString))
		{
			throw new ArgumentException("Connection string cannot be null or empty");
		}
		source qSPRSource = GetQSPRSource(suiteFilePath);
		QTMFormatUnitData qTMFormatUnitData = GenerateQtmXmlUnitData(qSPRSource, selectedTestNamesCollection, selectedParameterNamesCollection, onlySessionData: false, null);
		if (qTMFormatUnitData.Tests != null && qTMFormatUnitData.Tests.Count > 0)
		{
			qTMFormatUnitData.Config.SessionName = suiteFilePath;
			qTMFormatUnitData.Config.TreeType = treeType;
			qTMFormatUnitData.AddConfig("ParamResult", "ParamResult");
			qTMFormatUnitData.Config.WORKSTATION = qTMFormatUnitData.Config.MachineName;
			return qTMFormatUnitData.WriteToDatabase(connectionString);
		}
		return -1L;
	}

	private void AddQSPRTestsToQtmData(TestColl qsprTestCollection, QTMFormatUnitData qtmData, List<string> selectedTestNamesCollection, List<string> selectedParametersCollection, DataTable aliasTbl)
	{
		List<string> list = CreateConfigurationLoopCollection();
		Dictionary<string, Dictionary<string, string>> dictionary = new Dictionary<string, Dictionary<string, string>>();
		bool flag = selectedParametersCollection != null && selectedParametersCollection.Count > 0;
		foreach (Tests item in qsprTestCollection.Test)
		{
			try
			{
				Test test = null;
				TimeSpan testDuration = TimeSpan.MinValue;
				if (item.Time != null && item.Time.Duration.HH >= 0 && item.Time.Duration.MM >= 0 && item.Time.Duration.MS >= 0 && item.Time.Duration.SS >= 0)
				{
					testDuration = new TimeSpan(0, item.Time.Duration.HH, item.Time.Duration.MM, item.Time.Duration.SS, item.Time.Duration.MS);
				}
				if (item.DataSetCollection.Count == 0)
				{
					if (IsInList(selectedTestNamesCollection, item.ExtendedName) && !flag)
					{
						test = qtmData.AddTest(item.ExtendedName, GetTestResult(item), "0", testDuration, "");
					}
				}
				else
				{
					foreach (DataSetColl item2 in item.DataSetCollection)
					{
						foreach (DataSets item3 in item2.DataSet)
						{
							string qsprTestName = GetQsprTestName(item, item2);
							Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
							List<string> list2 = ProcessParameters(item3, list, dictionary2);
							if (!includeParametricData)
							{
								list2 = null;
							}
							if (list2 != null && list2.Count > 0)
							{
								Dictionary<string, string> dictionary3 = null;
								if (aliasTbl != null && aliasTbl.Rows.Count > 0)
								{
									dictionary3 = GetAliasInformation(item, list2, qsprTestName, aliasTbl);
								}
								if (IsInList(selectedTestNamesCollection, qsprTestName) && IsInList(selectedParametersCollection, list2))
								{
									string text = string.Empty;
									if ((list == null || list.Count == 0) && selectedParametersCollection != null)
									{
										GetLoopConditionsFromReferencedQSPRDataSets(selectedParametersCollection, dictionary, item, item3, dictionary2);
										GetLoopConditionsFromCurrentQSPRDataSet(selectedParametersCollection, item, item3, dictionary2);
									}
									else
									{
										GetLoopConditionsFromReferencedQSPRDataSets(list, dictionary, item, item3, dictionary2);
										GetLoopConditionsFromCurrentQSPRDataSet(list, item, item3, dictionary2);
									}
									if (!dictionary.ContainsKey(item3.id))
									{
										dictionary.Add(item3.id, dictionary2);
									}
									Output outputs = item3.Outputs;
									if (outputs != null)
									{
										foreach (Results item4 in outputs.Result)
										{
											if (item4.invalid && IgnoreInvalidResults)
											{
												continue;
											}
											DIValue dI = item4.DI;
											if (list.Contains(dI.N.Trim()) || !IsInList(selectedParametersCollection, dI.N))
											{
												continue;
											}
											if (dictionary3 == null)
											{
												if (text != qsprTestName)
												{
													test = qtmData.AddTest(qsprTestName, GetTestResult(item), "0", testDuration, string.Empty);
													AddLoopConditionsList(qtmData, dictionary2);
													text = qsprTestName;
												}
											}
											else
											{
												string text2 = dictionary3[dI.N];
												if (text2 != text)
												{
													text = text2;
													test = qtmData.AddTest(text2, GetTestResult(item), "0", testDuration, string.Empty);
													AddLoopConditionsList(qtmData, dictionary2);
												}
											}
											AddQsprParameter(qtmData, item4, dI);
										}
									}
									if (IsInList(selectedParametersCollection, errorMessageParameterName))
									{
										if (string.IsNullOrEmpty(text))
										{
											test = qtmData.AddTest(qsprTestName, GetTestResult(item), "0", testDuration, string.Empty);
											AddLoopConditionsList(qtmData, dictionary2);
											text = qsprTestName;
										}
										AddQSPRTestExceptions(qtmData, item3);
									}
								}
								else
								{
									if ((list == null || list.Count == 0) && selectedParametersCollection != null)
									{
										GetLoopConditionsFromReferencedQSPRDataSets(selectedParametersCollection, dictionary, item, item3, dictionary2);
										GetLoopConditionsFromCurrentQSPRDataSet(selectedParametersCollection, item, item3, dictionary2);
									}
									else
									{
										GetLoopConditionsFromReferencedQSPRDataSets(list, dictionary, item, item3, dictionary2);
										GetLoopConditionsFromCurrentQSPRDataSet(list, item, item3, dictionary2);
									}
									if (!dictionary.ContainsKey(item3.id))
									{
										dictionary.Add(item3.id, dictionary2);
									}
								}
							}
							else
							{
								if ((list == null || list.Count == 0) && selectedParametersCollection != null)
								{
									GetLoopConditionsFromReferencedQSPRDataSets(selectedParametersCollection, dictionary, item, item3, dictionary2);
									GetLoopConditionsFromCurrentQSPRDataSet(selectedParametersCollection, item, item3, dictionary2);
								}
								else
								{
									GetLoopConditionsFromReferencedQSPRDataSets(list, dictionary, item, item3, dictionary2);
									GetLoopConditionsFromCurrentQSPRDataSet(list, item, item3, dictionary2);
								}
								if (!dictionary.ContainsKey(item3.id))
								{
									dictionary.Add(item3.id, dictionary2);
								}
								if (IsInList(selectedTestNamesCollection, qsprTestName) && !flag)
								{
									test = qtmData.AddTest(qsprTestName, GetTestResult(item), "0", testDuration, "");
								}
							}
						}
					}
				}
				try
				{
					if (test != null)
					{
						test.TestStartTime = item.Time.Start.HH + ":" + item.Time.Start.MM + ":" + item.Time.Start.SS;
						test.TestStopTime = item.Time.Stop.HH + ":" + item.Time.Stop.MM + ":" + item.Time.Stop.SS;
					}
				}
				catch
				{
				}
			}
			catch (Exception ex)
			{
				throw new QsprConversionException(" Test " + item.Name + "failed to load: " + ex.Message, -4561);
			}
		}
		dictionary = null;
	}

	private bool AddQSPRTestExceptions(QTMFormatUnitData qtmData, DataSets currDataSet)
	{
		bool result = false;
		if (currDataSet.Exceptions != null && currDataSet.Exceptions.Exception != null)
		{
			foreach (QSPRTestException item in currDataSet.Exceptions.Exception)
			{
				result = true;
				if (!addedQSPRExceptions.Contains(item.Name))
				{
					qtmData.AddConfig(item.Name, item.Name);
					addedQSPRExceptions.Add(item.Name);
				}
				qtmData.AddParamToCurrentTest(errorMessageParameterName, string.Empty, item.Description);
			}
		}
		return result;
	}

	private static void AddQsprParameter(QTMFormatUnitData qtmData, Results results, DIValue data)
	{
		if (!double.TryParse(data.V, out var result))
		{
			qtmData.AddParamToCurrentTest(data.N, "", data.V, "1");
			return;
		}
		string unitOfMeasure = "";
		if (data.U != null)
		{
			unitOfMeasure = data.U;
		}
		qtmData.AddParamToCurrentTest(data.N, unitOfMeasure, result, results.Limits.Max, results.Limits.Min);
	}

	private void AddLoopConditionsList(QTMFormatUnitData qtmData, Dictionary<string, string> currentTestLoopConditions)
	{
		foreach (KeyValuePair<string, string> currentTestLoopCondition in currentTestLoopConditions)
		{
			qtmData.AddLoopConditionsToCurrentTest(currentTestLoopCondition.Key, currentTestLoopCondition.Value);
		}
	}

	private QTMFormatUnitData.Result GetTestResult(Tests test)
	{
		DIValue dIValue = new DIValue();
		if (test.PassFail != null)
		{
			dIValue = (DIValue)test.PassFail.DI[0];
		}
		else
		{
			dIValue.V = defaultResult;
		}
		if (!dIValue.V.Contains("PASS"))
		{
			return QTMFormatUnitData.Result.Failed;
		}
		return QTMFormatUnitData.Result.Passed;
	}

	private Dictionary<string, string> GetAliasInformation(Tests currentTest, List<string> currentDataSetParameters, string qtmTestName, DataTable aliasTable)
	{
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		foreach (string currentDataSetParameter in currentDataSetParameters)
		{
			DataRow[] array = aliasTable.Select($"testID = '{currentTest.Name}' AND resID = '{currentDataSetParameter}'");
			string value = qtmTestName;
			if (array.Length == 1)
			{
				value = array[0]["name"].ToString();
			}
			if (!dictionary.ContainsKey(currentDataSetParameter))
			{
				dictionary.Add(currentDataSetParameter, value);
			}
		}
		return dictionary;
	}

	private List<string> ProcessParameters(DataSets currDataSet, List<string> userSelectedLoopConditions, Dictionary<string, string> currentTestLoopConditions)
	{
		List<string> list = new List<string>();
		if (currDataSet.Exceptions != null)
		{
			list.Add(errorMessageParameterName);
		}
		Output outputs = currDataSet.Outputs;
		if (outputs != null)
		{
			foreach (Results item in outputs.Result)
			{
				DIValue dI = item.DI;
				if (userSelectedLoopConditions.Contains(dI.N.Trim()))
				{
					if (!currentTestLoopConditions.ContainsKey(dI.N.Trim()))
					{
						currentTestLoopConditions.Add(dI.N, string.Empty);
					}
				}
				else if (!list.Contains(dI.N))
				{
					list.Add(dI.N);
				}
			}
		}
		return list;
	}

	private void GetLoopConditionsFromReferencedQSPRDataSets(List<string> userSelectedLoopNamesCollection, Dictionary<string, Dictionary<string, string>> dataSetLoopConditionsMapping, Tests test, DataSets currDataSet, Dictionary<string, string> currentTestLoopConditions)
	{
		if (currDataSet.DSRef == null || currDataSet.DSRef.Count <= 0)
		{
			return;
		}
		foreach (DSRefInfo item in currDataSet.DSRef)
		{
			if (!dataSetLoopConditionsMapping.ContainsKey(item.id))
			{
				continue;
			}
			Dictionary<string, string> dictionary = dataSetLoopConditionsMapping[item.id];
			foreach (KeyValuePair<string, string> item2 in dictionary)
			{
				currentTestLoopConditions[item2.Key] = item2.Value;
			}
		}
	}

	private static void GetLoopConditionsFromCurrentQSPRDataSet(List<string> userSelectedLoopNamesCollection, Tests test, DataSets currDataSet, Dictionary<string, string> currentTestLoopConditions)
	{
		Input inputs = currDataSet.Inputs;
		if (inputs == null)
		{
			return;
		}
		foreach (DIValue item in inputs.DI)
		{
			try
			{
				if (userSelectedLoopNamesCollection.Contains(item.N.Trim()) || userSelectedLoopNamesCollection.Count == 0)
				{
					currentTestLoopConditions[item.N.Trim()] = item.V;
				}
			}
			catch (Exception ex)
			{
				throw new QsprConversionException(" Test " + test.Name + "failed loop conditions: " + ex.Message, -4567);
			}
		}
	}

	private string GetQsprTestName(Tests test, DataSetColl dataColl)
	{
		string text = test.Name.Trim();
		if (AppendDataSetCollectionName && !string.IsNullOrEmpty(dataColl.Name))
		{
			text = text + "__" + dataColl.Name.Trim();
		}
		return text;
	}

	private void CreateQtmDataConfiguration(TestColl qsprTestsCollection, QTMFormatUnitData qtmData)
	{
		string serialNumber = GetSerialNumber(qsprTestsCollection);
		GetUnitStartAndStopDateTime(qsprTestsCollection, out var startDateTime, out var stopDateTime);
		QTMFormatUnitData.Result result = QTMFormatUnitData.Result.Passed;
		result = QTMFormatUnitData.Result.Exception;
		if (qsprTestsCollection.PassFail.DI != null)
		{
			if (qsprTestsCollection.PassFail.DI.V.ToLower() == "fail")
			{
				result = QTMFormatUnitData.Result.Failed;
			}
			else if (qsprTestsCollection.PassFail.DI.V.ToLower() == "pass")
			{
				result = QTMFormatUnitData.Result.Passed;
			}
		}
		string text = qsprTestsCollection.Image.Filename;
		if (!string.IsNullOrEmpty(text))
		{
			FileInfo fileInfo = new FileInfo(text);
			text = fileInfo.Name;
		}
		if (!string.IsNullOrEmpty(testTreeIDOverride))
		{
			treeID = testTreeIDOverride;
		}
		if (useNamedLogProcessing)
		{
			qtmData.AddStandardConfig(serialNumber, result, startDateTime.ToString(), stopDateTime.ToString(), qsprTestsCollection.Tester.Type.Replace(" SUITE", ""), TreeID, qsprTestsCollection.Tester.Name, MCN, string.Empty, QTMFormatUnitData.ExtendedDataType.No, string.Empty, text, "DVT", MachineName, RegisteredMachine, string.Empty, string.Empty, string.Empty, SiteKey, Database, Server, SiteTreeID);
		}
		else
		{
			qtmData.AddStandardConfig(serialNumber, result, startDateTime.ToString(), stopDateTime.ToString(), TesterID, TreeID, Workstation, MCN, string.Empty, (QTMFormatUnitData.ExtendedDataType)ExtendedData, string.Empty, text, TreeType, MachineName, RegisteredMachine, string.Empty, string.Empty, string.Empty, SiteKey, Database, Server, SiteTreeID);
		}
		if (useNamedLogProcessing)
		{
			new Dictionary<string, DataSets>();
			CreateConfigurationLoopCollection();
			foreach (Tests item in qsprTestsCollection.Test)
			{
				try
				{
					foreach (DataSetColl item2 in item.DataSetCollection)
					{
						try
						{
							foreach (DataSets item3 in item2.DataSet)
							{
								try
								{
									string qsprTestName = GetQsprTestName(item, item2);
									bool flag = runtitleLogNames != null && runtitleLogNames.Contains(qsprTestName);
									bool flag2 = configLogNames != null && configLogNames.Contains(qsprTestName);
									if (!flag && !flag2)
									{
										continue;
									}
									string text2 = null;
									if (item3.Inputs != null && item3.Inputs.DI != null)
									{
										foreach (DIValue item4 in item3.Inputs.DI)
										{
											try
											{
												string text3 = item4.N.Trim();
												string text4 = item4.V.Trim();
												if (text3.CompareTo(qsprTestName) == 0)
												{
													text2 = text4;
													break;
												}
											}
											catch
											{
											}
										}
									}
									if (text2 == null)
									{
										foreach (object item5 in item3.Outputs.Result)
										{
											try
											{
												Results results = (Results)item5;
												string text5 = results.DI.N.Trim();
												string text6 = results.DI.V.Trim();
												if (text5.CompareTo(qsprTestName) == 0)
												{
													text2 = text6;
													break;
												}
											}
											catch
											{
											}
										}
									}
									if (text2 != null)
									{
										if (flag2)
										{
											qtmData.AddConfigTag(qsprTestName, text2);
										}
										else if (flag)
										{
											qtmData.AddConfig(qsprTestName, text2);
										}
									}
								}
								catch
								{
								}
							}
						}
						catch
						{
						}
					}
				}
				catch
				{
				}
			}
		}
		try
		{
			qtmData.AddConfig("QSPR", "QSPR");
			if (string.IsNullOrEmpty(RunTitle))
			{
				return;
			}
			string text7 = RunTitle;
			string[] array = text7.Split(',');
			string[] array2 = array;
			foreach (string text8 in array2)
			{
				try
				{
					string[] array3 = text8.Split('=');
					qtmData.AddConfig(array3[0].Trim(), array3[1].Trim());
				}
				catch
				{
				}
			}
		}
		catch
		{
		}
	}

	private DataTable GetAliasData(string aliasFilePath)
	{
		if (!File.Exists(aliasFilePath))
		{
			return null;
		}
		return CsvToDataTable(aliasFilePath);
	}

	public static DataTable CsvToDataTable(string csvFilePath)
	{
		if (!File.Exists(csvFilePath))
		{
			throw new ApplicationException("csv file does not exist");
		}
		DataTable dataTable = new DataTable();
		StreamReader streamReader = null;
		string[] csvSplitString = new string[1] { "," };
		try
		{
			streamReader = new StreamReader(csvFilePath);
			bool flag = true;
			while (!streamReader.EndOfStream)
			{
				if (flag)
				{
					ExtractHeaderInformation(dataTable, streamReader, csvSplitString);
					flag = false;
				}
				else
				{
					ExtractDataInformation(dataTable, streamReader, csvSplitString);
				}
			}
			return dataTable;
		}
		catch (Exception innerException)
		{
			throw new ApplicationException("Error extracting data from csv file:" + csvFilePath, innerException);
		}
		finally
		{
			streamReader?.Close();
		}
	}

	private static void ExtractDataInformation(DataTable tbl, StreamReader sr, string[] csvSplitString)
	{
		string text = sr.ReadLine();
		string[] array = text.Split(csvSplitString, StringSplitOptions.None);
		DataRow dataRow = tbl.NewRow();
		int num = tbl.Columns.Count;
		if (array.Length < tbl.Columns.Count)
		{
			num = array.Length;
		}
		for (int i = 0; i < num; i++)
		{
			dataRow[i] = RemoveCsvFormatting(array[i]);
		}
		tbl.Rows.Add(dataRow);
	}

	private static void ExtractHeaderInformation(DataTable tbl, StreamReader sr, string[] csvSplitString)
	{
		string text = sr.ReadLine();
		string[] array = text.Split(csvSplitString, StringSplitOptions.None);
		string[] array2 = array;
		foreach (string csvFormattedString in array2)
		{
			string text2 = RemoveCsvFormatting(csvFormattedString);
			if (!tbl.Columns.Contains(text2))
			{
				DataColumn column = new DataColumn(text2);
				tbl.Columns.Add(column);
			}
		}
	}

	private static string RemoveCsvFormatting(string csvFormattedString)
	{
		csvFormattedString = csvFormattedString.Replace("\"\"", "\"");
		if (csvFormattedString.StartsWith("\"") && csvFormattedString.EndsWith("\""))
		{
			csvFormattedString = csvFormattedString.Remove(0, 1);
			csvFormattedString = csvFormattedString.Remove(csvFormattedString.Length - 1, 1);
		}
		return csvFormattedString;
	}

	public IEnumerable<DataSets> GetReleatedDataSets(DataSets dataSet, Dictionary<string, DataSets> refTests)
	{
		if (dataSet.DSRef == null || dataSet.DSRef.Count <= 0)
		{
			yield break;
		}
		foreach (DSRefInfo dataSetReferenceInfo in dataSet.DSRef)
		{
			if (!refTests.ContainsKey(dataSetReferenceInfo.id))
			{
				continue;
			}
			DataSets relatedDataSet = refTests[dataSetReferenceInfo.id];
			yield return relatedDataSet;
			foreach (DataSets releatedDataSet in GetReleatedDataSets(relatedDataSet, refTests))
			{
				yield return releatedDataSet;
			}
		}
	}

	public void GenerateQSPRXmlData(QTMFormatUnitData unitData, string qsprXmlFilePath, string styleSheetPath)
	{
		source qSPRSource = GetQSPRSource(unitData);
		WriteQSPRSourceToXml(qSPRSource, qsprXmlFilePath, styleSheetPath);
	}

	public void ConvertQtmXmlToQsprXml(string qtmXmlFilePath, string qsprXmlFilePath)
	{
		if (!File.Exists(qtmXmlFilePath))
		{
			throw new FileNotFoundException("Unable to find file", qtmXmlFilePath);
		}
		ROOT rOOT = ROOT.LoadFromFile(qtmXmlFilePath);
		QTMFormatUnitData unitData = rOOT.ConvertToQtmFormatUnitData();
		GenerateQSPRXmlData(unitData, qsprXmlFilePath, string.Empty);
	}

	private void WriteQSPRSourceToXml(source qsprSource, string qsprXmlFilePath, string styleSheetPath)
	{
		using FileStream output = new FileStream(qsprXmlFilePath, FileMode.Create);
		XmlSerializer xmlSerializer = new XmlSerializer(qsprSource.GetType());
		XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
		XmlSerializerNamespaces xmlSerializerNamespaces = new XmlSerializerNamespaces();
		xmlSerializerNamespaces.Add("", "");
		xmlWriterSettings.OmitXmlDeclaration = true;
		xmlWriterSettings.NewLineChars = string.Empty;
		using (XmlWriter xmlWriter = XmlWriter.Create(output, xmlWriterSettings))
		{
			if (!string.IsNullOrEmpty(styleSheetPath))
			{
				xmlWriter.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href ='" + styleSheetPath + "'");
			}
			xmlSerializer.Serialize(xmlWriter, qsprSource);
		}
		if (this.QsprOutputGenerated != null)
		{
			this.QsprOutputGenerated(this, EventArgs.Empty);
		}
	}

	public List<string> GenerateSuiteData(DataTable parametricDataTbl, string folderPath, string styleSheetPath, bool useTestRealNamesAsDefault = false)
	{
		List<string> list = new List<string>();
		useRealNamesAsDefault = useTestRealNamesAsDefault;
		if (!Directory.Exists(folderPath))
		{
			Directory.CreateDirectory(folderPath);
		}
		foreach (source item in GenerateSuiteObject(parametricDataTbl))
		{
			if (this.GeneratingQsprOutput != null)
			{
				QsprFileToConvertEventArgs qsprFileToConvertEventArgs = new QsprFileToConvertEventArgs();
				this.GeneratingQsprOutput(this, qsprFileToConvertEventArgs);
				if (qsprFileToConvertEventArgs.CancelConversion)
				{
					break;
				}
			}
			string filePath = GetFilePath(folderPath, item);
			WriteQSPRSourceToXml(item, filePath, styleSheetPath);
			list.Add(filePath);
		}
		return list;
	}

	private string GetFilePath(string folderPath, source qsprObj)
	{
		TestColl validQSPRTestCollection = GetValidQSPRTestCollection(qsprObj);
		string serialNumber = GetSerialNumber(validQSPRTestCollection);
		GetUnitStartAndStopDateTime(validQSPRTestCollection, out var startDateTime, out var _);
		string text = startDateTime.ToString("%M") + "_" + startDateTime.ToString("%d") + "_" + startDateTime.ToString("%y") + "__" + startDateTime.ToString("%H") + "_" + startDateTime.ToString("%m") + "_" + startDateTime.ToString("%s");
		string testerId = GetValidQSPRTestCollection(qsprObj).GetTesterId();
		return Path.Combine(folderPath, serialNumber + "_" + testerId + "_" + text + ".xml");
	}

	private IEnumerable<source> GenerateSuiteObject(DataTable parametricDataTbl)
	{
		source qsprObj = null;
		if (parametricDataTbl == null || parametricDataTbl.Rows.Count <= 0)
		{
			yield break;
		}
		string currentSessionDataRID = string.Empty;
		string currentNodeDataRID = string.Empty;
		List<DataRow> paramDataRowsPerNodeDataRID = new List<DataRow>();
		string sortExpression = string.Join(", ", new List<string> { "SessionDataRID", "NodeDataRID" }.ToArray());
		try
		{
			DataRow[] array = parametricDataTbl.Select(null, sortExpression);
			foreach (DataRow paramRow in array)
			{
				if (currentSessionDataRID != paramRow["SessionDataRID"].ToString())
				{
					currentSessionDataRID = paramRow["SessionDataRID"].ToString();
					if (qsprObj != null)
					{
						WriteTestInformation(qsprObj, paramDataRowsPerNodeDataRID);
						yield return qsprObj;
						paramDataRowsPerNodeDataRID.Clear();
						currentNodeDataRID = string.Empty;
					}
					qsprObj = new source();
					WriteConfigurationInformation(qsprObj, paramRow);
					WriteConfigurationTest(qsprObj, paramRow);
				}
				if (currentNodeDataRID != paramRow["NodeDataRID"].ToString())
				{
					if (!string.IsNullOrEmpty(currentNodeDataRID))
					{
						WriteTestInformation(qsprObj, paramDataRowsPerNodeDataRID);
					}
					currentNodeDataRID = paramRow["NodeDataRID"].ToString();
					paramDataRowsPerNodeDataRID.Clear();
				}
				paramDataRowsPerNodeDataRID.Add(paramRow);
			}
		}
		finally
		{
		}
		WriteTestInformation(qsprObj, paramDataRowsPerNodeDataRID);
		yield return qsprObj;
	}

	private void WriteConfigurationTest(source qsprObj, DataRow sessionDataRow)
	{
		if (sessionDataRow == null)
		{
			return;
		}
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		if (!Convert.IsDBNull(sessionDataRow["VisitNum"]) && !string.IsNullOrEmpty(sessionDataRow["VisitNum"].ToString()))
		{
			dictionary.Add("VisitNum", sessionDataRow["VisitNum"].ToString());
		}
		if (!Convert.IsDBNull(sessionDataRow["LastVisit"]) && !string.IsNullOrEmpty(sessionDataRow["LastVisit"].ToString()))
		{
			dictionary.Add("LastVisit", sessionDataRow["LastVisit"].ToString());
		}
		if (!Convert.IsDBNull(sessionDataRow["MCN"]) && !string.IsNullOrEmpty(sessionDataRow["MCN"].ToString()))
		{
			dictionary.Add("MCN", sessionDataRow["MCN"].ToString());
		}
		if (!Convert.IsDBNull(sessionDataRow["TesterID"]) && !string.IsNullOrEmpty(sessionDataRow["TesterID"].ToString()))
		{
			dictionary.Add("TesterID", sessionDataRow["TesterID"].ToString());
		}
		if (!Convert.IsDBNull(sessionDataRow["TreeID"]) && !string.IsNullOrEmpty(sessionDataRow["TreeID"].ToString()))
		{
			dictionary.Add("TreeID", sessionDataRow["TreeID"].ToString());
		}
		if (!Convert.IsDBNull(sessionDataRow["WorkStation"]) && !string.IsNullOrEmpty(sessionDataRow["WorkStation"].ToString()))
		{
			dictionary.Add("WorkStation", sessionDataRow["WorkStation"].ToString());
		}
		if (!Convert.IsDBNull(sessionDataRow["RunTitle"]) && !string.IsNullOrEmpty(sessionDataRow["RunTitle"].ToString()))
		{
			Dictionary<string, string> dictionary2 = SplitLoopConditions(sessionDataRow["RunTitle"].ToString());
			foreach (KeyValuePair<string, string> item in dictionary2)
			{
				if (!dictionary.ContainsKey(item.Key))
				{
					dictionary.Add(item.Key, item.Value);
				}
			}
		}
		qsprObj.AddConfigurationTest(dictionary);
	}

	private void WriteConfigurationInformation(source qsprObj, DataRow sessionDataRow)
	{
		if (sessionDataRow == null)
		{
			return;
		}
		if (!Convert.IsDBNull(sessionDataRow["WorkStation"]))
		{
			workstation = sessionDataRow["WorkStation"].ToString();
		}
		if (sessionDataRow.Table.Columns.Contains("Comments") && !Convert.IsDBNull(sessionDataRow["Comments"]))
		{
			comments = sessionDataRow["Comments"].ToString();
		}
		if (sessionDataRow.Table.Columns.Contains("MachineName") && !Convert.IsDBNull(sessionDataRow["MachineName"]))
		{
			machineNamefromXML = sessionDataRow["MachineName"].ToString();
		}
		if (!DateTime.TryParse(sessionDataRow["StartTime"].ToString(), out var result))
		{
			try
			{
				result = DateTime.ParseExact(sessionDataRow["StartTime"].ToString(), "M/d/yy HH:mm:ss:fff", stringFormatProvider);
			}
			catch
			{
			}
		}
		if (!DateTime.TryParse(sessionDataRow["StopTime"].ToString(), out var result2))
		{
			try
			{
				result2 = DateTime.ParseExact(sessionDataRow["StopTime"].ToString(), "M/d/yy HH:mm:ss:fff", stringFormatProvider);
			}
			catch
			{
			}
		}
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		string swBuildId = null;
		if (!Convert.IsDBNull(sessionDataRow["RunTitle"]) && !string.IsNullOrEmpty(sessionDataRow["RunTitle"].ToString()))
		{
			Dictionary<string, string> dictionary2 = SplitLoopConditions(sessionDataRow["RunTitle"].ToString());
			foreach (KeyValuePair<string, string> item in dictionary2)
			{
				if (item.Key.StartsWith("DLL_"))
				{
					string key = item.Key.Replace("DLL_", "");
					dictionary[key] = item.Value;
				}
				else if (item.Key.ToLower() == "$SWBuildID".ToLower())
				{
					swBuildId = item.Value;
				}
			}
		}
		string treeFileName = string.Empty;
		if (sessionDataRow.Table.Columns.Contains("TreeFileName") && !Convert.IsDBNull(sessionDataRow["TreeFileName"]) && !string.IsNullOrEmpty(sessionDataRow["TreeFileName"].ToString()))
		{
			treeFileName = sessionDataRow["TreeFileName"].ToString();
		}
		qsprObj.AddConfiguration(sessionDataRow["UUT_SN"].ToString(), sessionDataRow["TesterID"].ToString(), sessionDataRow["DvtFlag"].ToString(), result, result2, sessionDataRow["GlobalResult"].ToString(), treeFileName, null, swBuildId, dictionary, workstation, comments, machineNamefromXML);
	}

	private void WriteTestInformation(source qsprObj, List<DataRow> paramDataRows)
	{
		if (qsprObj == null || qsprObj.TestCollection == null || qsprObj.TestCollection.Count <= 0 || paramDataRows == null || paramDataRows.Count <= 0)
		{
			return;
		}
		if (paramDataRows[0].Table.Columns.Contains("TestStartTime") && paramDataRows[0].Table.Columns.Contains("TestStopTime") && paramDataRows[0].Table.Columns.Contains("TestDuration") && !Convert.IsDBNull(paramDataRows[0]["TestStartTime"]) && !Convert.IsDBNull(paramDataRows[0]["TestStopTime"]) && !Convert.IsDBNull(paramDataRows[0]["TestDuration"]))
		{
			DateTime result = DateTime.MinValue;
			DateTime result2 = DateTime.MinValue;
			TimeSpan result3 = TimeSpan.MinValue;
			if (!DateTime.TryParse(paramDataRows[0]["TestStartTime"].ToString(), out result))
			{
				try
				{
					result = DateTime.ParseExact(paramDataRows[0]["TestStartTime"].ToString(), "M/d/yy HH:mm:ss:fff", stringFormatProvider);
				}
				catch
				{
				}
			}
			if (!DateTime.TryParse(paramDataRows[0]["TestStopTime"].ToString(), out result2))
			{
				try
				{
					result2 = DateTime.ParseExact(paramDataRows[0]["TestStopTime"].ToString(), "M/d/yy HH:mm:ss:fff", stringFormatProvider);
				}
				catch
				{
				}
			}
			if (!TimeSpan.TryParse(paramDataRows[0]["TestDuration"].ToString(), out result3))
			{
				try
				{
					result3 = TimeSpan.ParseExact(paramDataRows[0]["TestDuration"].ToString(), "c", stringFormatProvider);
				}
				catch
				{
				}
			}
			qsprObj.AddTest(paramDataRows[0]["TestName"].ToString(), paramDataRows[0]["RealName"].ToString(), paramDataRows[0]["TestPath"].ToString(), paramDataRows[0]["TestResult"].ToString(), result, result2, result3, useRealNamesAsDefault);
		}
		else
		{
			qsprObj.AddTest(paramDataRows[0]["TestName"].ToString(), paramDataRows[0]["TestResult"].ToString());
		}
		List<string> list = new List<string>(paramDataRows.Count);
		Dictionary<string, List<int>> dictionary = new Dictionary<string, List<int>>();
		List<int> list2 = new List<int>();
		for (int i = 0; i < paramDataRows.Count; i++)
		{
			if (Convert.IsDBNull(paramDataRows[i]["ArrayParamIndex"]))
			{
				list2.Add(i);
				if (!list.Contains(paramDataRows[i]["ScnValue"].ToString()))
				{
					string value = paramDataRows[i]["ScnValue"].ToString();
					if (!string.IsNullOrEmpty(value))
					{
						list.Add(paramDataRows[i]["ScnValue"].ToString());
					}
				}
				continue;
			}
			string text = paramDataRows[i]["ArrayParamIndex"].ToString();
			string key = text;
			if (paramDataRows[i].Table.Columns.Contains("ArrayParamColumnIndex") && !Convert.IsDBNull(paramDataRows[i]["ArrayParamColumnIndex"]))
			{
				string text2 = paramDataRows[i]["ArrayParamColumnIndex"].ToString();
				key = text + "_" + text2;
			}
			if (!dictionary.ContainsKey(key))
			{
				List<int> list3 = new List<int>();
				list3.Add(i);
				dictionary.Add(key, list3);
			}
			else
			{
				dictionary[key].Add(i);
			}
		}
		if (list.Count == 0)
		{
			list.Add(paramDataRows[0]["ScnValue"].ToString());
		}
		if (dictionary.Keys.Count > 0)
		{
			if (list2.Count > 0)
			{
				AddNonArrayDataSet(qsprObj, paramDataRows, list, list2);
			}
			{
				foreach (KeyValuePair<string, List<int>> item in dictionary)
				{
					qsprObj.StartNewDataSetInCurrentTest();
					Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
					List<string> list4 = new List<string>();
					list4.AddRange(list);
					foreach (int item2 in item.Value)
					{
						if (item.Key.Contains("_"))
						{
							string[] array = item.Key.Split('_');
							if (array.Length == 2)
							{
								dictionary2.Add("aIndex_" + paramDataRows[item2]["ParameterName"].ToString(), array[0]);
								dictionary2.Add("aColumnIndex_" + paramDataRows[item2]["ParameterName"].ToString(), array[1]);
							}
						}
						else
						{
							dictionary2.Add("aIndex_" + paramDataRows[item2]["ParameterName"].ToString(), item.Key);
						}
						qsprObj.AddParameterToCurrentTest(paramDataRows[item2]["ParameterName"].ToString(), paramDataRows[item2]["ArrayResult"].ToString(), paramDataRows[item2]["ArrayParamCharResult"].ToString(), paramDataRows[item2]["ArrayUpperLimit"].ToString(), paramDataRows[item2]["ArrayLowerLimit"].ToString(), paramDataRows[item2]["UOM"].ToString());
						if (!list4.Contains(paramDataRows[item2]["ScnValue"].ToString()))
						{
							string value2 = paramDataRows[item2]["ScnValue"].ToString();
							if (!string.IsNullOrEmpty(value2))
							{
								list4.Add(paramDataRows[item2]["ScnValue"].ToString());
							}
						}
					}
					if (list4.Count > 0)
					{
						foreach (string item3 in list4)
						{
							Dictionary<string, string> dictionary3 = new Dictionary<string, string>();
							foreach (KeyValuePair<string, string> item4 in SplitLoopConditions(item3))
							{
								dictionary3.Add(item4.Key, item4.Value);
							}
							foreach (KeyValuePair<string, string> item5 in dictionary2)
							{
								dictionary3.Add(item5.Key, item5.Value);
							}
							qsprObj.AddLoopConditionsToCurrentTest(dictionary3);
						}
					}
					else
					{
						if (dictionary2.Count <= 0)
						{
							continue;
						}
						Dictionary<string, string> dictionary4 = new Dictionary<string, string>();
						foreach (KeyValuePair<string, string> item6 in dictionary2)
						{
							dictionary4.Add(item6.Key, item6.Value);
						}
						qsprObj.AddLoopConditionsToCurrentTest(dictionary4);
					}
				}
				return;
			}
		}
		AddNonArrayDataSet(qsprObj, paramDataRows, list, list2);
	}

	private void AddNonArrayDataSet(source qsprObj, List<DataRow> paramDataRows, List<string> loopCondtionsList, List<int> nonArrayParametersRows)
	{
		foreach (int nonArrayParametersRow in nonArrayParametersRows)
		{
			qsprObj.AddParameterToCurrentTest(paramDataRows[nonArrayParametersRow]["ParameterName"].ToString(), paramDataRows[nonArrayParametersRow]["NumValue"].ToString(), paramDataRows[nonArrayParametersRow]["CharValue"].ToString(), paramDataRows[nonArrayParametersRow]["UpperLimit"].ToString(), paramDataRows[nonArrayParametersRow]["LowerLimit"].ToString(), paramDataRows[nonArrayParametersRow]["UOM"].ToString());
		}
		foreach (string loopCondtions in loopCondtionsList)
		{
			qsprObj.AddLoopConditionsToCurrentTest(SplitLoopConditions(loopCondtions));
		}
	}

	public DataTable GenerateQDMFormattedData(string qsprFilePath, bool pivotLoopConditions, List<string> testNames, List<string> parameterNames, string aliasFilePath)
	{
		try
		{
			QTMFormatUnitData qTMFormatUnitData = GenerateQtmXmlUnitData(qsprFilePath, testNames, parameterNames, aliasFilePath);
			DataTable dataTable = qTMFormatUnitData.ToTable();
			if (pivotLoopConditions)
			{
				PivotLoopConditions(dataTable);
			}
			if (dataTable.Columns.Contains("ScnValue"))
			{
				dataTable.Columns["ScnValue"].SetOrdinal(dataTable.Columns.Count - 1);
			}
			return dataTable;
		}
		catch (Exception ex)
		{
			throw new QsprConversionException("Error while converting QSPR file to DataTable: " + ex.ToString() + Environment.NewLine + ex.StackTrace, -6789);
		}
	}

	private void PivotLoopConditions(DataTable dt)
	{
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		foreach (DataRow row in dt.Rows)
		{
			if (row["ScnValue"] == null)
			{
				continue;
			}
			string scnValue = row["ScnValue"].ToString();
			Dictionary<string, string> dictionary2 = SplitLoopConditions(scnValue);
			foreach (KeyValuePair<string, string> item in dictionary2)
			{
				if (!dictionary.ContainsKey(item.Key))
				{
					if (!dt.Columns.Contains(item.Key))
					{
						dt.Columns.Add(item.Key);
						dictionary.Add(item.Key, item.Key);
					}
					else
					{
						string text = "LOOP_" + item.Key;
						dt.Columns.Add(text);
						dictionary.Add(item.Key, text);
					}
				}
				row[dictionary[item.Key]] = item.Value;
			}
		}
	}

	private static bool IsInList(List<string> collection, string stringToSearch)
	{
		return collection?.Contains(stringToSearch) ?? true;
	}

	private static bool IsInList(List<string> sourceCollection, List<string> subSetCollection)
	{
		if (sourceCollection == null)
		{
			return true;
		}
		foreach (string item in subSetCollection)
		{
			if (sourceCollection.Contains(item))
			{
				return true;
			}
		}
		return false;
	}

	public source GetQSPRSource(string qsprFilePath)
	{
		FileStream fileStream = null;
		try
		{
			fileStream = new FileStream(qsprFilePath, FileMode.Open, FileAccess.Read);
			XmlSerializer xmlSerializer = new XmlSerializer(typeof(source));
			if (!(xmlSerializer.Deserialize(fileStream) is source result))
			{
				throw new QsprConversionException("Error deserializing Qspr file", -1234);
			}
			return result;
		}
		catch (Exception ex)
		{
			throw ex;
		}
		finally
		{
			if (fileStream != null)
			{
				fileStream.Close();
				fileStream.Dispose();
			}
		}
	}

	public source GetQSPRSource(QTMFormatUnitData unitData)
	{
		source source2 = new source();
		source2.TestCollection = new ArrayList();
		TestColl testColl = new TestColl();
		AddQSPRTestsFromQTMData(testColl, unitData);
		AddQSPRConfigurationFromQTMData(testColl, unitData);
		source2.TestCollection.Add(testColl);
		return source2;
	}

	private void AddQSPRConfigurationFromQTMData(TestColl testCollection, QTMFormatUnitData unitData)
	{
		if (!string.IsNullOrEmpty(unitData.Config.StartTime) && !string.IsNullOrEmpty(unitData.Config.StopTime))
		{
			DateTime result = DateTime.MinValue;
			DateTime result2 = DateTime.MinValue;
			if (!DateTime.TryParse(unitData.Config.StartTime, out result))
			{
				result = DateTime.ParseExact(unitData.Config.StartTime, "M/d/yy HH:mm:ss:fff", stringFormatProvider);
			}
			if (!DateTime.TryParse(unitData.Config.StopTime, out result2))
			{
				result2 = DateTime.ParseExact(unitData.Config.StopTime, "M/d/yy HH:mm:ss:fff", stringFormatProvider);
			}
			TestColl.DateInfo date = default(TestColl.DateInfo);
			date.DD = result.Day;
			date.MM = result.Month;
			date.YYYY = result.Year;
			testCollection.Date = date;
			testCollection.Time = new TimeInfo();
			TimeInfo.info start = default(TimeInfo.info);
			start.HH = result.Hour;
			start.MM = result.Minute;
			start.SS = result.Second;
			testCollection.Time.Start = start;
			TimeInfo.info stop = default(TimeInfo.info);
			stop.HH = result2.Hour;
			stop.MM = result2.Minute;
			stop.SS = result2.Second;
			testCollection.Time.Stop = stop;
			TimeSpan timeSpan = result2.Subtract(result);
			TimeInfo.durationinfo duration = default(TimeInfo.durationinfo);
			duration.HH = timeSpan.Hours;
			duration.MM = timeSpan.Minutes;
			duration.SS = timeSpan.Seconds;
			duration.MS = timeSpan.Milliseconds;
			testCollection.Time.Duration = duration;
		}
		if (!string.IsNullOrEmpty(unitData.Config.TESTERID))
		{
			TestColl.TesterInfo testerInfo = new TestColl.TesterInfo();
			testerInfo.Name = unitData.Config.TESTERID;
			testCollection.Tester = testerInfo;
		}
		testCollection.UUT = new TestColl.UUTInfo();
		testCollection.UUT.ID = unitData.Config.UUT_SN;
		testCollection.UUT.SWBuildID = unitData.Config.SW_MCN;
		if (!string.IsNullOrEmpty(unitData.Config.TreeID))
		{
			TestColl.ImageInfo image = default(TestColl.ImageInfo);
			image.DI = new DIValue();
			image.DI.N = unitData.Config.TreeID;
			image.UNCFilename = (image.Filename = unitData.Config.TreeFileName);
			testCollection.Image = image;
		}
		if (!string.IsNullOrEmpty(unitData.Config.Result))
		{
			TestColl.PassFailInfo passFail = default(TestColl.PassFailInfo);
			passFail.DI = new DIValue();
			passFail.DI.N = "Status";
			if (unitData.Config.Result.ToLower() == "passed")
			{
				passFail.DI.V = "PASS";
			}
			else if (unitData.Config.Result.ToLower() == "failed")
			{
				passFail.DI.V = "FAIL";
			}
			testCollection.PassFail = passFail;
		}
	}

	private void AddQSPRTestsFromQTMData(TestColl testCollection, QTMFormatUnitData unitData)
	{
		testCollection.Test = new ArrayList();
		Dictionary<string, string> hashLoopRefID = new Dictionary<string, string>();
		ResetNewDataSetId();
		foreach (Test test in unitData.Tests)
		{
			ArrayList arrayList = new ArrayList();
			testCollection.Test.Add(GenerateQSPRTestFromQTMTest(test, arrayList, hashLoopRefID));
			foreach (Tests item in arrayList)
			{
				testCollection.Test.Add(item);
			}
		}
	}

	private Tests GenerateQSPRTestFromQTMTest(Test qtmTest, ArrayList newlyCreatedQSPRTests, Dictionary<string, string> hashLoopRefID)
	{
		Tests tests = new Tests();
		tests.DataSetCollection = new ArrayList();
		tests.ExtendedName = qtmTest.TestName;
		tests.Name = qtmTest.TestName;
		DataSetColl dataSetColl = new DataSetColl();
		dataSetColl.DataSet = new ArrayList();
		DataSets dataSets = new DataSets();
		PopulateQSPRDataSetFromQTMTest(dataSets, qtmTest, newlyCreatedQSPRTests, hashLoopRefID);
		dataSetColl.DataSet.Add(dataSets);
		tests.DataSetCollection.Add(dataSetColl);
		tests.PassFail = new Input();
		tests.PassFail.DI = new ArrayList();
		DIValue dIValue = new DIValue();
		dIValue.N = "Status";
		if (qtmTest.TestResult.ToLower() == "failed")
		{
			dIValue.V = "FAIL";
		}
		else if (qtmTest.TestResult.ToLower() == "passed")
		{
			dIValue.V = "PASS";
		}
		tests.PassFail.DI.Add(dIValue);
		return tests;
	}

	private void PopulateQSPRDataSetFromQTMTest(DataSets qsprDataSet, Test qtmTest, ArrayList newlyCreatedQSPRTests, Dictionary<string, string> hashLoopRefID)
	{
		qsprDataSet.id = GenerateNewDataSetId();
		AddQTMLoopConditionsToQSPRDataSet(qsprDataSet, qtmTest.LoopConditions, hashLoopRefID);
		if (qsprDataSet.Outputs == null)
		{
			qsprDataSet.Outputs = new Output();
		}
		AddQTMParametersToQSPRDataSet(qtmTest, qsprDataSet, qsprDataSet.Outputs, qtmTest.ParamResults, newlyCreatedQSPRTests);
		qsprDataSet.ts = qtmTest.TestDuration.TotalSeconds.ToString();
	}

	private void AddQTMParametersToQSPRDataSet(Test qtmTest, DataSets qsprDataSet, Output qsprDataSetOutput, ArrayList qtmTestOutputParameters, ArrayList newlyCreatedQSPRTests)
	{
		if (qtmTestOutputParameters == null)
		{
			return;
		}
		if (qsprDataSetOutput == null)
		{
			qsprDataSetOutput = new Output();
		}
		qsprDataSetOutput.Result = new ArrayList();
		foreach (ParamResult qtmTestOutputParameter in qtmTestOutputParameters)
		{
			if (qtmTestOutputParameter.Array == null)
			{
				Results results = new Results();
				results.DI = new DIValue();
				results.DI.N = qtmTestOutputParameter.Name;
				Results.Limit limit = new Results.Limit();
				if (!string.IsNullOrEmpty(qtmTestOutputParameter.UpperLimit))
				{
					limit.Max = qtmTestOutputParameter.UpperLimit;
				}
				if (!string.IsNullOrEmpty(qtmTestOutputParameter.LowerLimit))
				{
					limit.Min = qtmTestOutputParameter.LowerLimit;
				}
				results.Limits = limit;
				if (qtmTestOutputParameter.Value.HasValue)
				{
					results.DI.V = qtmTestOutputParameter.Value.ToString();
				}
				else
				{
					results.DI.V = qtmTestOutputParameter.CHAR_Value;
				}
				results.DI.U = qtmTestOutputParameter.UnitOfMeasure;
				qsprDataSetOutput.Result.Add(results);
				continue;
			}
			foreach (ArrayResult item in qtmTestOutputParameter.Array)
			{
				newlyCreatedQSPRTests.Add(AddQTMArrayParam(item, qsprDataSet, qtmTest));
			}
		}
	}

	private Tests AddQTMArrayParam(ArrayResult array, DataSets qsprDataSetParent, Test qtmTest)
	{
		Tests tests = new Tests();
		tests.DataSetCollection = new ArrayList();
		tests.ExtendedName = qtmTest.TestName;
		tests.Name = qtmTest.TestName;
		DataSetColl dataSetColl = new DataSetColl();
		dataSetColl.DataSet = new ArrayList();
		DataSets dataSets = new DataSets();
		dataSets.DSRef = new ArrayList();
		DSRefInfo dSRefInfo = new DSRefInfo();
		dSRefInfo.id = qsprDataSetParent.id;
		dataSets.DSRef.Add(dSRefInfo);
		dataSets.Inputs = new Input();
		DIValue dIValue = new DIValue();
		dIValue.N = "aIndex";
		dIValue.V = array.RowIndex;
		dataSets.Inputs.DI = new ArrayList();
		dataSets.Inputs.DI.Add(dIValue);
		Results results = new Results();
		results.DI = new DIValue();
		results.DI.N = array.Name;
		Results.Limit limit = new Results.Limit();
		limit.Max = array.UpperLimit;
		limit.Min = array.LowerLimit;
		results.Limits = limit;
		if (array.Value.HasValue)
		{
			results.DI.V = array.Value.ToString();
		}
		else
		{
			results.DI.V = array.CHAR_Value;
		}
		dataSets.Outputs = new Output();
		dataSets.Outputs.Result = new ArrayList();
		dataSets.Outputs.Result.Add(results);
		dataSetColl.DataSet.Add(dataSets);
		tests.DataSetCollection.Add(dataSetColl);
		tests.PassFail = new Input();
		tests.PassFail.DI = new ArrayList();
		DIValue dIValue2 = new DIValue();
		dIValue2.N = "Status";
		if (qtmTest.TestResult.ToLower() == "failed")
		{
			dIValue2.V = "FAIL";
		}
		else if (qtmTest.TestResult.ToLower() == "passed")
		{
			dIValue2.V = "PASS";
		}
		tests.PassFail.DI.Add(dIValue2);
		return tests;
	}

	private void AddQTMLoopConditionsToQSPRDataSet(DataSets qsprDataSet, ArrayList qtmLoopConditions, Dictionary<string, string> hashLoopRefID)
	{
		if (qtmLoopConditions == null)
		{
			return;
		}
		string text = "";
		string id = "";
		int num = -1;
		int num2 = 1;
		foreach (LoopCondition qtmLoopCondition in qtmLoopConditions)
		{
			if (!string.IsNullOrWhiteSpace(qtmLoopCondition.Key) && !string.IsNullOrWhiteSpace(qtmLoopCondition.Value))
			{
				text = text + " " + qtmLoopCondition.Key + "__" + qtmLoopCondition.Value;
				if (hashLoopRefID.ContainsKey(text))
				{
					id = hashLoopRefID[text];
					num = num2;
				}
			}
			num2++;
		}
		if (num >= 0)
		{
			qtmLoopConditions.RemoveRange(0, num);
			qsprDataSet.DSRef = new ArrayList();
			DSRefInfo dSRefInfo = new DSRefInfo();
			dSRefInfo.id = id;
			qsprDataSet.DSRef.Add(dSRefInfo);
		}
		if (qtmLoopConditions.Count <= 0)
		{
			return;
		}
		if (qsprDataSet.Inputs == null)
		{
			qsprDataSet.Inputs = new Input();
		}
		Input inputs = qsprDataSet.Inputs;
		inputs.DI = new ArrayList();
		foreach (LoopCondition qtmLoopCondition2 in qtmLoopConditions)
		{
			DIValue dIValue = new DIValue();
			if (!string.IsNullOrWhiteSpace(qtmLoopCondition2.Key))
			{
				dIValue.N = qtmLoopCondition2.Key;
			}
			if (!string.IsNullOrWhiteSpace(qtmLoopCondition2.Value))
			{
				dIValue.V = qtmLoopCondition2.Value;
			}
			inputs.DI.Add(dIValue);
		}
		hashLoopRefID.Add(text, qsprDataSet.id);
	}

	private string GenerateNewDataSetId()
	{
		return Convert.ToString(++dataSetId);
	}

	private void ResetNewDataSetId()
	{
		dataSetId = 0;
	}

	private string GetQtmTestResult(string qsprTestResult)
	{
		if (qsprTestResult.ToLower() == "pass")
		{
			return "Passed";
		}
		return "Failed";
	}

	private void ClearOutputFilePaths()
	{
		currentQsprToCsvFilePath = string.Empty;
		currentQsprToQtmXmlFilePath = string.Empty;
	}

	private void AddTestRowCollection(DataTable dt, List<DataRow> testRowCollection)
	{
		foreach (DataRow item in testRowCollection)
		{
			dt.Rows.Add(item);
		}
	}

	private Dictionary<string, string> SplitLoopConditions(string scnValue)
	{
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		string[] separator = new string[1] { "__" };
		string[] separator2 = new string[2] { "_ _", "_._" };
		if (!string.IsNullOrEmpty(scnValue))
		{
			string[] array = scnValue.Split(separator2, StringSplitOptions.None);
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(separator, StringSplitOptions.None);
				if (array2.Length == 2 && !dictionary.ContainsKey(array2[0]))
				{
					dictionary.Add(array2[0], array2[1]);
				}
			}
		}
		return dictionary;
	}

	private string GetGlobalResult(TestColl testCollection)
	{
		string text = testCollection.PassFail.DI.V.ToLower();
		if (text == "pass")
		{
			return "Passed";
		}
		return "Failed";
	}

	private List<string> CreateConfigurationLoopCollection(List<string> selectedParametersCollection = null)
	{
		if (selectedParametersCollection != null && selectedParametersCollection.Count > 0)
		{
			return selectedParametersCollection;
		}
		string text = LoopConditions;
		string[] array = text.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
		List<string> list = new List<string>();
		string[] array2 = array;
		foreach (string text2 in array2)
		{
			if (!list.Contains(text2.Trim()))
			{
				list.Add(text2.Trim());
			}
		}
		return list;
	}

	private void GetUnitStartAndStopDateTime(TestColl testCollection, out DateTime startDateTime, out DateTime stopDateTime)
	{
		TimeInfo.info start = testCollection.Time.Start;
		_ = testCollection.Time.Stop;
		TimeInfo.durationinfo duration = testCollection.Time.Duration;
		TestColl.DateInfo date = testCollection.Date;
		startDateTime = new DateTime(date.YYYY, date.MM, date.DD, start.HH, start.MM, start.SS);
		if (testCollection.StopDate.DD != 0 && testCollection.StopDate.MM != 0 && testCollection.StopDate.YYYY != 0)
		{
			TestColl.DateInfo stopDate = testCollection.StopDate;
			stopDateTime = startDateTime.Add(new TimeSpan(new DateTime(stopDate.YYYY, stopDate.MM, stopDate.DD).Subtract(startDateTime).Days, duration.HH, duration.MM, duration.SS, duration.MS));
		}
		else
		{
			stopDateTime = startDateTime.Add(new TimeSpan(0, duration.HH, duration.MM, duration.SS, duration.MS));
		}
	}

	private string GetSerialNumber(TestColl testCollection)
	{
		string empty = string.Empty;
		if (!string.IsNullOrEmpty(testCollection.UUT.ID))
		{
			return testCollection.UUT.ID;
		}
		return "NA";
	}

	public TestColl GetValidQSPRTestCollection(source qsprDataSource)
	{
		TestColl testColl = null;
		foreach (TestColl item in qsprDataSource.TestCollection)
		{
			if (item.UUT != null)
			{
				testColl = item;
				break;
			}
		}
		if (testColl == null)
		{
			throw new QsprConversionException("Error finding valid TestCollection", -9005);
		}
		return testColl;
	}

	public static bool IsQsprFile(string filePath)
	{
		using StreamReader streamReader = new StreamReader(filePath);
		try
		{
			char[] array = new char[1024];
			streamReader.ReadBlock(array, 0, 1024);
			string text = new string(array);
			if (text.ToLower().Contains("<TestCollection>".ToLower()))
			{
				return true;
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public void Dispose()
	{
	}

	public source GetSuiteConfig(string qsprFilePath, out string serialNumber, out DateTime startDate, out DateTime endDate)
	{
		source qSPRSource = GetQSPRSource(qsprFilePath);
		TestColl validQSPRTestCollection = GetValidQSPRTestCollection(qSPRSource);
		serialNumber = GetSerialNumber(validQSPRTestCollection);
		GetUnitStartAndStopDateTime(validQSPRTestCollection, out startDate, out endDate);
		return qSPRSource;
	}
}
