Exemple #1
0
        /// <summary>
        /// Loads a plugin from selected path.
        /// <br/><b>Important note:</b> keeping references to plugin containers outside this class will make them unloadable.
        /// </summary>
        /// <param name="path">Path to load the plugin from. Can point either to local <b>DLL</b>, <b>C# code file</b> or a <b>GitHub project url</b>.</param>
        /// <param name="permissions">Permissions granted to the plugin.</param>
        /// <returns>Loaded plugin. If loading failed, <see cref="PluginContainer.Plugin"/> property will be null.</returns>
        public PluginContainer LoadPlugin(string path, PluginPermissions permissions)
        {
            IPluginProvider provider = PluginProviderSelector.GetPluginProvider(path);

            if (provider == null)
            {
                logger?.LogError($"Couldn't load plugin from path '{path}'");
                return(null);
            }

            PluginContainer plugin = provider.GetPlugin(path, logger);

            return(HandlePlugin(plugin, permissions));
        }
        /// <summary>
        /// Updates the plugin cache with missing plugins and
        /// then copies the required plugins for the task.
        /// </summary>
        public void PreparePlugins(Task task, out string configFileName)
        {
            lock (locker) {
                log.LogMessage("Fetching plugins for task " + task.Id);

                List <Guid>   missingGuids  = new List <Guid>();
                List <Plugin> neededPlugins = new List <Plugin>();
                lock (cachedPluginsGuids) {
                    foreach (Guid pluginId in task.PluginsNeededIds)
                    {
                        Plugin plugin = pluginService.GetPlugin(pluginId);
                        if (plugin != null)
                        {
                            neededPlugins.Add(plugin);
                        }

                        if (!cachedPluginsGuids.Contains(pluginId))
                        {
                            missingGuids.Add(pluginId);
                        }
                    }
                }

                IEnumerable <PluginData> pluginDatas = pluginService.GetPluginDatas(missingGuids);

                if (pluginDatas != null)
                {
                    foreach (PluginData pluginData in pluginDatas)
                    {
                        string pluginDir = Path.Combine(PluginCacheDir, pluginData.PluginId.ToString());

                        //put all files belonging to a plugin in the same directory
                        SafelyCreateDirectory(pluginDir);
                        File.WriteAllBytes(Path.Combine(pluginDir, Path.GetFileName(pluginData.FileName)), pluginData.Data);
                    }

                    if (missingGuids.Count > 0)
                    {
                        DoUpdateRun();
                    }
                    CopyPluginsForJob(neededPlugins, task.Id, out configFileName);
                }
                else
                {
                    configFileName = "";
                }
                log.LogMessage(string.Format("Fetched {0} plugins for task {1}", missingGuids.Count, task.Id));
            }
        }
Exemple #3
0
 /** <inheritdoc /> */
 public TPlugin GetPlugin <TPlugin>() where TPlugin : class
 {
     return(_pluginProvider.GetPlugin <TPlugin>());
 }