private void buttonSelectPlugins_Click(object sender, EventArgs e)
        {
            var inputPlugin  = inputPlugins.Single(p => p.Configure().PluginDisplayName == listBoxAvailableInputPlugins.SelectedItem.ToString());
            var effectPlugin = effectPlugins.Single(p => p.Configure().PluginDisplayName == listBoxAvailableEffectPlugins.SelectedItem.ToString());
            var outputPlugin = outputPlugins.Single(p => p.Configure().PluginDisplayName == listBoxAvailableOutputPlugins.SelectedItem.ToString());

            var effectPluginContext = PluginContextFactory.GenerateInitialEffectPluginContext(effectPlugin);

            effectPluginContext.SetInput("Frequency (Hz)", 1);
            effectPluginContext.SetInput("RGB Value - R", 255);
            effectPluginContext.SetInput("RGB Value - G", 255);
            effectPluginContext.SetInput("RGB Value - B", 255);

            var inputPluginContext = PluginContextFactory.GenerateInitialInputDevicePluginContext(inputPlugin);

            var outputPluginContext = PluginContextFactory.GenerateInitialOutputDevicePluginContext(outputPlugin);

            outputPluginContext.SetInput("Listening port", 8080);
            outputPluginContext.SetInput("Path", "/output");

            var effectPluginChain = PluginChainBuilder
                                    .CreateEffectPluginChain()
                                    .AddEffectPlugin(effectPlugin, effectPluginContext)
                                    .FinishAddingDependencies();

            var processingPluginChain = PluginChainBuilder
                                        .CreateProcessingPluginChain()
                                        .AddInputDevicePlugin(inputPlugin, inputPluginContext)
                                        .SetEffectPluginChain(effectPluginChain)
                                        .AddOutputDevicePlugin(outputPlugin, outputPluginContext);

            pluginRunner.StartProcessingPluginChain(processingPluginChain);

            buttonSelectPlugins.Enabled = false;
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("--- Plugin test console ---");
            Console.WriteLine();

            int           pluginCount      = 0;
            IPluginReader reader           = new PluginReader();
            var           availablePlugins = new Dictionary <int, IPlugin>();
            var           pluginOptions    = new List <string>();
            var           plugins          = reader.GetAvailablePlugins <IInputDevicePlugin>();

            foreach (var plugin in plugins)
            {
                availablePlugins.Add(pluginCount++, plugin);
                pluginOptions.Add(string.Format("[{0}] {1}", pluginCount, plugin.Configure().PluginDisplayName));
            }

            var pluginSelection = RequestForValidSelection <int>("Select from the following available plugins:", pluginOptions, availablePlugins.Keys.Select(k => (k + 1).ToString()));

            Console.Clear();

            IPluginRunner runner  = new PluginRunner();
            var           context = PluginContextFactory.GenerateInitialInputDevicePluginContext((IInputDevicePlugin)availablePlugins[pluginSelection - 1]);

            foreach (var input in context.GetPluginInputs())
            {
                var param = RequestForValidInput(string.Format("Enter value for parameter '{0}':", input.Key), input.Value);
                context.SetInput(input.Key, param);
            }

            Console.Clear();
            Console.WriteLine("Running plugin...");
            Console.WriteLine("Press ESC to stop");
            Console.WriteLine();

            var cts = new CancellationTokenSource();

            runner.RunInputDevicePlugin((IInputDevicePlugin)availablePlugins[pluginSelection - 1], context,
                                        (c) =>
            {
                Console.WriteLine();
                Console.WriteLine("Output changed: ");
                var outputValues = new List <object>();
                foreach (var output in context.GetPluginOutputs())
                {
                    outputValues.Add(context.GetOutput(output.Key));
                }

                Console.WriteLine(JsonConvert.SerializeObject(outputValues));
            },
                                        (ex) =>
            {
                Console.WriteLine("An error occurred in the plugin: " + ex.Message);
            },
                                        cts.Token);

            while (Console.ReadKey().Key != ConsoleKey.Escape)
            {
                continue;
            }

            cts.Cancel();

            availablePlugins[pluginSelection - 1].Dispose();
        }