public void BuildDescriptors(string rootDirectory) { RootDirectory = rootDirectory; PluginDescriptors.Clear(); LogSystem?.Print("Scanning for plugins in " + RootDirectory); if (!Directory.Exists(RootDirectory)) { return; } var directories = Directory.GetDirectories(RootDirectory); foreach (string dir in directories) { var descriptor = FindDescriptorByDirectory(dir); if (descriptor != null) { continue; } try { descriptor = new SharpConfigDescriptor(dir); PluginDescriptors.Add(descriptor); } catch (Exception e) { LogSystem?.PrintWarning(e.ToString()); } } }
/// <inheritdoc /> public virtual IModuleHostBuilder UsePlugin(Type type) { type.EnsureHostBuilderPlugin(); if (!PluginDescriptors.Contains(type)) { PluginDescriptors.Add(type); } return(this); }
/// <summary> Tries to find a plugin descriptor by name. </summary> /// <param name="pluginName"> Case-insensitive full name of the plugin. </param> /// <returns> Relevant PluginDescriptor object if found; null if not found. </returns> /// <exception cref="ArgumentNullException"> If pluginName is null. </exception> public static PluginDescriptor FindDescriptor([NotNull] string pluginName) { if (pluginName == null) { throw new ArgumentNullException("pluginName"); } PluginDescriptor result; if (PluginDescriptors.TryGetValue(pluginName.ToLower(), out result)) { return(result); } else { return(null); } }
static void LoadDescriptor(string fullName) { try { XDocument descriptorXml = XDocument.Load(fullName); PluginDescriptor descriptor = new PluginDescriptor(descriptorXml.Root); descriptor.PluginDescriptorFileName = fullName; if (descriptor.LoaderType == PluginLoaderType.Python && pythonPluginLoader == null) { Logger.Log(LogType.Warning, "PluginManager: Could not load {0}: Python support is disabled.", fullName); } else { PluginDescriptors.Add(descriptor.Name.ToLower(), descriptor); } } catch (Exception ex) { Logger.Log(LogType.Error, "PluginManager: Failed to load plugin descriptor from {0}: {1}", fullName, ex); } }