/ViLA-PluginBase

Contains classes for plugin development for Virpil Communicator.

Primary LanguageC#GNU General Public License v3.0GPL-3.0

ViLA Plugin Base

Nuget .NET 5 CI build GitHub Discord

This contains a single abstract class PluginBase to be used by any virpil communicator plugins.

ViLA Plugin Base logo - a vector outline of a plug, with the cord wound around it like an @ symbol

Usage/Examples

using System.Threading;
using System.Threading.Tasks;

// custom inheriting class with *parameterless constructor*
public class MyPlugin : PluginBase
{
    // you can define your own parameterless constructor if you want, but
    // you won't be able to send data or access LoggerFactory within the constructor

    private readonly CancellationTokenSource _cts = new();
    private CancellationToken CancellationToken => _cts.Token;

    public override async Task<bool> Start()
    {
        // probably not something you want to do in practice, but
        // shows you should run your task on a different thread
        return ThreadPool.QueueUserWorkItem(ctx =>
        {
            var i = 0;
            while (ctx.IsCancellationRequested)
            {
                // it's important to call PluginBase.Send with your data
                Send("id", i++);
                Thread.Sleep(1000);
            }
        }, CancellationToken, false);
    }

    public override async Task Stop()
    {
        _cts.Cancel();
    }
}

Note that QueueUserWorkItem() returns as soon as the task is created, and the task continues running on a different thread. This is very important - all plugins must complete initialization and return from their respective Start() methods in order for ViLA to function.

Installation

You can find this package on NuGet. When installing, it is important to add the following to your .csproj file:

<PackageReference Include="ViLA.PluginBase" Version="<version>">
    <ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>

This will prevent any dependency confusion between your plugin, any other plugins, and the application - all of which depend on this package and may be using slightly different versions.

Used By

Some example plugins include:

Acknowledgements