public bool UnloadPlugin(DesktopPluginContext context) { Log.Write("Plugin", $"Unloading plugin '{context.FriendlyName}'", LogLevel.Debug); Plugins.Remove(context); AssembliesChanged?.Invoke(this, EventArgs.Empty); return(context.Assemblies.All(p => RemoveAllTypesForAssembly(p))); }
protected void LoadPlugin(DirectoryInfo directory) { // "Plugins" are directories that contain managed and unmanaged dll // These dlls are loaded into a PluginContext per directory directory.Refresh(); if (Plugins.All(p => p.Directory.Name != directory.Name)) { if (directory.Exists) { Log.Write("Plugin", $"Loading plugin '{directory.Name}'", LogLevel.Debug); var context = new DesktopPluginContext(directory); // Populate PluginTypes so desktop implementations can access them ImportTypes(context); Plugins.Add(context); } else { Log.Write("Plugin", $"Tried to load a nonexistent plugin '{directory.Name}'", LogLevel.Warning); } } else { Log.Write("Plugin", $"Attempted to load the plugin {directory.Name} when it is already loaded.", LogLevel.Debug); } }
public void LoadPlugins(DirectoryInfo directory) { // "Plugins" are directories that contain managed and unmanaged dll // These dlls are loaded into a PluginContext per directory Parallel.ForEach(directory.GetDirectories(), (dir, state, index) => { Log.Write("Plugin", $"Loading plugin '{dir.Name}'"); var context = new DesktopPluginContext(dir); foreach (var plugin in Directory.EnumerateFiles(dir.FullName, "*.dll")) { LoadPlugin(context, plugin); } PluginContexts.Add(context); }); // If there are plugins found outside subdirectories then load into FallbackPluginContext // This fallback does not support loading unmanaged dll if the default loader fails // We don't worry with duplicate entries here since CLR won't load duplicate assemblies of the same file foreach (var plugin in directory.EnumerateFiles("*.dll")) { var name = Regex.Match(plugin.Name, $"^(.+?){plugin.Extension}").Groups[1].Value; Log.Write("Plugin", $"Loading independent plugin '{name}'"); LoadPlugin(FallbackPluginContext, plugin.FullName); } // Populate PluginTypes so UX and Daemon can access them Parallel.ForEach(PluginContexts, (loadedContext, _, index) => { LoadPluginTypes(loadedContext); }); LoadPluginTypes(FallbackPluginContext); }
public bool UpdatePlugin(DesktopPluginContext plugin, DirectoryInfo source) { var targetDir = new DirectoryInfo(plugin.Directory.FullName); if (UninstallPlugin(plugin)) { return(InstallPlugin(targetDir, source)); } return(false); }
public bool UninstallPlugin(DesktopPluginContext plugin) { var random = new Random(); if (!Directory.Exists(TrashDirectory.FullName)) { TrashDirectory.Create(); } Log.Write("Plugin", $"Uninstalling plugin '{plugin.FriendlyName}'"); var trashPath = Path.Join(TrashDirectory.FullName, $"{plugin.FriendlyName}_{random.Next()}"); plugin.Directory.MoveTo(trashPath); return(UnloadPlugin(plugin)); }
public DesktopPluginManager(DirectoryInfo directory) : base() { FallbackPluginContext = new DesktopPluginContext(directory); }