I am working on a windows service to process a batch of records. In this I have a set of processors to process my records based on a set of conditions. So I have a Engine class which looks something like this :
public interface IProcessor
{
ICollection<OutputEntity> Process(ICollection<InputEntity>> entities);
string SomeField{get;set;}
}
public class Engine
{
public Engine(IEnumerable<IProcessor> processors)
{
//asign the processors to local variable
}
public void ProcessRecords(IService service)
{
// getRecords code etc.
foreach(var processor in processors)
{
processor.Process(typeRecords.Where(typeRecord => typeRecord.SomeField == processor.SomeField));
}
}
}
This is based on another question I has posted a while back here. Now my requirement is that I have some more conditions coming into play based on things like Current Day , some attributes on a set of entities etc. And on every condition I need to use a combination of processors in a certain sequence. For instance :
if (( DateTime.Now.Date.DayOfWeek == DayOfWeek.Monday) && (inputEntityInstance.Property1 == "X" ))
{
Processor1.Process(inputEntityInstance);
Processor2.Process(inputEntityInstance);
Processor3.Process(inputEntityInstance):
}
if (( IsLastDayOfMonth() && (inputEntityInstance.Property2 == "Y" ))
{
Processor1.Process(inputEntityInstance);
Processor4.Process(inputEntityInstance);
Processor6.Process(inputEntityInstance):
}
\
However the situation I have now is that I have around 10 types of processors. For any give condition , about 3 or 4 are applicable.
Whats the best way to implement this .. I was looking at implementing some kind of a rule engine ..
The idea is that if tomorrow a new condition /rule is to be implemented I could define it somewhere along with the set of processors and the sequence required ... is this advisable ?
Thanks a lot.