using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using System.Xml.Schema;
using System.Xml.Serialization;
using QC.CTDS.DM.SharedLibrary;

namespace QC.CTDS.DM.DataStructures.FormatDescriptorStructure;

[Serializable]
[XmlRoot(Namespace = "", IsNullable = false)]
[XmlType(AnonymousType = true)]
public class FormatDescriptor : BindableObject
{
	private int version;

	private int currentVersion = 1;

	private ObservableCollection<OutputGroupSetDescriptor> outputGroupSet = new ObservableCollection<OutputGroupSetDescriptor>();

	private bool isExpanded = true;

	private bool pptMode;

	private bool groupCharts;

	private ObservableCollection<PPTGroup> pptGroupsList = new ObservableCollection<PPTGroup>();

	private ObservableCollection<GlobalParameter> globalParameterList = new ObservableCollection<GlobalParameter>();

	private bool isSelected = true;

	private ExcelProperties globalExcelDisplayProperties = new ExcelProperties();

	private string filePath;

	[XmlAttribute]
	[DefaultValue(0)]
	public int Version
	{
		get
		{
			return version;
		}
		set
		{
			version = value;
		}
	}

	[XmlIgnore]
	public int CurrentVersion
	{
		get
		{
			return currentVersion;
		}
		set
		{
			currentVersion = value;
		}
	}

	[XmlElement("OutputGroupSet", Form = XmlSchemaForm.Unqualified)]
	public ObservableCollection<OutputGroupSetDescriptor> OutputGroupSet
	{
		get
		{
			return outputGroupSet;
		}
		set
		{
			if (outputGroupSet != value)
			{
				outputGroupSet = value;
				OnPropertyChanged("OutputGroupSet");
			}
		}
	}

	[XmlIgnore]
	public bool IsExpanded
	{
		get
		{
			return isExpanded;
		}
		set
		{
			if (isExpanded != value)
			{
				isExpanded = value;
				OnPropertyChanged("IsExpanded");
			}
		}
	}

	[XmlIgnore]
	public bool PPTMode
	{
		get
		{
			return pptMode;
		}
		set
		{
			if (pptMode == value)
			{
				return;
			}
			pptMode = value;
			OnPropertyChanged("PPTMode");
			if (OutputGroupSet != null)
			{
				OutputGroupSet.ForEach(delegate(OutputGroupSetDescriptor outputGroupSet)
				{
					outputGroupSet.PPTMode = value;
				});
			}
		}
	}

	public bool GroupCharts
	{
		get
		{
			return groupCharts;
		}
		set
		{
			if (groupCharts != value)
			{
				groupCharts = value;
				OnPropertyChanged("GroupCharts");
			}
		}
	}

	public ObservableCollection<PPTGroup> PPTGroupsList
	{
		get
		{
			return pptGroupsList;
		}
		set
		{
			if (pptGroupsList != value)
			{
				pptGroupsList = value;
				OnPropertyChanged("PPTGroupsList");
			}
		}
	}

	public ObservableCollection<GlobalParameter> GlobalParameterList
	{
		get
		{
			return globalParameterList;
		}
		set
		{
			if (globalParameterList != value)
			{
				globalParameterList = value;
				OnPropertyChanged("GlobalParameterList");
			}
		}
	}

	[XmlIgnore]
	public bool IsSelected
	{
		get
		{
			return isSelected;
		}
		set
		{
			if (isSelected != value)
			{
				isSelected = value;
				OnPropertyChanged("IsSelected");
			}
		}
	}

	public ExcelProperties GlobalExcelDisplayProperties
	{
		get
		{
			return globalExcelDisplayProperties;
		}
		set
		{
			if (globalExcelDisplayProperties != value)
			{
				globalExcelDisplayProperties = value;
				globalExcelDisplayProperties.Parent = this;
				OnPropertyChanged("GlobalExcelDisplayProperties");
			}
		}
	}

	[XmlIgnore]
	public bool IsNewFile { get; set; }

	[XmlIgnore]
	public string FilePath
	{
		get
		{
			return filePath;
		}
		set
		{
			if (!(filePath == value))
			{
				filePath = value;
				OnPropertyChanged("FilePath");
			}
		}
	}

	[XmlIgnore]
	public string FileName => Path.GetFileName(FilePath);

	private void PPTGroupsList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
	{
		OnPropertyChanged("PPTGroupsList");
	}

	private void GlobalParameterList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
	{
		OnPropertyChanged("GlobalParameterList");
	}

	public FormatDescriptor()
	{
		OutputGroupSet.CollectionChanged += EstablishParentChildRelationOnCollectionChanged;
		OutputGroupSet.CollectionChanged += OutputGroupSet_CollectionChanged;
		PPTGroupsList.CollectionChanged += EstablishParentChildRelationOnCollectionChanged;
		PPTGroupsList.CollectionChanged += PPTGroupsList_CollectionChanged;
		GlobalParameterList.CollectionChanged += EstablishParentChildRelationOnCollectionChanged;
		GlobalParameterList.CollectionChanged += GlobalParameterList_CollectionChanged;
		GlobalExcelDisplayProperties.Parent = this;
	}

	public override void Changed(string changedFieldName)
	{
		switch (changedFieldName)
		{
		case "PPTMode":
			return;
		case "IsSelected":
			return;
		}
		base.Changed(changedFieldName);
	}

	public FormatDescriptor(string filePath)
		: this()
	{
		FilePath = filePath;
	}

	private void OutputGroupSet_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
	{
		OnPropertyChanged("OutputGroupSet");
	}

	public static FormatDescriptor ReadFormatDescriptor(string filePath)
	{
		FormatDescriptor formatDescriptor = null;
		formatDescriptor = CommonFunctions.Deserialize<FormatDescriptor>(filePath);
		if (formatDescriptor != null)
		{
			formatDescriptor.FilePath = filePath;
			formatDescriptor.EstablishParentChildRelationship();
			return formatDescriptor;
		}
		throw new Exception($"Error finding format descriptor file: {filePath}. Please make sure that the path is accesible");
	}

	public static FormatDescriptor ReadFormatDescriptorFromString(string formatDescriptorContent)
	{
		FormatDescriptor formatDescriptor = null;
		formatDescriptor = CommonFunctions.DeserializeString<FormatDescriptor>(formatDescriptorContent);
		if (formatDescriptor != null)
		{
			formatDescriptor.FilePath = "";
			formatDescriptor.EstablishParentChildRelationship();
			return formatDescriptor;
		}
		throw new Exception($"Error deserializing format descriptor content:");
	}

	public static void WriteFromatDescriptor(FormatDescriptor fd, string filePath)
	{
		fd.Version = fd.CurrentVersion;
		CommonFunctions.Serialize(filePath, fd);
		fd.FilePath = filePath;
		fd.ResetChange();
	}

	public static FormatDescriptor CreateSelectedDescriptorsFormatDescriptor(FormatDescriptor orignalFormatDescriptor)
	{
		FormatDescriptor formatDescriptor = (FormatDescriptor)ObjectCopier.GetCopy(orignalFormatDescriptor);
		formatDescriptor.RemoveNotSelectedDescriptors();
		formatDescriptor.Version = formatDescriptor.CurrentVersion;
		return formatDescriptor;
	}

	public void RemoveNotSelectedDescriptors()
	{
		if (OutputGroupSet != null)
		{
			OutputGroupSet.RemoveAll((OutputGroupSetDescriptor outputGroupSet) => outputGroupSet.IsChecked == false);
			OutputGroupSet.ForEach(delegate(OutputGroupSetDescriptor outputGroupSet)
			{
				outputGroupSet.RemoveUnselectedDescriptors();
			});
		}
	}

	public void SetSelectedStateOfAllOutputGroupSets(bool? newState)
	{
		if (OutputGroupSet != null)
		{
			OutputGroupSet.ForEach(delegate(OutputGroupSetDescriptor outputGroupSet)
			{
				outputGroupSet.IsChecked = newState;
			});
		}
	}

	public void SetSelectedPPTStateOfAllOutputGroupSets(bool? newState)
	{
		if (OutputGroupSet != null)
		{
			OutputGroupSet.ForEach(delegate(OutputGroupSetDescriptor outputGroupSet)
			{
				outputGroupSet.IsForPPTChecked = newState;
			});
		}
	}

	public static void WriteToTemporaryFile(FormatDescriptor fd, string filePath)
	{
		CommonFunctions.Serialize(filePath, fd);
	}

	public void AddNewSheet(int sheetPosition)
	{
		if (OutputGroupSet != null)
		{
			OutputGroupSetDescriptor outputGroupSetDescriptor = new OutputGroupSetDescriptor();
			outputGroupSetDescriptor.Name = "Temp" + OutputGroupSet.Count;
			OutputGroupSetDescriptor outputGroupSetDescriptor2 = outputGroupSetDescriptor;
			if (sheetPosition == -1)
			{
				OutputGroupSet.Add(outputGroupSetDescriptor2);
			}
			else
			{
				OutputGroupSet.Insert(sheetPosition + 1, outputGroupSetDescriptor2);
			}
			outputGroupSetDescriptor2.IsSelected = true;
			IsExpanded = true;
		}
	}

	public void ExpandAll()
	{
		IsExpanded = true;
		if (OutputGroupSet != null)
		{
			OutputGroupSet.ForEach(delegate(OutputGroupSetDescriptor outputGroupSet)
			{
				outputGroupSet.IsExpanded = true;
			});
		}
	}

	public void CollapseAll()
	{
		IsExpanded = false;
		if (OutputGroupSet != null)
		{
			OutputGroupSet.ForEach(delegate(OutputGroupSetDescriptor outputGroupSet)
			{
				outputGroupSet.IsExpanded = false;
			});
		}
	}

	public void RemoveSelectedSheetsAndCharts()
	{
		if (OutputGroupSet != null)
		{
			OutputGroupSet.RemoveAll((OutputGroupSetDescriptor outputGroupSet) => outputGroupSet.IsChecked == true);
			OutputGroupSet.ForEach(delegate(OutputGroupSetDescriptor outputGroupSet)
			{
				outputGroupSet.RemoveSelectedCharts();
			});
			SetSelectedStateOfAllOutputGroupSets(false);
		}
	}

	public static FormatDescriptor CreateCurrentItemFormatDescriptor(string currentFilePath, DiscriminatorElement discriminatorElement, FormatDescriptor orignalFormatDescriptor)
	{
		FormatDescriptor formatDescriptor = new FormatDescriptor(currentFilePath);
		if (discriminatorElement is OutputGroupSetDescriptor)
		{
			formatDescriptor.OutputGroupSet.Add((OutputGroupSetDescriptor)ObjectCopier.GetCopy(discriminatorElement));
			formatDescriptor.RemoveNotSelectedDescriptors();
		}
		else if (discriminatorElement is CondensedSummary)
		{
			CondensedSummary condensedSummary = (CondensedSummary)discriminatorElement;
			OutputGroupSetDescriptor outputGroupSetDescriptor = (OutputGroupSetDescriptor)ObjectCopier.GetCopy(condensedSummary.Parent);
			outputGroupSetDescriptor.RemoveAllCharts();
			outputGroupSetDescriptor.GroupSetDescCollection.Add((CondensedSummary)ObjectCopier.GetCopy(condensedSummary));
			formatDescriptor.OutputGroupSet.Add(outputGroupSetDescriptor);
		}
		else if (discriminatorElement is WideCondensedSummary)
		{
			WideCondensedSummary wideCondensedSummary = (WideCondensedSummary)discriminatorElement;
			OutputGroupSetDescriptor outputGroupSetDescriptor2 = (OutputGroupSetDescriptor)ObjectCopier.GetCopy(wideCondensedSummary.Parent);
			outputGroupSetDescriptor2.RemoveAllCharts();
			outputGroupSetDescriptor2.GroupSetDescCollection.Add((WideCondensedSummary)ObjectCopier.GetCopy(wideCondensedSummary));
			formatDescriptor.OutputGroupSet.Add(outputGroupSetDescriptor2);
		}
		else if (discriminatorElement is MultiDimensionOutputGroupDescriptor)
		{
			MultiDimensionOutputGroupDescriptor multiDimensionOutputGroupDescriptor = (MultiDimensionOutputGroupDescriptor)discriminatorElement;
			OutputGroupSetDescriptor outputGroupSetDescriptor3 = (OutputGroupSetDescriptor)ObjectCopier.GetCopy(multiDimensionOutputGroupDescriptor.Parent);
			outputGroupSetDescriptor3.RemoveAllCharts();
			outputGroupSetDescriptor3.GroupSetDescCollection.Add((MultiDimensionOutputGroupDescriptor)ObjectCopier.GetCopy(multiDimensionOutputGroupDescriptor));
			formatDescriptor.OutputGroupSet.Add(outputGroupSetDescriptor3);
		}
		else if (discriminatorElement is LineOutputGroupDescriptor)
		{
			LineOutputGroupDescriptor lineOutputGroupDescriptor = (LineOutputGroupDescriptor)discriminatorElement;
			OutputGroupSetDescriptor outputGroupSetDescriptor4 = (OutputGroupSetDescriptor)ObjectCopier.GetCopy(lineOutputGroupDescriptor.Parent);
			outputGroupSetDescriptor4.RemoveAllCharts();
			outputGroupSetDescriptor4.GroupSetDescCollection.Add((LineOutputGroupDescriptor)ObjectCopier.GetCopy(lineOutputGroupDescriptor));
			formatDescriptor.OutputGroupSet.Add(outputGroupSetDescriptor4);
		}
		else if (discriminatorElement is HistogramOutputGroupDescriptor)
		{
			HistogramOutputGroupDescriptor histogramOutputGroupDescriptor = (HistogramOutputGroupDescriptor)discriminatorElement;
			OutputGroupSetDescriptor outputGroupSetDescriptor5 = (OutputGroupSetDescriptor)ObjectCopier.GetCopy(histogramOutputGroupDescriptor.Parent);
			outputGroupSetDescriptor5.RemoveAllCharts();
			outputGroupSetDescriptor5.GroupSetDescCollection.Add((HistogramOutputGroupDescriptor)ObjectCopier.GetCopy(histogramOutputGroupDescriptor));
			formatDescriptor.OutputGroupSet.Add(outputGroupSetDescriptor5);
		}
		else if (discriminatorElement is ScatterOutputGroupDescriptor)
		{
			ScatterOutputGroupDescriptor scatterOutputGroupDescriptor = (ScatterOutputGroupDescriptor)discriminatorElement;
			OutputGroupSetDescriptor outputGroupSetDescriptor6 = (OutputGroupSetDescriptor)ObjectCopier.GetCopy(scatterOutputGroupDescriptor.Parent);
			outputGroupSetDescriptor6.RemoveAllCharts();
			outputGroupSetDescriptor6.GroupSetDescCollection.Add((ScatterOutputGroupDescriptor)ObjectCopier.GetCopy(scatterOutputGroupDescriptor));
			formatDescriptor.OutputGroupSet.Add(outputGroupSetDescriptor6);
		}
		formatDescriptor.Version = formatDescriptor.CurrentVersion;
		formatDescriptor.GlobalParameterList = orignalFormatDescriptor.GlobalParameterList;
		formatDescriptor.GlobalExcelDisplayProperties = orignalFormatDescriptor.GlobalExcelDisplayProperties;
		return formatDescriptor;
	}

	public static bool IsFormatDescriptorFile(string sourceFile)
	{
		return CommonFunctions.HasText(sourceFile, "<FormatDescriptor");
	}

	public void GetTestAndParamNames(out List<string> testNames, out List<string> paramNames, bool includeInputParams = true)
	{
		testNames = new List<string>();
		paramNames = new List<string>();
		XDocument xDocument = null;
		if (!string.IsNullOrEmpty(FilePath))
		{
			xDocument = XDocument.Load(filePath);
		}
		else
		{
			string text = CommonFunctions.SerializeToString(this);
			xDocument = XDocument.Parse(text);
		}
		testNames.AddRange((from attr in (from elem in xDocument.Descendants("OutputGroupSet")
				where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
				select elem).Descendants("Result").Attributes("testID")
			select attr.Value).Distinct());
		testNames.AddRange((from attr in (from elem in xDocument.Descendants("OutputGroupSet")
				where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
				select elem).Descendants("Series").Attributes("testID")
			select attr.Value).Distinct());
		testNames.AddRange((from attr in (from elem in xDocument.Descendants("OutputGroupSet")
				where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
				select elem).Descendants("MultiDimensionResultSet").Attributes("testID")
			select attr.Value).Distinct());
		testNames.AddRange(from elem in xDocument.Descendants("TestName")
			select elem.Value);
		testNames.AddRange((from attr in (from elem in xDocument.Descendants("OutputGroupSet")
				where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
				select elem).Descendants("StatsResult").Attributes("testID")
			select attr.Value).Distinct());
		paramNames.AddRange((from attr in (from elem in xDocument.Descendants("OutputGroupSet")
				where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
				select elem).Descendants("Result").Attributes("resID")
			select attr.Value).Distinct());
		paramNames.AddRange((from attr in (from elem in xDocument.Descendants("OutputGroupSet")
				where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
				select elem).Descendants("DepVar").Attributes("id")
			select attr.Value).Distinct());
		paramNames.AddRange((from attr in (from elem in xDocument.Descendants("OutputGroupSet")
				where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
				select elem).Descendants("IndVar").Attributes("id")
			select attr.Value).Distinct());
		paramNames.AddRange((from attr in (from elem in xDocument.Descendants("OutputGroupSet")
				where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
				select elem).Descendants("XAxis").Attributes("id")
			select attr.Value).Distinct());
		if (includeInputParams)
		{
			paramNames.AddRange((from attr in (from elem in xDocument.Descendants("OutputGroupSet")
					where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
					select elem).Descendants("Discriminator").Attributes("id")
				select attr.Value).Distinct());
			paramNames.AddRange((from attr in (from elem in xDocument.Descendants("OutputGroupSet")
					where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
					select elem).Descendants("Filter").Attributes("id")
				select attr.Value).Distinct());
			paramNames.AddRange((from idxParam in (from elem in xDocument.Descendants("OutputGroupSet")
					where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
					select elem).Descendants("IndexedParam").Attributes("id")
				select idxParam.Value).Distinct());
		}
		paramNames.AddRange((from attr in (from elem in xDocument.Descendants("OutputGroupSet")
				where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
				select elem).Descendants("MultiDimensionResultSet").Attributes("resID")
			select attr.Value).Distinct());
		paramNames.AddRange((from attr in (from elem in xDocument.Descendants("OutputGroupSet")
				where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
				select elem).Descendants("ZAxis").Attributes("id")
			select attr.Value).Distinct());
		paramNames.AddRange((from idxParam in (from elem in xDocument.Descendants("OutputGroupSet")
				where (elem.Attribute("IsChecked") != null && (elem.Attribute("IsChecked").Value.ToLower() == "true" || elem.Attribute("IsChecked").Value.ToLower() == "indeterminate")) || elem.Attribute("IsChecked") == null
				select elem).Descendants("StatsResult").Attributes("resID")
			select idxParam.Value).Distinct());
		paramNames.AddRange(from elem in xDocument.Descendants("ParameterName")
			select elem.Value);
		testNames = testNames.Select((string tName) => tName.Trim()).Distinct().ToList();
		paramNames = paramNames.Select((string pName) => pName.Trim()).Distinct().ToList();
	}

	public string GetFormatDescriptorString()
	{
		return CommonFunctions.SerializeToString(this);
	}

	public void ApplyFileGrouping(FileSystemItemsGroupingCollection groupingCollection)
	{
		if (groupingCollection == null || groupingCollection.FileSystemItemsGroupList.Count <= 0)
		{
			return;
		}
		IEnumerable<string> groupNames = from fileGrp in groupingCollection.FileSystemItemsGroupList
			where !string.IsNullOrEmpty(fileGrp.GroupName)
			select fileGrp.GroupName;
		if (groupNames == null || groupNames.Count() <= 0)
		{
			return;
		}
		OutputGroupSet.ForEach(delegate(OutputGroupSetDescriptor grpSet)
		{
			grpSet.ApplyFileGrouping(groupNames);
		});
		ObservableCollection<GlobalParameter> observableCollection = new ObservableCollection<GlobalParameter>();
		foreach (GlobalParameter item in GlobalParameterList.Where((GlobalParameter gParam) => !string.IsNullOrEmpty(gParam.TestName) && !string.IsNullOrEmpty(gParam.ParameterName)))
		{
			foreach (string item2 in groupNames)
			{
				GlobalParameter globalParameter = new GlobalParameter();
				globalParameter.TestName = item.TestName + "_" + item2;
				globalParameter.ParameterName = item.ParameterName;
				observableCollection.Add(globalParameter);
			}
		}
		GlobalParameterList = observableCollection;
	}

	public void RemoveFileGrouping(IEnumerable<string> groupNameCollection)
	{
		if (groupNameCollection == null || groupNameCollection.Count() <= 0)
		{
			return;
		}
		OutputGroupSet.ForEach(delegate(OutputGroupSetDescriptor grpSet)
		{
			grpSet.RemoveFileGrouping(groupNameCollection);
		});
		ObservableCollection<GlobalParameter> observableCollection = new ObservableCollection<GlobalParameter>();
		HashSet<string> hashSet = new HashSet<string>();
		foreach (GlobalParameter item in GlobalParameterList.Where((GlobalParameter gParam) => !string.IsNullOrEmpty(gParam.TestName) && !string.IsNullOrEmpty(gParam.ParameterName)))
		{
			foreach (string item2 in groupNameCollection)
			{
				if (item.TestName.EndsWith("_" + item2))
				{
					string text = item.TestName.Replace("_" + item2, "");
					if (!hashSet.Contains(text + item.ParameterName))
					{
						hashSet.Add(text + item.ParameterName);
						item.TestName = text;
						observableCollection.Add(item);
					}
				}
			}
		}
		GlobalParameterList = observableCollection;
	}

	public void ApplyDataGrouping(List<Tuple<string, List<string>>> dataGroupingCollection)
	{
		if (dataGroupingCollection == null || dataGroupingCollection.Count <= 0)
		{
			return;
		}
		IEnumerable<string> groupNames = from dataGrp in dataGroupingCollection
			where !string.IsNullOrEmpty(dataGrp.Item1)
			select dataGrp.Item1;
		if (groupNames == null || groupNames.Count() <= 0)
		{
			return;
		}
		OutputGroupSet.ForEach(delegate(OutputGroupSetDescriptor grpSet)
		{
			grpSet.ApplyFileGrouping(groupNames);
		});
		ObservableCollection<GlobalParameter> observableCollection = new ObservableCollection<GlobalParameter>();
		foreach (GlobalParameter item in GlobalParameterList.Where((GlobalParameter gParam) => !string.IsNullOrEmpty(gParam.TestName) && !string.IsNullOrEmpty(gParam.ParameterName)))
		{
			foreach (string item2 in groupNames)
			{
				GlobalParameter globalParameter = new GlobalParameter();
				globalParameter.TestName = item.TestName + "_" + item2;
				globalParameter.ParameterName = item.ParameterName;
				observableCollection.Add(globalParameter);
			}
		}
		GlobalParameterList = observableCollection;
	}

	public void ApplyPrefixGrouping(ReportSettings reportSettingsInfo)
	{
		for (int i = 0; i < OutputGroupSet.Count; i++)
		{
			if (reportSettingsInfo.SheetDiscriminator != null)
			{
				OutputGroupSet[i].PrefixDiscriminator(reportSettingsInfo.SheetDiscriminator);
			}
			if (reportSettingsInfo.ChartDiscriminator != null || reportSettingsInfo.GroupDiscriminator != null)
			{
				OutputGroupSet[i].ApplyChartPrefixGrouping(reportSettingsInfo);
			}
		}
	}
}
