Last modified on 25 September 2024, at 13:36

UBIK Actions

UBIK® Actions provide the possibility to configure a programmatic method to perform for a UBIK® object.

Purpose

In some cases it is required to define a range of actions to be available for a UBIK® MetaClass or instance. For example, if the user should be provided with a custom selection of actions to perform for an object. UBIK® Actions are the representation of such an executable action, and they can be put into relation to a MetaClass, so that one can evaluate a list of eligible actions for any MetaClass.

UBIK.Studio's Class Browser provides available Actions in the context menu for MetaClasses and instances.

In earlier UBIK® versions, Workflows were used for this purpose. However, since UBIK® version 4, Microsoft WF workflows have fallen increasingly out of favor because support for WF Workflows was abandoned in Microsoft's netstandard framework, which UBIK® relies on. Thus, UBIK® Actions can be seen as the designated replacement for WF Workflows in UBIK®.

Configuration of UBIK® Actions

Long story short: Use the ACTION MetaClass to specify a method to execute. Then, relate it to a MetaClass using the SYSREL_METACLASS_ACTION so it can be found for instances of that MetaClass. See below for a deeper understanding of how to use and customize UBIK® Actions.

Entity-relation model

The core of UBIK® Actions consists of a C# interface and a relationship between MetaClasses and Actions. Additionally, there are several convenience utilities to accommodate the definition and configuration of Actions.

IUBIKAction Interface and SYSREL_METACLASS_ACTION Relationship

To configure an Action for an object, one has to declare it as an Action and link it to the MetaClass of the object (or, if the object is a MetaClass itself, to the object). This is enabled by the C# interface IUBIKAction and the system relationship SYSREL_METACLASS_ACTION.

IUBIKAction C# interface and SYSCLS_ACTION Classification

The IUBIKAction interface guarantees the following methods:

namespace UBIK.Kernel
{
    public interface IUBIKAction : IUBIKObject
    {
        bool IsApplicable(BaseClass obj);
        void Perform(BaseClass obj);
        SelectiveItem CategoryObject { get; }
    }
}

To add the IUBIKAction C# interface to the custom code of a UBIK® MetaClass, the classification SYSCLS_ACTION can be assigned to a MetaClass that should define Actions.

SYSREL_METACLASS_ACTION system Relationship

Further, the UBIK® Relationship SYSREL_METACLASS_ACTION is used to relate MetaClasses to any UBIK® object implementing the interface described above.

MetaClass.Actions and MetaClass.AllActions

As a result of a successful configuration, the "Actions" C# property on the MetaClass will return a list of all directly configured actions. Further, "AllActions" will return also all inherited actions.



The ACTION MetaClass

The ACTION MetaClass has the required classification by default and provides a basic implementation for the configuration of a target method. Similar to the obsolete Workflow MetaClass, it provides Boolean properties to flag an Action either for instances or MetaClasses. Also, it has two string properties for the identification of a target method and the class it is defined in:

ACTION properties
Property name Data type Meaning
RUNONINSTANCE Boolean Whether this Action should be performed on instances of related MetaClasses
RUNONMETACLASS Boolean Whether this Action should be performed on related MetaClasses themselves
METHODNAME String The name of the method to perform with this Action
METHODOWNER String The full type name (with namespace in the form of com.example.TypeName) providing the method to perform with this Action

Restrictions for the target class and method

The UBIK® object to perform this action for must be specified for the target class and method, and the target class and method must be accessible. This means both the class and the method must be public. Also, either the method or the class constructor must take a BaseClass as a parameter. Static methods and classes are also supported. In case of a non-static method, the owning class must have a public constructor without parameters or with a single BaseClass parameter. The DLL containing the target method (UBIK® custom code is also supported) must be available to UBIK®, for example in the Injection folder.

Further possibilities for customization

As explained above, the fundamental core requirement for an Action really is the IUBIKAction interface. Therefore, any MetaClass implementing it can be used as an Action MetaClass - as long as it is derived from SYSTEMOBJECT as a root MetaClass. Further, the methods provided by the ACTION default implementation can be overridden and customized using custom object code.

Triggering UBIK® Actions

UBIK® Actions are available in some of our products' UI, for example in UBIK.Studio's context menu in the Class Browser, and UBIK.MaTaP.AdminTool's context menu for project instances. However, they can also be accessed programmatically, for example with the following snippet executing all actions for an instance:

public void PerformAllRelevantActions(BaseClass instance)
{
    MetaClass mc = instance.MetaClass;
    UBIKClassList<RelationalObject> actions = mc.RelatesTo(mc.Environment.GetSystemRelation(SystemObjects.SYSREL_METACLASS_ACTION));
    foreach (RelationalObject ro in actions)
    {
        IUBIKAction action = ro as IUBIKAction;
        if (action != null && action.IsApplicable(instance))
        {
            action.Perform(instance);
        }
    }
}