Plugin Architecture Version 1

The following C# class is taken from our demo project https://github.com/ikarstein/kenaflow.demoplugin.v1

using System;
using System.Collections;
using System.Collections.Generic;
using System.Management.Automation;

namespace kenaflow.demoplugin.v1
{
    public class DemoPluginV1 : KenaflowPluginV1
    {
        private readonly KenaflowPluginConfigurationV1 MyConfig = new KenaflowPluginConfigurationV1
        {
            Id = Guid.Parse("{E9132626-B03B-415A-A73F-07CBF56D151E}"),
            Enabled = true,
            Name = "Demo Plugin v1",
            Version = new Version("1.0.0.0"),
            MinKenaflowVersion = new Version("4.0.0.0"),
            LogDebug = true,
			SupportedWorkflowTypes = new List<string>{"*"}
        };

        protected override KenaflowPluginConfigurationV1 GetPluginConfig(Options options)
        {
            //Return the Plugin Configuriation to kenaflow.
            LogNormal("Loading config of DemoPlugin v1");
            return MyConfig;
        }

        protected override void Loaded()
        {
            //Can be used to initialize the plugin after it was loaded and successfully registered.
        }

        protected override void Init(WFConfig config)
        {
            MyConfig.Enabled = true;
        }
    }

    [Cmdlet("Get", "PluginTestV1")]
    public class Test : PSCmdlet
    {
        protected override void ProcessRecord()
        {
            WriteObject($"Test: {DateTime.Now}");
        }
    }
}

The plugin class is derrived from KenaflowPluginV1.

This base class offers some tools that are described in this article: Helper Methods.

It has a configuration object that is stored in a private property called MyConfig.

During initialization kenaflow requests this configuration object by calling GetPluginConfig. The parameter options will contain used the command line options for kenaflow.exe.

Id is the unique ID of the plugin.

Enabled tells kenaflow whether the plugin is available. If set to false the plugin is going to be ignored. But if kenaflow.exe was started with command line switch --plugin <assemlby> the plugin is executed even if it's Enabled-setting is `false.

Name is the display name of the plugin. It must be unique in kenaflow. No other plugin can have the same name!

Version is the version of the plugin. It's the developers choice what to set here.

MinKenaflowVersion is the minimum kenaflow version that is supported by the plugin.

LogDebug tells kenaflow to write some debugging messages to the log reporting plugin method calls.

SupportedWorkflowTypes can be used to restrict the provided Cmdlets to certain workflow types. Valid values are:

To support all workflow types please specify:

SupportedWorkflowTypes = new List{"*"}

> To support **no** workflow types please specify:
> ```cs
SupportedWorkflowTypes = null

or

SupportedWorkflowTypes = new List<string()


#### Method `KenaflowPluginConfigurationV1 GetPluginConfig(Options options)`

The method is called to request the plugin configuration.

#### Method `void Loaded()`

The method is called immediately after the plugin was registered successfully.


#### Method `void Init(WFConfig config)`

The method `Init` is called BEFORE each workflow run. Here the plugin gets the configuration of the currently executed workflow. The plugin can decide to deactivate itself by setting `MyConfig.Enabled` to `false`. 


### Cmdlet Definition

The class `Test` in the exmaple above defines the cmdlet `Get-PluginTestV1`.