private bool EnumProducers()

in sqlnexus/fmMain.cs [1138:1229]


		private bool EnumProducers()
		{
			bool bRes=true;
			lvProducers.Items.Clear();

			ArrayList Producers = new ArrayList();

			if (File.Exists("manifest.xml")) 
			{
				XmlDocument manifestDoc = new XmlDocument();
				manifestDoc.Load("manifest.xml");
				foreach (XmlNode node in manifestDoc["Manifest"]["Producers"].ChildNodes)
				{
					if (null==FindName(Producers,node.Attributes["name"].Value))
						Producers.Add(node);				
				}
			}

			if (null!=m_ConfigDoc) 
			{
				foreach (XmlNode node in m_ConfigDoc["dsConfig"]["Analysis"]["Producers"].ChildNodes)
				{
					if (null==FindName(Producers,node.Attributes["name"].Value))
						Producers.Add(node);				
				}
			}

			string[] Files=Directory.GetFiles(Application.StartupPath,"*.DLL");
			foreach (string file in Files) 
			{
				if (null==FindAssembly(Producers,file))
					Producers.Add(file);				
			}


			foreach (object obj in Producers) 
			{
				string file;
				bool selected;
				if (obj is XmlNode) 
				{
					file=Application.StartupPath+"\\"+(obj as XmlNode).Attributes["assembly"].Value;
					selected=Convert.ToBoolean((obj as XmlNode).Attributes["selected"].Value);
				}
				else // assume string
				{
					file=(obj as string);
					selected=false;
				}
				Assembly Assem;
				try
				{
					Assem = Assembly.LoadFile(file);
				}
				catch (Exception ex)
				{
					Debug.WriteLine(ex.Message);
					continue;
				}
				Type[] typs=Assem.GetExportedTypes();
				foreach (Type typ in typs) 
				{
					//Ignore abstract classes
					if (typ.IsAbstract)
						continue;

					TypeFilter loadIfcFilt = new TypeFilter(loadIfcFilter);
					Type[] ifcs = typ.FindInterfaces(loadIfcFilt,"SQLAnalyzerInterfaces.IProducer");
					foreach (Type ifc in ifcs) 
					{

						//If we get in here, the Class implements the interface, so add it to the list
						//and bail
						Assembly assem = Assembly.LoadFile(file);
						IProducer prod = (IProducer)assem.CreateInstance(typ.FullName,true); 

						if (obj is XmlNode)
						{
							prod.Name=(obj as XmlNode).Attributes["name"].Value;
						}

						//Ignore anonymous producers
						if (0==prod.Name.Length) 
							continue;

						if (!AddProducer(typ, prod, file, selected))
							bRes=false;
					}
				}
			}
			return bRes;
		}