SharpPluginSystem 1.0.8.2

dotnet add package SharpPluginSystem --version 1.0.8.2                
NuGet\Install-Package SharpPluginSystem -Version 1.0.8.2                
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.8.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SharpPluginSystem --version 1.0.8.2                
#r "nuget: SharpPluginSystem, 1.0.8.2"                
#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.8.2

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

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 ConsumerPlugin : Plugin
{
    public override string PluginId => "consumer_plugin";
    public override string PluginName => "Consumer Plugin";
    public override FXPluginType PluginType => FXPluginType.Sequential;

    public override List<string> InputNames => new List<string> { "Input" };
    public override List<string> OutputNames => new List<string> { "ProcessedOutput" };

    public ConsumerPlugin()
    {
        RegisterFunction("ProcessedOutput", (inputs, lastResult) =>
        {
            var input = Convert.ToSingle(inputs["Input"]);
            return input * 2; // Example processing
        });
    }
}

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:



static async Task Main()
    {
        var fxGraph = new FXGraph();

        // Create the MathPlugin
        var mathPlugin = new MathPlugin();

        // Add MathPlugin to the graph
        var mathNode = new FXGraphItem(mathPlugin);
        fxGraph.AddPlugin(mathPlugin);

        // Simulate an external consumer node (hypothetical)
        var consumerPlugin = new ConsumerPlugin(); // A plugin that consumes "Sum"
        fxGraph.AddPlugin(consumerPlugin);

        // Connect the "Sum" output of MathPlugin to the "Input" of ConsumerPlugin
        fxGraph.ConnectNodes(mathNode.UniqueId, "Sum", consumerPlugin.PluginId, "Input");

        // Define inputs for the MathPlugin
        var inputs = new Dictionary<string, object> { { "A", 10f }, { "B", 5f } };

        // Run the graph
        var result = await fxGraph.RunFXGraphAsync();

        Console.WriteLine($"Final Result: {result}");
    }

Asynchronous Execution

Just incase you don't want your UI to freeze while executing a plugin, you can run the graph asynchronously.

var mathPlugin = new MathPlugin();

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

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

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