Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/enable plugin by dependency #394

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public PluginDef UpdatePluginStatus(IServiceProvider services, string id, bool e
if (enable)
{
var dependentPlugins = new HashSet<string>();
FindPluginDependency(id, enable, ref dependentPlugins);
var dependentAgentIds = new HashSet<string>();
FindPluginDependency(id, enable, ref dependentPlugins, ref dependentAgentIds);
var missingPlugins = dependentPlugins.Where(x => !config.EnabledPlugins.Contains(x)).ToList();
if (!missingPlugins.IsNullOrEmpty())
{
Expand All @@ -155,7 +156,7 @@ public PluginDef UpdatePluginStatus(IServiceProvider services, string id, bool e

// enable agents
var agentService = services.GetRequiredService<IAgentService>();
foreach (var agentId in plugin.AgentIds)
foreach (var agentId in dependentAgentIds)
{
var agent = agentService.LoadAgent(agentId).Result;
agent.Disabled = false;
Expand Down Expand Up @@ -189,7 +190,7 @@ public PluginDef UpdatePluginStatus(IServiceProvider services, string id, bool e
return plugin;
}

private void FindPluginDependency(string pluginId, bool enabled, ref HashSet<string> dependentPlugins)
private void FindPluginDependency(string pluginId, bool enabled, ref HashSet<string> dependentPlugins, ref HashSet<string> dependentAgentIds)
{
var pluginDef = _plugins.FirstOrDefault(x => x.Id == pluginId);
if (pluginDef == null) return;
Expand All @@ -198,6 +199,13 @@ private void FindPluginDependency(string pluginId, bool enabled, ref HashSet<str
{
pluginDef.Enabled = enabled;
dependentPlugins.Add(pluginId);
if (!pluginDef.AgentIds.IsNullOrEmpty())
{
foreach (var agentId in pluginDef.AgentIds)
{
dependentAgentIds.Add(agentId);
}
}
}

var foundPlugin = _modules.FirstOrDefault(x => x.Id == pluginId);
Expand All @@ -213,7 +221,7 @@ private void FindPluginDependency(string pluginId, bool enabled, ref HashSet<str

foreach (var plugin in plugins)
{
FindPluginDependency(plugin.Id, enabled, ref dependentPlugins);
FindPluginDependency(plugin.Id, enabled, ref dependentPlugins, ref dependentAgentIds);
}
}
}
Expand Down