0

I'm developing a simple application which should be able in process different tasks using a plug-in architecture, so each plug-in is a DLL library file and contains a class which implements a provided interface as follows.

public interface ITaskProcessor
{
    void Execute(FileStream input, FileStream output);
}

I suppose that the Execute method of a certain plug-in will be invoked only if the input file exists, so I created the following class in my plug-in architecture.

public class TaskProcessorContext
{
    private ITaskProcessor TaskProcessorInstance;

    // ...

    void Execute(string inputDataFilename, string outputDataFilename)
    {
        using (FileStream input = File.OpenRead(inputDataFilename), output = new FileStream(outputDataFilename, FileMode.Create))
        {
            this.TaskProcessorInstance.Execute(input, output);
        }
    }
}

The overall functioning of my application should provide that a BasicHttpBinding web service receives the file containing a task and the unique name of the plug-in that should process the task:

  • the received file is temporarily stored in a specific directory, then the web service should notify the completion of the writing of the file, so that the task can be queued for execution;
  • an identifier is associated to the task, so it will be possible to know its processing state, for example using a Dictionary;
  • when the task is completed or if it is encoured an error during the processing, these events should be notified to the web service.

How could manage this communication between the WCF service and the thread that processes the task?

enzom83
  • 8,080
  • 10
  • 68
  • 114
  • 1
    You will need some additional elements for the interface to report status and errors. These can be in the form of events or fields/properties that a queried by the calling thread. – Kami Feb 10 '15 at 15:56
  • @Kami: I could add some events to both the `ITaskProcessor` interface and the `TaskProcessorContext` class, for example the events `OnTaskStarted`, `OnTaskException`, `OnTaskFinished`. – enzom83 Feb 10 '15 at 16:01
  • These events would be on the interface, with the calling thread handling when raised. It does require that the plugins implement some additional functionality by raise relevant events. Are you not able to do so? – Kami Feb 10 '15 at 16:12
  • @Kami: Yes, I am able to do so. The other doubt concerned the forwarding of an event raised from an instance of `ITaskProcessor` to an instance of `TaskProcessorContext`: for this second doubt, I found an answer in [this question](http://stackoverflow.com/questions/1065355/forwarding-events-in-c-sharp). – enzom83 Feb 10 '15 at 16:53

0 Answers0