示例#1
0
文件: Program.cs 项目: Slord6/Plugins
        private static List <string> ResolvePluginPaths(ArgParser argParser)
        {
            // Get the plugins in the plugin folder
            List <string> pluginPaths = Directory.GetFiles(@".\Plugins\").ToList();

            // If other locations were passed add those (but add them in front so if they require re-downloading that happens first)
            List <string> locations = argParser.GetValues(ArgStrings.PluginLocations);

            if (locations != null)
            {
                locations.AddRange(pluginPaths);
                pluginPaths = locations;
            }

            // If there are files to load paths from, do that
            locations = argParser.GetValues(ArgStrings.PluginLocationsFromFile);
            if (locations != null)
            {
                List <string> loadedPaths = locations.SelectMany(filePath => LoadPathsFromFile(filePath)).ToList();
                // again insert in the front
                loadedPaths.AddRange(pluginPaths);
                pluginPaths = loadedPaths;
            }

            return(pluginPaths);
        }
示例#2
0
文件: Program.cs 项目: Slord6/Plugins
        static void Main(string[] args)
        {
            try
            {
                ArgParser argParser;
                try
                {
                    argParser = new ArgParser(args, new string[]
                    {
                        ArgStrings.PluginLocations,
                        ArgStrings.Help,
                        ArgStrings.TargetPlugins,
                        ArgStrings.PluginLocationsFromFile
                    });
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(GetHelpText());
                    return;
                }

                if (argParser.GetValues(ArgStrings.Help) != null)
                {
                    Console.WriteLine(GetHelpText());
                    return;
                }

                List <string> pluginPaths = ResolvePluginPaths(argParser);

                // Load plugins and invoke OnLoad for each
                IEnumerable <IPlugin> plugins = PluginHandler.LoadPlugins(pluginPaths.ToArray());

                PluginHandler.RunPlugins(argParser, plugins);

                PluginHandler.UnloadPlugins(ref plugins);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#3
0
        public static void RunPlugins(ArgParser argParser, IEnumerable <IPlugin> plugins)
        {
            List <string> targetPlugins = argParser.GetValues(ArgStrings.TargetPlugins);

            if (targetPlugins == null)
            {
                targetPlugins = plugins.Select(p => p.Name).ToList();
            }

            foreach (string pluginName in targetPlugins)
            {
                Console.WriteLine($"-- {pluginName} --");

                IPlugin plugin = plugins.FirstOrDefault(c => c.Name == pluginName);
                if (plugin == null)
                {
                    Console.WriteLine("No such plugin is known.");
                    return;
                }

                Console.WriteLine("Running...");
                Task <PluginResultData> task = plugin.CreateTask();
                task.RunSynchronously();
                if (!task.IsCompletedSuccessfully)
                {
                    Console.WriteLine("Plugin failed");

                    Exception ex = task.Exception;
                    while (ex != null)
                    {
                        Console.WriteLine(ex.Message);
                        ex = ex.InnerException;
                    }
                }
                else
                {
                    Console.WriteLine("Plugin complete");
                }
            }
        }