Multiple Code Processors
Option #1: The Controller handles a collection of ICodeProcessorWorker
Interfaces
The main idea is to segregate the ICodeProcessor interface into ICodeProcessorProduct and ICodeProcessorWorker.
ICodeProcessorProduct
Handles requirements and basic preprocessing of whole product:
ICodeProcessorProduct
{
Name
NeedsLicense
ValidateParameters
GetCodeDescriptor (with FoundExtensions set)
// Execution Mode: Parallel, Sequencial, Special Order?
}
ICodeProcessorWorker
Handles a working agent and execution:
ICodeProcessorWorker
{
Name
SupportedExtensions (with EntryPointExtensions)
ProgressDescriptor
Logger
Execute
}
ICodeProcessor
It´s an interface that combines both ICodeProcessorProduct and ICodeProcessorWorker:
ICodeProcessor : ICodeProcessorProduct, ICodeProcessorWorker
{
}
It´s important to note that this would not break the previously supported contract for the other teams.
Two methods of initialization would be possible:
Passing an ICodeProcessor.
Passing an ICodeProcesorProduct and a collection of ICodeProcessorWorker.
The first method would reuse the second, as it would be possible to split the ICodeProcessor reference into two (one for ICodeProcessorProduct and another to ICodeProcessorWorker).
Pseudocode for deciding when to run each worker
codeDescriptor = main.GetCodeDescriptor();
foreach worker in Workers
{
if (worker.SupportedExtensions.Where(e => e.IsEntryPointExtension).Any(e => codeDescriptor.FoundExtensions.Contains(e)))
{
worker.Execute();
}
}

Work items
Option #2: The Controller handles a single composite code processor
Pros:
The Controller would remain mostly unaffected.
Cons :
We might need to introduce a complex mechanism for assigning CodeModelWriters, Loggers, etc that the composite code processor would need to respect.
CodeProcessor
{
public CodeModelWritingAgent[] CodeModelWritingAgents;
public Execute(CodeModelWriter[] codeModelWriters)
{
ValidateAndAssignCodeModelWriters(codeModelWriters);
}
}
Controller
{
CodeModelWriter[] GetCodeModelWriters()
{
List<CodeModelWriter> CodeModelWriters = new List<CodeModelWriter>();
foreach (CodeModelWritingAgent agent in codeProcessor.CodeModelWritingAgents)
{
CodeModelWriters.Add(AssessmentModelWriter.CreateCodeModelWriter(agent.Name, agent.Version, agent.Technology));
}
return CodeModelWriters.ToArray();
}
Execute()
{
...
CodeModelWriter[] codeModelWriters = GetCodeModelWriters();
codeProcessor.Execute(codeModelWriters);
...
}
}
Last updated