in sqlnexus/fmMain.cs [1260:1352]
private bool EnumAnalyzers()
{
bool bRes=true;
lvAnalyzers.Items.Clear();
ArrayList Analyzers = new ArrayList();
if (File.Exists("manifest.xml"))
{
XmlDocument manifestDoc = new XmlDocument();
manifestDoc.Load("manifest.xml");
foreach (XmlNode node in manifestDoc["Manifest"]["Analyzers"].ChildNodes)
{
if (null==FindName(Analyzers,node.Attributes["name"].Value))
Analyzers.Add(node);
}
}
if (null!=m_ConfigDoc)
{
foreach (XmlNode node in m_ConfigDoc["dsConfig"]["Analysis"]["Analyzers"].ChildNodes)
{
if (null==FindName(Analyzers,node.Attributes["name"].Value))
Analyzers.Add(node);
}
}
string[] Files=Directory.GetFiles(Application.StartupPath,"*.DLL");
foreach (string file in Files)
{
if (null==FindAssembly(Analyzers,file))
Analyzers.Add(file);
}
foreach (object obj in Analyzers)
{
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.IAnalyzer");
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);
IAnalyzer anl = (IAnalyzer)assem.CreateInstance(typ.FullName,true);
if (obj is XmlNode)
{
anl.Name=(obj as XmlNode).Attributes["name"].Value;
}
//Ignore anonymous analyzers
if (0==anl.Name.Length)
continue;
if (!AddAnalyzer(typ,anl,file,selected))
bRes=false;
}
}
}
return bRes;
}