Using NIPO

NIPO can be used within other applications since it is a library.
The central class is NIPO.Controller.NIPOController. You can use this class to search suitable plugins in your filesystem. By adding plugins to the NIPOController you build a NIPO instance.
The following example shows how the controller is used to build a new NIPO instance:
MyInputPlugin input=new MyInputPlugin();
MyProcessingPlugin processing=new MyProcessingPlugin();
MyFileOutputPlugin fileout=new MyFileOutputPlugin();
MyVisualizationPlugin visualization=new MyVisualizationPlugin();
/*
...configure plugins*/

NIPOController.Instance.AddInputPlugin(input);
NIPOController.Instance.AddProcessingPlugin(processing);
NIPOController.Instance.AddOutputPlugin(fileout);
NIPOController.Instance.AddOutputPlugin(visualization);
NIPOController.Instance.Start();
Basically at least one input and one output plugins are needed to run a NIPO instance. The plain NIPOController supports one single processing plugin. But this does not mean that you can use only one. NIPO additionally defines two special processing plugins. The NIPO.Plugin.Extension.PluginChain can be used to chain up multiple processing plugins. The NIPO.Plugin.Extension.BranchMergePlugin is used to build parallel plugins (or chains of plugins). A subclass of it can be used to decide for each data packet, which plugin is responsible. See the documentation of those plugins for details.
The following example shows how to search for plugins. It also uses the PluginChainPlugin.

NIPOController controller = NIPOController.Instance;
 /* A processing chain can be used to chain up multiple processing plugins */
NIPO.Plugins.Extension.ProcessingChainPlugin chain = new NIPO.Plugins.Extension.ProcessingChainPlugin();
 /* Search for all plugins in the subfolder "Plugins" */
List<FileInfo> assemblies = NIPOController.SearchAssemblies(new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "Plugins")),true);
foreach (FileInfo info in assemblies)
{
    List<Type> inputTypes = NIPOController.SearchPlugIns(info.FullName, NIPO.Plugins.PlugInType.Input);
    foreach (Type type in inputTypes)
    {
        Console.WriteLine(type.FullName);
        InputPlugin input=(InputPlugin)type.Assembly.CreateInstance(type.FullName);
     /*
     Configure Plugins
     */
        controller.AddInputPlugIn(input);
    }
    List<Type> outputTypes = NIPOController.SearchPlugIns(info.FullName, NIPO.Plugins.PlugInType.Output);
    foreach (Type type in outputTypes)
    {
        Console.WriteLine(type.FullName);
     /*
     Configure Plugins
     */
        OutputPlugin outputPlugin = (OutputPlugin)type.Assembly.CreateInstance(type.FullName);
       controller.AddOutputPlugin(outputPlugin);
    }

    List<Type> processingTypes = NIPOController.SearchPlugIns(info.FullName, NIPO.Plugins.PlugInType.Processing);
    foreach (Type type in processingTypes)
    {
        Console.WriteLine(type.FullName);
     /*
     Configure Plugins
     */
        chain.AddPlugin((ProcessingPlugin)type.Assembly.CreateInstance(type.FullName));
    }

}
controller.AddProcessingPlugin(chain);
controller.Start();

Plugins may need to be configured in order to work properly. A NIPO Plugins defines the ConfigurationObject where a plugin can store this data. An application using NIPO may use this to let the user configure the plugin (an easy way is to use the Windows Forms PropertyGrid).

Last edited Mar 24, 2010 at 10:45 AM by bedieber, version 6

Comments

No comments yet.