Table of Contents

Class CadPluginManager

Namespace
OpenCAD2D.Plugins
Assembly
OpenCAD2D.Core.dll

The command plugins of the presenter, as AutoCAD's NETLOAD and APPLOAD keep them (A14 of the plan): loaded from a .dll, the folder of one, or the plugin folder, unloaded and loaded again while the presenter runs, their commands added to the command line of every drawing open (Attach(CadCommandRegistry)), every load written in the load log (Log) and logged with its full path.

public sealed class CadPluginManager : IDisposable
Inheritance
CadPluginManager
Implements
Inherited Members

Remarks

Shadow copy. A plugin's files are copied to a folder of the manager's own (ShadowFolder) and loaded from there, so that the .dll a plugin's author builds is never locked: build it again and PLUGINRELOAD picks it up. On .NET 8 each plugin has a collectible load context, which unloading frees; on .NET Framework (hosted in Tekla) nothing can be unloaded, so PLUGINUNLOAD only takes the plugin's commands away and a new build is taken when the presenter restarts (D19). CadPluginLoader is what differs.

Trusted folders, as AutoCAD's TRUSTEDPATHS (D21): loading a plugin runs its code with the user's rights, so a file outside TrustedFolders is loaded only when ConfirmUntrusted says yes, and never where it is not set.

At every start (LoadAtStart()) the plugins of PluginFolder are loaded (each .dll directly in it, then each folder below it that holds .dll files as one plugin, at any depth), then those on the startup list, which is kept with the trusted folders in the JSON file SettingsPath.

The manager is used from one thread, the window's.

Constructors

CadPluginManager(CadPluginLoader, string, string, string)

Makes the manager of the presenter's plugins, reading its startup list and trusted folders from settingsPath.

Fields

LoadCommand

The name of the command that loads a plugin by its path: PLUGINLOAD, alias NETLOAD.

ReloadCommand

The name of the command that loads a plugin again from its file by its name: PLUGINRELOAD.

UnloadCommand

The name of the command that unloads a plugin by its name: PLUGINUNLOAD.

Properties

CanUnload

Gets whether unloading a plugin frees its code (.NET 8), or only switches it off (.NET Framework).

ConfirmUntrusted

Gets or sets what is asked before a plugin outside the trusted folders is loaded: given the file's full path, it says whether to load it, as a dialog that asks the user does. Null, as it is until set, loads none.

Log

Gets the load log, the oldest line first; LogChanged is raised as it grows.

PluginFolder

Gets the plugin folder, always trusted, whose plugins are loaded at every start.

Plugins

Gets the plugins known in this session, loaded or not, in ordinal order of their names, either case the same, then of their paths.

SettingsPath

Gets the JSON file of the startup list and the trusted folders.

ShadowFolder

Gets the folder the plugins' files are copied to and loaded from.

StartupList

Gets the paths of the startup list, loaded at every start after the plugin folder, in the order they were put on it.

TrustedFolders

Gets the trusted folders, full paths: the plugin folder first, then those added, in the order they were added.

Methods

AddTrustedFolder(string)

Adds a trusted folder, whose plugins load without asking, and writes the list.

Attach(CadCommandRegistry)

Adds the commands of the loaded plugins to a registry, and those of every plugin loaded later, with PLUGINLOAD (alias NETLOAD), PLUGINUNLOAD and PLUGINRELOAD, which ask on the command line for a path or a name. A command the registry has already is left, so that the window's own PLUGINLOAD, which shows a file dialog, can be added first.

Detach(CadCommandRegistry)

Takes the plugins' commands and those Attach(CadCommandRegistry) added out of a registry, as when its drawing is closed.

Dispose()

Unloads every plugin and deletes the copies of their files that can be deleted; a copy the runtime still holds is deleted at a later start.

Find(string)

Finds a plugin known in this session by its name, either case the same.

IsTrusted(string)

Gets whether a file or folder lies in one of the trusted folders.

Load(string)

Loads a plugin for this session, as PLUGINLOAD and NETLOAD do: from a .dll (with the plugin.json beside it, where there is one), or the folder of a plugin. Its commands are added to every registry attached. Refused, with the reason, where the path is outside the trusted folders and not confirmed, the plugin needs a newer API, a plugin of its name or path is loaded already, or it has no command.

LoadAtStart()

Loads what is loaded at every start: each .dll directly in the plugin folder, in ordinal order of the names (either case the same), then each folder below it that has a plugin.json or a .dll directly in it as one plugin, at any depth, in the order of the walk (OpenCAD2D.CadSupportWalk), then the startup list in its order. A folder with neither is walked into, and one with either is not. The plugin folder is trusted, so nothing is asked. A plugin loaded already is left; each other is a line of the log, and a .dll that is no plugin, or cannot be loaded, is refused with its line and does not stop the others.

Reload(string)

Loads a plugin again from its file, as PLUGINRELOAD does, unloading it first where it is loaded: a plugin's author changes its code, builds it and reloads it with the presenter running. On .NET Framework the build loaded first in the session stays, and the result says so.

Remove(string)

Forgets a plugin: it is unloaded where it is loaded, taken out of Plugins and off the startup list, and the list is written. Loading its file again makes it known anew. A plugin of the plugin folder cannot be forgotten, because it is loaded at every start.

RemoveTrustedFolder(string)

Takes a trusted folder off the list and writes it; the plugin folder stays trusted.

SetLoadAtStartup(string, bool)

Puts a plugin on the startup list, or takes it off, and writes the list; a plugin of the plugin folder is loaded at every start anyway.

Unload(string)

Unloads a plugin, as PLUGINUNLOAD does: its commands go from every registry, and a run of one going on fails at its next step. On .NET 8 its load context is freed; on .NET Framework its code stays loaded, switched off, until the presenter restarts. It stays in Plugins, so that it can be loaded again.

Events

LogChanged

Raised when a line is added to Log.

PluginsChanged

Raised when a plugin is loaded or unloaded, or put on or off the startup list.