using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Xml.Serialization;
using ProductConfigurationController.Properties;

namespace ProductConfigurationController;

public class ProductConfigManager
{
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public struct ProductConfigDefaultValues
	{
		public const string PRODUCT = "8x26";

		public const string STATION_CONFIG = "SWDL";

		public const string CONFIGURATION = "Software Download";

		public const int TEST_TREE_TIMEOUT = 500;

		public const int TEST_TREE_TIMEOUT_OFFSET = 10;

		public const string TEST_TREE_PATH = "C:\\Qualcomm\\QMSCT\\sample\\DotNetSample.xtt";
	}

	private Dictionary<string, List<string>> SupportedTechnologies = new Dictionary<string, List<string>>();

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

	public WarningCallcack WarningDialog;

	private ProductSetup productSetup;

	private ProductSetup productSetupBackup;

	private string filename;

	private int configurationIndex = -1;

	private int productIndex = -1;

	private FileStream fs;

	public EventHandler OnLoad;

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

	public EventHandler OnChangeSelectedProduct;

	public EventHandler OnChangeSelectedConfiguration;

	public EventHandler OnChangeEngine;

	public EventHandler OnChangeStationConfigName;

	public EventHandler OnChangeTestTreePath;

	public EventHandler OnChangeTestTreeTimeoutSeconds;

	private int testTreeTimeoutSeconds = 500;

	public EventHandler OnChangeTestTreeTimeoutSecondsOffset;

	private int testTreeTimeoutSecondsOffset = 10;

	public EventHandler OnChangeTechnologySpecificGV;

	public EventHandler OnChangeCustomConfiguration;

	public EventHandler OnChangeTechnology;

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

	public EventHandler OnChangeProductList;

	public EventHandler OnChangeConfigurationList;

	public string Filename => filename;

	public List<string> ProductList
	{
		get
		{
			products.Clear();
			ProductType[] product = productSetup.Product;
			foreach (ProductType productType in product)
			{
				products.Add(productType.ProductName);
			}
			return products;
		}
	}

	public List<string> EngineList => SupportedEngines;

	public List<string> TechnologySupportedEngineList
	{
		get
		{
			List<string> list = new List<string>();
			if (Technology != null && SupportedTechnologies.ContainsKey(Technology))
			{
				foreach (string item in SupportedTechnologies[Technology])
				{
					if (SupportedEngines.Contains(item))
					{
						list.Add(item);
					}
				}
			}
			return list;
		}
	}

	public string SelectedProduct
	{
		get
		{
			if (productIndex < 0)
			{
				return null;
			}
			return productSetup.Product[productIndex].ProductName;
		}
		set
		{
			string selectedConfiguration = SelectedConfiguration;
			SelectProduct(value);
			if (selectedConfiguration != null)
			{
				SelectConfiguration(selectedConfiguration);
			}
		}
	}

	public string SelectedConfiguration
	{
		get
		{
			if (productIndex < 0 || configurationIndex < 0)
			{
				return null;
			}
			return productSetup.Product[productIndex].Configuration[configurationIndex].Name;
		}
		set
		{
			SelectConfiguration(value);
		}
	}

	public string Engine
	{
		get
		{
			if (productIndex < 0 || configurationIndex < 0)
			{
				return null;
			}
			return productSetup.Product[productIndex].Configuration[configurationIndex].Engine.EngineName;
		}
		set
		{
			if (productIndex >= 0 || configurationIndex >= 0)
			{
				productSetup.Product[productIndex].Configuration[configurationIndex].Engine.EngineName = value;
				VerifyEngine();
			}
			if (OnChangeEngine != null)
			{
				OnChangeEngine(this, null);
			}
		}
	}

	public string StationConfigName
	{
		get
		{
			if (productIndex < 0 || configurationIndex < 0)
			{
				return null;
			}
			return productSetup.Product[productIndex].Configuration[configurationIndex].StationConfigName;
		}
		set
		{
			if (productIndex >= 0 || configurationIndex >= 0)
			{
				productSetup.Product[productIndex].Configuration[configurationIndex].StationConfigName = value;
			}
			if (OnChangeStationConfigName != null)
			{
				OnChangeStationConfigName(this, null);
			}
		}
	}

	public string TestPlanFilePath
	{
		get
		{
			if (productIndex < 0 || configurationIndex < 0)
			{
				return null;
			}
			return productSetup.Product[productIndex].Configuration[configurationIndex].Engine.TestPlanFilePath;
		}
		set
		{
			if (productIndex >= 0 || configurationIndex >= 0)
			{
				if (productIndex < 0 || configurationIndex < 0)
				{
					return;
				}
				productSetup.Product[productIndex].Configuration[configurationIndex].Engine.TestPlanFilePath = value;
				VerifyTestTree();
			}
			if (OnChangeTestTreePath != null)
			{
				OnChangeTestTreePath(this, null);
			}
		}
	}

	public int TestTimeoutSeconds
	{
		get
		{
			try
			{
				if (productIndex < 0 || configurationIndex < 0)
				{
					return -1;
				}
				testTreeTimeoutSeconds = productSetup.Product[productIndex].Configuration[configurationIndex].Engine.TestTimeoutSeconds;
			}
			catch
			{
				Warning("Invalid Test Tree Timout value " + productSetup.Product[productIndex].Configuration[configurationIndex].Engine.TestTimeoutSeconds);
				testTreeTimeoutSeconds = 500;
			}
			return testTreeTimeoutSeconds;
		}
		set
		{
			if ((productIndex >= 0 || configurationIndex >= 0) && value > 0)
			{
				testTreeTimeoutSeconds = value;
				productSetup.Product[productIndex].Configuration[configurationIndex].Engine.TestTimeoutSeconds = value;
				VerifyTestTimeout();
			}
			if (OnChangeTestTreeTimeoutSeconds != null)
			{
				OnChangeTestTreeTimeoutSeconds(this, null);
			}
		}
	}

	public int TestTimeoutSecondsOffset
	{
		get
		{
			try
			{
				if (productIndex < 0 || configurationIndex < 0)
				{
					return -1;
				}
				testTreeTimeoutSecondsOffset = productSetup.Product[productIndex].Configuration[configurationIndex].Engine.TestTimeoutSecondsOffset;
			}
			catch
			{
				Warning("Invalid Test Tree Timout Offset value " + productSetup.Product[productIndex].Configuration[configurationIndex].Engine.TestTimeoutSecondsOffset);
				testTreeTimeoutSecondsOffset = 10;
			}
			return testTreeTimeoutSecondsOffset;
		}
		set
		{
			if (productIndex >= 0 || configurationIndex >= 0)
			{
				testTreeTimeoutSecondsOffset = value;
				productSetup.Product[productIndex].Configuration[configurationIndex].Engine.TestTimeoutSecondsOffset = value;
			}
			if (OnChangeTestTreeTimeoutSecondsOffset != null)
			{
				OnChangeTestTreeTimeoutSecondsOffset(this, null);
			}
		}
	}

	public Dictionary<string, string> TechnologySpecificGV
	{
		get
		{
			if (productIndex < 0 || configurationIndex < 0)
			{
				return null;
			}
			return productSetup.Product[productIndex].Configuration[configurationIndex].TechnologySpecificGV.ToDictionary((GVType p) => p.Name, (GVType p) => p.Value);
		}
		set
		{
			if (productIndex >= 0 || configurationIndex >= 0)
			{
				List<GVType> list = new List<GVType>();
				foreach (string key in value.Keys)
				{
					GVType gVType = new GVType();
					gVType.Name = key;
					gVType.Value = value[key];
					list.Add(gVType);
				}
				productSetup.Product[productIndex].Configuration[configurationIndex].TechnologySpecificGV = list.ToArray();
			}
			if (OnChangeTechnologySpecificGV != null)
			{
				OnChangeTechnologySpecificGV(this, null);
			}
		}
	}

	public string CustomConfiguration
	{
		get
		{
			if (productIndex < 0 || configurationIndex < 0)
			{
				return null;
			}
			return productSetup.Product[productIndex].Configuration[configurationIndex].CustomConfigurationString;
		}
		set
		{
			if (productIndex >= 0 || configurationIndex >= 0)
			{
				productSetup.Product[productIndex].Configuration[configurationIndex].CustomConfigurationString = value;
			}
			if (OnChangeCustomConfiguration != null)
			{
				OnChangeCustomConfiguration(this, null);
			}
		}
	}

	public string Technology
	{
		get
		{
			if (productIndex < 0 || configurationIndex < 0)
			{
				return null;
			}
			return productSetup.Product[productIndex].Configuration[configurationIndex].Technology;
		}
		set
		{
			if (productIndex >= 0 || configurationIndex >= 0)
			{
				productSetup.Product[productIndex].Configuration[configurationIndex].Technology = value;
				VerifyTechnology();
			}
			if (OnChangeTechnology != null)
			{
				OnChangeTechnology(this, null);
			}
		}
	}

	public List<string> ConfigurationList
	{
		get
		{
			if (productIndex < 0)
			{
				return null;
			}
			configurations.Clear();
			ConfigurationType[] configuration = productSetup.Product[productIndex].Configuration;
			foreach (ConfigurationType configurationType in configuration)
			{
				configurations.Add(configurationType.Name);
			}
			return configurations;
		}
	}

	public List<string> TechnologyList => SupportedTechnologies.Keys.ToList();

	private GVType[] Copy(GVType[] gvt)
	{
		List<GVType> list = new List<GVType>();
		foreach (GVType gVType in gvt)
		{
			GVType gVType2 = new GVType();
			gVType2.Name = gVType.Name;
			gVType2.Value = gVType.Value;
			list.Add(gVType2);
		}
		return list.ToArray();
	}

	private ConfigurationType Copy(ConfigurationType ct)
	{
		ConfigurationType configurationType = new ConfigurationType();
		configurationType.Name = ct.Name;
		configurationType.Engine = new EngineType();
		configurationType.StationConfigName = ct.StationConfigName;
		configurationType.Technology = ct.Technology;
		configurationType.TechnologySpecificGV = Copy(ct.TechnologySpecificGV);
		configurationType.Engine.EngineName = ct.Engine.EngineName;
		configurationType.Engine.TestPlanFilePath = ct.Engine.TestPlanFilePath;
		configurationType.Engine.TestTimeoutSeconds = ct.Engine.TestTimeoutSeconds;
		configurationType.Engine.TestTimeoutSecondsOffset = ct.Engine.TestTimeoutSecondsOffset;
		return configurationType;
	}

	private ProductType Copy(ProductType pt)
	{
		ProductType productType = new ProductType();
		productType.ProductName = pt.ProductName;
		List<ConfigurationType> list = new List<ConfigurationType>();
		ConfigurationType[] configuration = pt.Configuration;
		foreach (ConfigurationType ct in configuration)
		{
			list.Add(Copy(ct));
		}
		productType.Configuration = list.ToArray();
		return productType;
	}

	private ProductSetup Copy(ProductSetup ps)
	{
		ProductSetup productSetup = new ProductSetup();
		List<ProductType> list = new List<ProductType>();
		ProductType[] product = ps.Product;
		foreach (ProductType pt in product)
		{
			list.Add(Copy(pt));
		}
		productSetup.Product = list.ToArray();
		return productSetup;
	}

	private bool Compare(GVType gvt, GVType gvtcmp)
	{
		if (gvtcmp.Name != gvt.Name || gvtcmp.Value != gvt.Value)
		{
			return false;
		}
		return true;
	}

	private bool Compare(ConfigurationType ct, ConfigurationType ctcmp)
	{
		if (ctcmp.Name != ct.Name || ctcmp.StationConfigName != ct.StationConfigName || ctcmp.Technology != ct.Technology || ctcmp.Engine.EngineName != ct.Engine.EngineName || ctcmp.Engine.TestPlanFilePath != ct.Engine.TestPlanFilePath || ctcmp.Engine.TestTimeoutSeconds != ct.Engine.TestTimeoutSeconds || ctcmp.Engine.TestTimeoutSecondsOffset != ct.Engine.TestTimeoutSecondsOffset || ctcmp.TechnologySpecificGV.Count() != ct.TechnologySpecificGV.Count())
		{
			return false;
		}
		for (int i = 0; i < ctcmp.TechnologySpecificGV.Count(); i++)
		{
			if (!Compare(ctcmp.TechnologySpecificGV[i], ct.TechnologySpecificGV[i]))
			{
				return false;
			}
		}
		return true;
	}

	private bool Compare(ProductType pt, ProductType ptcmp)
	{
		if (ptcmp.ProductName != pt.ProductName || ptcmp.Configuration.Count() != pt.Configuration.Count())
		{
			return false;
		}
		for (int i = 0; i < ptcmp.Configuration.Count(); i++)
		{
			if (!Compare(ptcmp.Configuration[i], pt.Configuration[i]))
			{
				return false;
			}
		}
		return true;
	}

	private void Warning(string message)
	{
		if (WarningDialog != null)
		{
			WarningDialog(message, "Warning");
		}
	}

	public void SetFileName(string filename)
	{
		this.filename = filename;
	}

	public void AddSupportedEngine(string enginename)
	{
		SupportedEngines.Add(enginename);
	}

	public void AddSupportedTechnology(KeyValuePair<string, List<string>> technology)
	{
		SupportedTechnologies.Add(technology.Key, technology.Value);
	}

	private ProductType CreateDefaultProduct()
	{
		ProductType productType = new ProductType();
		productType.ProductName = "8x26";
		List<ConfigurationType> list = new List<ConfigurationType>();
		list.Add(CreateDefaultConfiguration());
		ConfigurationType configurationType = CreateDefaultConfiguration();
		configurationType.Name = "MultiDUT RF";
		configurationType.Technology = "MULTIDUT_RF";
		List<GVType> list2 = new List<GVType>();
		GVType gVType = new GVType();
		gVType.Name = "MULTIPLEX_MANAGER_CONFIG_FILE";
		if (Environment.Is64BitOperatingSystem)
		{
			gVType.Value = "C:\\Program Files (x86)\\Qualcomm\\QDART\\Databases\\MultiplexManagerConfigFile.xml";
		}
		else
		{
			gVType.Value = "C:\\Program Files\\Qualcomm\\QDART\\Databases\\MultiplexManagerConfigFile.xml";
		}
		list2.Add(gVType);
		configurationType.TechnologySpecificGV = list2.ToArray();
		list.Add(configurationType);
		ConfigurationType configurationType2 = CreateDefaultConfiguration();
		configurationType2.Name = "Station CAL";
		configurationType2.Technology = "MULTIDUT_RF";
		if (Environment.Is64BitOperatingSystem)
		{
			configurationType2.Engine.TestPlanFilePath = "C:\\Program Files (x86)\\Qualcomm\\QDART\\XTT\\SubSysStationCalibration\\QDART_AllTech__RF_FTM_CalVer__StnCal1.0.xtt";
		}
		else
		{
			configurationType2.Engine.TestPlanFilePath = "C:\\Program Files\\Qualcomm\\QDART\\XTT\\SubSysStationCalibration\\QDART_AllTech__RF_FTM_CalVer__StnCal1.0.xtt";
		}
		List<GVType> list3 = new List<GVType>();
		GVType gVType2 = new GVType();
		gVType2.Name = "MULTIPLEX_MANAGER_CONFIG_FILE";
		if (Environment.Is64BitOperatingSystem)
		{
			gVType2.Value = "C:\\Program Files (x86)\\Qualcomm\\QDART\\Databases\\MultiplexManagerConfigFile.xml";
		}
		else
		{
			gVType2.Value = "C:\\Program Files\\Qualcomm\\QDART\\Databases\\MultiplexManagerConfigFile.xml";
		}
		list3.Add(gVType2);
		GVType gVType3 = new GVType();
		gVType3.Name = "CREATE_GOLD_UNIT";
		gVType3.Value = "0";
		list3.Add(gVType3);
		configurationType2.TechnologySpecificGV = list3.ToArray();
		list.Add(configurationType2);
		ConfigurationType configurationType3 = CreateDefaultConfiguration();
		configurationType3.Name = "MMI";
		configurationType3.Technology = "MULTIDUT_MMI";
		list.Add(configurationType3);
		productType.Configuration = list.ToArray();
		return productType;
	}

	private ConfigurationType CreateDefaultConfiguration()
	{
		ConfigurationType configurationType = new ConfigurationType();
		configurationType.Name = "Software Download";
		configurationType.StationConfigName = "SWDL";
		configurationType.Engine = new EngineType();
		configurationType.Engine.EngineName = SupportedEngines[0];
		configurationType.Engine.TestPlanFilePath = "C:\\Qualcomm\\QMSCT\\sample\\DotNetSample.xtt";
		configurationType.Engine.TestTimeoutSeconds = 500;
		configurationType.Engine.TestTimeoutSecondsOffset = 10;
		configurationType.Technology = SupportedTechnologies.Keys.First();
		configurationType.TechnologySpecificGV = new List<GVType>().ToArray();
		configurationType.CustomConfigurationString = "";
		return configurationType;
	}

	public void CreateDefaultProductSetupXml()
	{
		try
		{
			XmlSerializer xmlSerializer = new XmlSerializer(typeof(ProductSetup));
			productSetup = new ProductSetup();
			List<ProductType> list = new List<ProductType>();
			list.Add(CreateDefaultProduct());
			productSetup.Product = list.ToArray();
			string directoryName = Path.GetDirectoryName(Filename);
			if (!Directory.Exists(directoryName))
			{
				Directory.CreateDirectory(directoryName);
			}
			StreamWriter streamWriter = new StreamWriter(File.Create(filename));
			xmlSerializer.Serialize(streamWriter, productSetup);
			streamWriter.Close();
		}
		catch (Exception ex)
		{
			throw ex;
		}
	}

	private void VerifyProductList()
	{
		if (productSetup.Product == null || productSetup.Product.Count() == 0)
		{
			List<ProductType> list = new List<ProductType>();
			Warning("No product found, will create a default one");
			list.Add(CreateDefaultProduct());
			productSetup.Product = list.ToArray();
		}
		if (OnChangeProductList != null)
		{
			OnChangeProductList(this, null);
		}
	}

	private void SelectProduct(string productName)
	{
		for (int i = 0; i < productSetup.Product.Count(); i++)
		{
			if (productSetup.Product[i].ProductName == productName)
			{
				productIndex = i;
				VerifyConfigurationList();
				if (OnChangeSelectedProduct != null)
				{
					OnChangeSelectedProduct(this, null);
				}
				return;
			}
		}
		Warning("Product not found, will select the first product");
		productIndex = 0;
		VerifyConfigurationList();
		if (OnChangeSelectedProduct != null)
		{
			OnChangeSelectedProduct(this, null);
		}
	}

	private void VerifyConfigurationList()
	{
		if (productSetup.Product[productIndex].Configuration == null || productSetup.Product[productIndex].Configuration.Count() == 0)
		{
			List<ConfigurationType> list = new List<ConfigurationType>();
			Warning("No configuration found, will create a default one");
			list.Add(CreateDefaultConfiguration());
			productSetup.Product[productIndex].Configuration = list.ToArray();
		}
		if (OnChangeConfigurationList != null)
		{
			OnChangeConfigurationList(this, null);
		}
	}

	private void SelectConfiguration(string configurationName)
	{
		for (int i = 0; i < productSetup.Product[productIndex].Configuration.Count(); i++)
		{
			if (productSetup.Product[productIndex].Configuration[i].Name == configurationName)
			{
				configurationIndex = i;
				VerifyConfiguration();
				if (OnChangeSelectedConfiguration != null)
				{
					OnChangeSelectedConfiguration(this, null);
				}
				return;
			}
		}
		Warning("Configuration not found, will select the first configuration");
		configurationIndex = 0;
		VerifyConfiguration();
		if (OnChangeSelectedConfiguration != null)
		{
			OnChangeSelectedConfiguration(this, null);
		}
	}

	private void VerifyConfiguration()
	{
		try
		{
			VerifyEngine();
			VerifyTechnology();
			VerifyTestTree();
			VerifyTestTimeout();
		}
		catch (Exception ex)
		{
			throw new Exception(string.Format(CommonResource.ErrMsgLoadConfigFileFailed, SelectedConfiguration, ex.Source, ex.Message));
		}
	}

	private void VerifyTestTree()
	{
		string text = TestPlanFilePath;
		if (text.StartsWith("\"") && text.EndsWith("\""))
		{
			text = text.Substring(1, text.Length - 2);
		}
		if (!File.Exists(text))
		{
			if (!File.Exists("C:\\Qualcomm\\QMSCT\\sample\\DotNetSample.xtt"))
			{
				throw new Exception(CommonResource.BoxMsgTreeNotFound + " C:\\Qualcomm\\QMSCT\\sample\\DotNetSample.xtt");
			}
			Warning(CommonResource.BoxMsgTreeNotFound + " " + TestPlanFilePath + "\n" + CommonResource.BoxMsgTreeChanged + "\nC:\\Qualcomm\\QMSCT\\sample\\DotNetSample.xtt");
			TestPlanFilePath = "C:\\Qualcomm\\QMSCT\\sample\\DotNetSample.xtt";
			text = TestPlanFilePath;
			if (text.StartsWith("\"") && text.EndsWith("\""))
			{
				text = text.Substring(1, text.Length - 2);
			}
		}
		productSetup.Product[productIndex].Configuration[configurationIndex].Engine.TestPlanFilePath = text;
	}

	private void VerifyTestTimeout()
	{
		if (TestTimeoutSeconds < 1 || TestTimeoutSecondsOffset < 0)
		{
			Warning(CommonResource.BoxMsgInvalidTimeout);
			TestTimeoutSeconds = 500;
		}
	}

	private void VerifyEngine()
	{
		if (!SupportedEngines.Contains(productSetup.Product[productIndex].Configuration[configurationIndex].Engine.EngineName))
		{
			Warning("Selected engine is not supportted, will change to " + SupportedEngines[0]);
			productSetup.Product[productIndex].Configuration[configurationIndex].Engine.EngineName = SupportedEngines[0];
		}
	}

	private void VerifyTechnology()
	{
		if (!SupportedTechnologies.ContainsKey(productSetup.Product[productIndex].Configuration[configurationIndex].Technology))
		{
			Warning("Selected technology is not supportted, will change to " + SupportedTechnologies.Keys.First());
			productSetup.Product[productIndex].Configuration[configurationIndex].Technology = SupportedTechnologies.Keys.First();
		}
	}

	public void Load()
	{
		if (!File.Exists(Filename))
		{
			throw new Exception(Filename + " not exists!!");
		}
		fs = new FileStream(Filename, FileMode.Open, FileAccess.Read, FileShare.Read);
		try
		{
			XmlSerializer xmlSerializer = new XmlSerializer(typeof(ProductSetup));
			productSetup = (ProductSetup)xmlSerializer.Deserialize(fs);
			productSetupBackup = Copy(productSetup);
			VerifyProductList();
			if (OnLoad != null)
			{
				OnLoad(this, null);
			}
		}
		catch (Exception ex)
		{
			throw new Exception("Unable to read product configuration file. " + filename + " Exception: " + ex.Message);
		}
		finally
		{
			fs.Close();
		}
	}

	public void Save()
	{
		FileStream fileStream = new FileStream(Filename, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
		try
		{
			XmlSerializer xmlSerializer = new XmlSerializer(typeof(ProductSetup));
			xmlSerializer.Serialize(fileStream, productSetup);
			productSetupBackup = Copy(productSetup);
		}
		catch (Exception ex)
		{
			throw new Exception("Unable to save product configuration file. " + filename + "Exception: " + ex.Message);
		}
		finally
		{
			fileStream.Close();
		}
	}

	public bool IsChanged()
	{
		if (productSetup.Product.Count() != productSetupBackup.Product.Count())
		{
			return true;
		}
		for (int i = 0; i < productSetup.Product.Count(); i++)
		{
			if (!Compare(productSetupBackup.Product[i], productSetup.Product[i]))
			{
				return true;
			}
		}
		return false;
	}

	public void DiscardChanges()
	{
		productSetup = Copy(productSetupBackup);
		productIndex = -1;
		configurationIndex = -1;
		if (OnLoad != null)
		{
			OnLoad(this, null);
		}
	}

	public void CreateNewFromSelectedProduct(string name)
	{
		if (ProductList.Contains(name, StringComparer.OrdinalIgnoreCase))
		{
			throw new Exception("Product already exists");
		}
		ProductType productType = Copy(productSetup.Product[productIndex]);
		productType.ProductName = name;
		List<ProductType> list = productSetup.Product.ToList();
		list.Add(productType);
		productSetup.Product = list.ToArray();
		if (OnChangeProductList != null)
		{
			OnChangeProductList(this, null);
		}
	}

	public void CreateNewFromSelectedConfiguration(string name)
	{
		if (ConfigurationList.Contains(name, StringComparer.OrdinalIgnoreCase))
		{
			throw new Exception("Configuration already exists");
		}
		ConfigurationType configurationType = Copy(productSetup.Product[productIndex].Configuration[configurationIndex]);
		configurationType.Name = name;
		List<ConfigurationType> list = productSetup.Product[productIndex].Configuration.ToList();
		list.Add(configurationType);
		productSetup.Product[productIndex].Configuration = list.ToArray();
		if (OnChangeConfigurationList != null)
		{
			OnChangeConfigurationList(this, null);
		}
	}
}
