SharpPluginSystem 1.0.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package SharpPluginSystem --version 1.0.7                
NuGet\Install-Package SharpPluginSystem -Version 1.0.7                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SharpPluginSystem" Version="1.0.7" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SharpPluginSystem --version 1.0.7                
#r "nuget: SharpPluginSystem, 1.0.7"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SharpPluginSystem as a Cake Addin
#addin nuget:?package=SharpPluginSystem&version=1.0.7

// Install SharpPluginSystem as a Cake Tool
#tool nuget:?package=SharpPluginSystem&version=1.0.7                

Plugin System with Node-Based Workflow

Overview

This plugin system provides a flexible and extensible architecture for defining and executing plugins. It supports named inputs and outputs, node-based workflows, and dynamic execution of specific functions. Designed for advanced use cases like FX graphs or modular applications, this system enables developers to build robust, reusable, and dynamic components.

Features

  • Strongly-Typed Inputs and Outputs: Each plugin can define named inputs and outputs with automatic mapping.
  • Dynamic Function Registration: Register multiple output functions for plugins and execute them only when connected.
  • Node-Based Workflow: Create and connect plugins dynamically in a graph-style system.
  • Single Plugin Execution: Execute individual plugins with specified inputs and outputs.
  • Last Result Propagation: Pass the output of one plugin to the next in sequence.
  • Save and Load Graphs: Serialize and deserialize the plugin graph for reuse.
  • UI-Friendly Properties: Includes positional and connection metadata for rendering plugins in a graphical node editor.

Getting Started

Installation

  1. Clone the repository or download the source files.
  2. Add the files to your project.

Plugin Implementation

Create a custom plugin by subclassing Plugin:

using PluginSystem;

public class MathPlugin : Plugin
{
    public override string PluginId => "math_plugin";
    public override string PluginName => "Math Plugin";
    public override FXPluginType PluginType => FXPluginType.Sequential;

    public override List<string> InputNames => new List<string> { "A", "B" };
    public override List<string> OutputNames => new List<string> { "Sum", "Difference" };

    public MathPlugin()
    {
        RegisterFunction("Sum", (inputs, lastResult) =>
        {
            var a = Convert.ToSingle(inputs["A"]);
            var b = Convert.ToSingle(inputs["B"]);
            return a + b;
        });

        RegisterFunction("Difference", (inputs, lastResult) =>
        {
            var a = Convert.ToSingle(inputs["A"]);
            var b = Convert.ToSingle(inputs["B"]);
            return a - b;
        });
    }

    public override object[] Run(Dictionary<string, object> inputs, object lastResult)
    {
        throw new NotImplementedException("Use registered functions to execute specific outputs.");
    }
}

Running a Plugin

Run a single plugin by creating an instance and setting its inputs:

var mathPlugin = new MathPlugin();

var inputs = new Dictionary<string, object>
{
    { "A", 10f },
    { "B", 5f }
};

var sumResult = mathPlugin.ExecuteFunction("Sum", inputs, null);
Console.WriteLine($"Sum: {sumResult}");

var differenceResult = mathPlugin.ExecuteFunction("Difference", inputs, null);
Console.WriteLine($"Difference: {differenceResult}");

Node-Based Workflow

  1. Create an FXGraph and add plugins to it.
  2. Connect plugins dynamically by specifying source and target nodes.
  3. Run the graph to execute connected functions.

Example:

var fxGraph = new FXGraph();

var mathPlugin = new MathPlugin();
fxGraph.AddPlugin(mathPlugin);

var greetingPlugin = new GreetingPlugin();
fxGraph.AddPlugin(greetingPlugin);

fxGraph.ConnectNodes(mathPlugin.PluginId, "Sum", greetingPlugin.PluginId, "Name");

var result = fxGraph.RunFXGraph();
Console.WriteLine($"Final Result: {result}");

Save and Load Graphs

Save Graph

fxGraph.SaveToFile("fxgraph.json");

Load Graph

var loadedGraph = FXGraph.LoadFromFile("fxgraph.json", availablePlugins);

Contribution

Contributions are welcome! Feel free to submit issues, fork the repo, or create pull requests.

License

This project is licensed under the Apache 2.0 License. See LICENSE for details.

Contact

For questions or support, fill out an issue.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SharpPluginSystem:

Package Downloads
BravoCMSLibrary

Create modular plugins for your projects in C#!

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.8.2 244 11/27/2024
1.0.8.1 78 11/27/2024
1.0.8 68 11/27/2024
1.0.7.3 73 11/27/2024
1.0.7.2 68 11/27/2024
1.0.7 79 11/27/2024