An open API service indexing awesome lists of open source software.

https://github.com/flowsynx/plugin-core

Plugin interface for create new plugin for FlowSynx engine
https://github.com/flowsynx/plugin-core

flowsynx plugin-core plugin-designer

Last synced: 3 months ago
JSON representation

Plugin interface for create new plugin for FlowSynx engine

Awesome Lists containing this project

README

          

๏ปฟ# FlowSynx PluginCore

**FlowSynx PluginCore** is a lightweight, extensible plugin execution framework designed for modular application architecture.
It supports structured error handling, versioning, logging, and flexible plugin execution with parameter and specification support.

---

## โœจ Features

- ๐Ÿ”Œ **Plugin Interface**: Define reusable plugins with metadata, specifications, and execution logic.
- โš™๏ธ **Execution Parameters**: Pass dynamic parameters and retrieve results using a standardized dictionary.
- ๐Ÿ“‹ **Specifications Model**: Configure plugins with reusable specifications.
- ๐Ÿชต **Plugin Logging**: Built-in logger interface with multiple severity levels.
- ๐Ÿงช **Versioning System**: Compare and manage plugin versions (`Major.Minor.Patch`).
- โ— **Custom Error Handling**: Structured exceptions and codes via `FlowSynxException` and `ErrorMessage`.
- ๐Ÿท๏ธ **Required Attributes**: Decorate required specification fields with `RequiredMemberAttribute`.

---

## ๐Ÿงฉ Core Concepts

### โœ… IPlugin Interface

The heart of the framework, the `IPlugin` interface, enforces a contract for plugin implementation:

```csharp
public interface IPlugin
{
PluginMetadata Metadata { get; }
PluginSpecifications? Specifications { get; set; }
Type SpecificationsType { get; }
Task Initialize(IPluginLogger logger);
Task ExecuteAsync(PluginParameters parameters, CancellationToken cancellationToken);
}
```

- Metadata: Descriptive data like name, description, author, etc.
- Specifications: Custom configuration for plugin behavior.
- SpecificationsType: Strongly typed representation of specifications (with validation).
- Initialize: Called before execution, typically for setup or validation.
- ExecuteAsync: The main execution method, receiving input parameters and returning results.

## โš™๏ธ Plugin Metadata & Specifications
A case-insensitive dictionary allowing plugins to define required and optional configuration options. Supports deep cloning and dynamic usage:

```csharp
public class PluginSpecifications : Dictionary, ICloneable
```

Supports `[RequiredMember]` attribute for validation:

```csharp
[RequiredMember]
public string RequiredSetting { get; set; }
```

### Create simple specifications
```csharp
public class MyPluginSpecs : PluginSpecifications
{
[RequiredMember]
public string RequiredSetting { get; set; } = "default";
}
```

## ๐Ÿ“ฆ Parameters and Cloning
`PluginParameters` provides a flexible, case-insensitive dictionary to pass runtime data to plugins:

```csharp
public class PluginParameters : Dictionary, ICloneable
```
Use `.Clone()` for safe state reuse.

## ๐Ÿ›  Logging
Plugins receive a logging abstraction to emit structured logs:
```csharp
public interface IPluginLogger
{
void Log(PluginLoggerLevel level, string message);
}
```

### Log Levels
Use the logger with severity levels or extension methods:
```csharp
public enum PluginLoggerLevel
{
Debug,
Information,
Warning,
Error
}
```

#### Logger Extensions
```csharp
logger.LogInfo("Started processing...");
logger.LogError("An error occurred.");
```

## ๐Ÿงญ Categories Support
To organize plugins by type or domain, use the `PluginNamespace` enum:

```csharp
public enum PluginCategory
{
AI,
Api,
Authentication,
BusinessIntelligence,
Blockchain,
Cloud,
Communication,
Data,
Database,
DevOps,
Finance,
ML,
Monitoring,
Logging,
Networking,
ProjectWorkflow,
ResourcePlanning,
Security,
Storage,
Testing,
Web
}
```

## ๐Ÿงช Example Plugin
```csharp
public class SampleGreetingPlugin : IPlugin
{
public PluginMetadata Metadata => new()
{
Id = Guid.Parse("fc58122d-6444-4c5b-ab3d-8cff62283a08"),
Name = "MyPlugin",
Description = "This is a test plugin.",
Version = new PluginVersion(1, 0, 0),
Namespace = PluginNamespace.Api,
CompanyName = "FlowSynx",
Authors = new List { "FlowSynx" },
Copyright = "ยฉ FlowSynx. All rights reserved.",
Tags = new List() { "MyCompany", "TestPlugin" }
};

public PluginSpecifications? Specifications { get; set; }

public Type SpecificationsType => typeof(GreetingSpecs);

public Task Initialize(IPluginLogger logger)
{
logger.LogInfo("Initializing GreetingPlugin...");
return Task.CompletedTask;
}

public Task ExecuteAsync(PluginParameters parameters, CancellationToken cancellationToken)
{
string name = parameters.TryGetValue("name", out var value) ? value?.ToString() ?? "World" : "World";
return Task.FromResult($"Hello, {name}!");
}
}
```