Hello,
Let me describe the problem and the solution i currently have and maybe you can help enlighten me on why it's a bad idea (assuming it is) and what i can do to make it a better system.
right now i have 600 "rippers" that parse files and rip them to csv or other formats. the rippers all implement a common interface and base class. At the moment when a job is queued up depending on the configuration of that job a specific ripper is called using reflection.
foreach (var stream in streams)
{
try
{
// load it
Assembly asm = Assembly.LoadFile(Path.Combine(stream.RipperPath, stream.RipperFileName), new Evidence());
if (asm == null)
{
MessageBox.Show(String.Format("Invalid Interface ripper loaded.\n{0}", Path.Combine(stream.RipperPath, stream.RipperFileName)));
return;
}
foreach (Type objType in asm.GetTypes())
{
if (!objType.IsPublic)
continue;
// make sure the type isn't Abstract
if (((objType.Attributes & TypeAttributes.Abstract) == TypeAttributes.Abstract))
continue;
// IRipper is the interface that all of the Rippers must implement to be loaded
Type objInterface = objType.GetInterface("IRipper", true);
if (objInterface == null)
continue;
try
{
var iri = (IRipper)Activator.CreateInstance(objType);
// Rippers must register with their hosts
iri.Host = this;
iri.OnStart += RipperStart;
iri.OnComplete += RipperComplete;
iri.OnProgressChanged += RipperStatusUpdate;
iri.dataStream = stream;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
catch (Exception ex)
{
MessageBox.Show(String.Format("Error loading interface: {0}\n{1}", Path.Combine(stream.RipperPath, stream.RipperFileName), ex.Message));
}
}
all rippers have implement a function called "Rip()" which the interface contracts them to.
using the current code the only problem i can see is that after loading 600 assemblies (since they're loaded when they are needed) it's going to start getting a little slow if they are not unloaded after they have been used.
What would you suggest?