Concepts

Plugins

Code that runs in the background after changes are saved.

Plugins are code that runs in the background after changes are saved. A plugin class names a perspective and when to fire; it receives the perspective's values before and after the change, and can read and write entities.

Triggers

AttributeFires when
[FireOnAdd("Staff")]An entity gains the perspective (it's created with it, or it's added).
[FireOnUpdate("Staff")]Any field the perspective lists changes.
[FireOnFieldUpdate("Staff", "department")]A watched field changes.
[FireOnDeleted("Staff")]An entity loses the perspective, or is deleted.

A field shared by several perspectives fires all of their plugins. Each class gets at most one event per perspective per change.

How plugins run

  • After the write. The write never waits for plugins, and a plugin can't fail a change that's already saved. Plugins can't veto changes.
  • In order. Each plugin has its own worker, which runs its events one at a time, in commit order. Different plugins run in parallel.
  • Retried. An exception, or taking more than 60 seconds, is retried twice. Then the failure is counted and the error kept with the plugin's recent errors.
  • No loops. Changes made by plugins are recorded as made by plugin:<id>. A change more than five plugin levels deep doesn't fire plugins, so plugins that update each other can't loop forever.
  • Not durable. Events waiting in memory are lost if the server stops.

Packages

A plugin is a .NET class library that references the OmniCore.PlugIn package. Building it produces an .opl file, which a System Admin uploads. A package can also:

  • carry schema in its manifest (fields, perspectives and relationships), added when it's installed;
  • hold workflow nodes, which appear in the workflow designer. See Writing workflow nodes.

Installing is all or nothing: the package, its assemblies and its schema are checked first, and if anything is wrong nothing changes.

Isolation

Each plugin loads in its own collectible load context, so it can be replaced, disabled or removed without a restart. Plugins run in-process with full trust, which is why only System Admins can install them. Removing a plugin leaves the schema it added.