Пример #1
0
        // Selects the specified plugin and executes it
        internal static void ExecuteCommand(string i, string o, string[] inputOptions, string[] outputOptions)
        {
            // TODO: This has to be improved, it's a big workaround to convert the optons to JObject
            // Convert options to dictionary
            IDictionary <string, string> inputOptionsDict  = inputOptions.Select(part => part.Split(':')).ToDictionary(sp => sp[0], sp => sp[1]);
            IDictionary <string, string> outputOptionsDict = outputOptions.Select(part => part.Split(':')).ToDictionary(sp => sp[0], sp => sp[1]);

            // Set current directory as base directory
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            // Create Settings
            Models.InputPlugin input = new Models.InputPlugin()
            {
                Name     = i,
                Settings = JObject.FromObject(inputOptionsDict),
                Instance = (IInputPlugin)Agent.GetPluginInstance(i)
            };

            Models.OutputPlugin output = new Models.OutputPlugin()
            {
                Name     = i,
                Settings = JObject.FromObject(outputOptionsDict),
                Instance = (IOutputPlugin)Agent.GetPluginInstance(o)
            };

            // Load plugins after parse options
            //List<PluginDefinition> pluginList = Agent.LoadPlugins();
            string inputResult = input.Instance.Execute(input.Settings);

            output.Instance.Execute(inputResult, output.Settings);
        }
Пример #2
0
 public Task(InputPlugin input, OutputPlugin output)
 {
     InputPlugin   = input;
     OutputPlugin  = output;
     InputOptions  = input.Settings;
     OutputOptions = output.Settings;
 }
Пример #3
0
        /// <summary>
        /// Schedule tasks defined in the config file
        /// </summary>
        /// <param name="inputPlugins">Plugins to be executed</param>
        internal static void CreateTasks(List <Settings.InputPlugin> inputPlugins)
        {
            // Set current directory as base directory
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            foreach (Settings.InputPlugin input in inputPlugins)
            {
                try
                {
                    var inputPlugin = new Winagent.Models.InputPlugin()
                    {
                        Name     = input.Name,
                        Settings = input.Settings,
                        Instance = (IInputPlugin)GetPluginInstance(input.Name)
                    };

                    foreach (Settings.OutputPlugin output in input.OutputPlugins)
                    {
                        var outputPlugin = new Winagent.Models.OutputPlugin()
                        {
                            Name     = output.Name,
                            Settings = output.Settings,
                            Instance = (IOutputPlugin)GetPluginInstance(output.Name)
                        };

                        // Create task with the input and output plugins to be run by the Timer
                        Task task = new Task(inputPlugin, outputPlugin);

                        // Set event handler for the messages received from this plugins
                        inputPlugin.Instance.MessageEvent  += new EventHandler <MessageEventArgs>((sender, eventArgs) => OnMessageEvent(sender, eventArgs, task));
                        outputPlugin.Instance.MessageEvent += new EventHandler <MessageEventArgs>((sender, eventArgs) => OnMessageEvent(sender, eventArgs, task));

                        // Create Timer to schedule the task
                        Timer timer = new Timer(new TimerCallback(ExecuteTask), task, 0, output.Schedule.GetTime());

                        // Put a reference to the timer in the task, so it can be managed from inside the callback
                        task.Timer = timer;

                        // Save reference to avoid GC
                        timersReference.Add(timer);
                    }
                }
                catch (InvalidOperationException ioe)
                {
                    // EventID 4 => There are no plugins to execute
                    MessageHandler.HandleError(String.Format("The specified plugin does not exist in the \"plugins\" directory."), 4, ioe);

                    throw;
                }
            }
        }