Skip to content

Commit 40b44f0

Browse files
committed
Initial Commit
#1
1 parent 43794bb commit 40b44f0

10 files changed

Lines changed: 471 additions & 1 deletion

Plugins.Template.sln

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35728.132
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowSynx.Plugins.Template", "src\FlowSynx.Plugins.Template.csproj", "{F9D91FB3-DFB2-46C2-A874-ABDDAC59565B}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A53C93CA-02F3-45BC-A0F0-207FEBFB3F38}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{F9D91FB3-DFB2-46C2-A874-ABDDAC59565B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{F9D91FB3-DFB2-46C2-A874-ABDDAC59565B}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{F9D91FB3-DFB2-46C2-A874-ABDDAC59565B}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{F9D91FB3-DFB2-46C2-A874-ABDDAC59565B}.Release|Any CPU.Build.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(NestedProjects) = preSolution
25+
{F9D91FB3-DFB2-46C2-A874-ABDDAC59565B} = {A53C93CA-02F3-45BC-A0F0-207FEBFB3F38}
26+
EndGlobalSection
27+
EndGlobal

README.md

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,99 @@
1-
# plugin-template-project
1+
# FlowSynx plugin template
2+
3+
This is a ready-to-use **Class Library template** for .NET, designed to help you quickly set up a clean and consistent starting point for your plugin.
4+
5+
You can use it with both the **.NET CLI** and **Visual Studio**.
6+
7+
---
8+
9+
## 🚀 Getting Started
10+
11+
### Install the Template
12+
13+
To use this template, you first need to install it:
14+
15+
```bash
16+
dotnet new -i FlowSynx.PluginTemplate::1.0.0
17+
```
18+
19+
---
20+
21+
### Create a New plugin Library
22+
23+
Run the following command to create a new plugin from this template:
24+
25+
```bash
26+
dotnet new fxplugin -n MyPlugin
27+
```
28+
29+
Replace `MyPlugin` with your desired plugin name.
30+
31+
This will create a folder with a pre-configured **C# Class Library project** ready for development.
32+
33+
---
34+
35+
## 🎨 Visual Studio Support
36+
37+
This template works in Visual Studio. After installation:
38+
39+
1. Open **Visual Studio**
40+
2. Go to **File > New > Project**
41+
3. Search for: `FlowSynx Plugin Template`
42+
4. Select the template and click **Next**
43+
44+
---
45+
46+
## 🛠 Updating the Template
47+
48+
If a new version of the template is available, you can update it by running:
49+
50+
```bash
51+
dotnet new -u FlowSynx.PluginTemplate
52+
dotnet new -i FlowSynx.PluginTemplate::1.1.0
53+
```
54+
55+
---
56+
57+
## 📦 Template Features
58+
59+
✅ Clean Class Library structure
60+
✅ Compatible with .NET 6, 7, and 8+
61+
✅ Works with both the CLI and Visual Studio
62+
63+
---
64+
65+
## 📂 Project Structure
66+
67+
When you create a project, the following structure is generated:
68+
69+
```
70+
MyAwesomeLibrary/
71+
72+
├── Models
73+
├──── InputParameter.cs
74+
├──── MathPluginSpecifications.cs
75+
├── flowsynx.png
76+
├── MathPlugin.cs
77+
├── README.md
78+
```
79+
80+
---
81+
82+
## ❓ Need Help?
83+
84+
If you run into issues using this template:
85+
86+
- Make sure you have the latest version of the .NET SDK installed.
87+
- Try uninstalling and reinstalling the template:
88+
89+
```bash
90+
dotnet new -u FlowSynx.PluginTemplate
91+
dotnet new -i FlowSynx.PluginTemplate
92+
```
93+
94+
- Restart Visual Studio after installation to refresh the template list.
95+
96+
---
97+
98+
## ✍️ Author
99+
© FlowSynx. All rights reserved.

src/.template.config/icon.png

8.62 KB
Loading

src/.template.config/template.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "http://json.schemastore.org/template",
3+
"author": "FlowSynx",
4+
"classifications": [ "FlowSynx", "PluginCore", "Library" ],
5+
"identity": "FlowSynx.PluginTemplate",
6+
"name": "FlowSynx Plugin Template",
7+
"shortName": "fxplugin",
8+
"description": "Make plugin integration for the FlowSynx automation engine.",
9+
"tags": {
10+
"language": "C#",
11+
"type": "project"
12+
},
13+
"sourceName": "TemplatePluginProject",
14+
"preferNameDirectory": true,
15+
"icon": "icon.png"
16+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Compile Remove=".template.config\**" />
11+
<EmbeddedResource Remove=".template.config\**" />
12+
<None Remove=".template.config\**" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="FlowSynx.PluginCore" Version="1.3.3" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<None Update="flowsynx.png">
21+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
22+
</None>
23+
<None Update="README.md">
24+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
25+
</None>
26+
</ItemGroup>
27+
28+
</Project>

src/MathPlugin.cs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using FlowSynx.PluginCore;
2+
using FlowSynx.PluginCore.Extensions;
3+
using FlowSynx.PluginCore.Helpers;
4+
using FlowSynx.Plugins.Template.Models;
5+
6+
namespace FlowSynx.Plugins.Template;
7+
8+
public class MathPlugin : IPlugin
9+
{
10+
private IPluginLogger? _logger;
11+
private bool _isInitialized;
12+
13+
public PluginMetadata Metadata => new()
14+
{
15+
Id = Guid.Parse("5cb7390d-d578-4cd0-8368-b73d8bae1b0a"),
16+
Name = "MyPlugin",
17+
CompanyName = "MyCompany",
18+
Description = "This is the test plugin for FlowSynx workflow engine.",
19+
Version = new Version(1, 0, 0),
20+
Category = PluginCategory.Data,
21+
Authors = new List<string> { "MyCompany" },
22+
Copyright = "© MyCompany. All rights reserved.",
23+
Icon = "flowsynx.png",
24+
ReadMe = "README.md",
25+
ProjectUrl = "https://example.com",
26+
Tags = new List<string>() { "mycompany", "test-plugin", "data", "data-platform", "plugin", "flowsynx" },
27+
MinimumFlowSynxVersion = new Version(1, 0, 0),
28+
};
29+
30+
public PluginSpecifications? Specifications { get; set; }
31+
32+
public Type SpecificationsType => typeof(MathPluginSpecifications);
33+
34+
private Dictionary<string, Func<InputParameter, CancellationToken, Task<object?>>> OperationMap
35+
=> new(StringComparer.OrdinalIgnoreCase)
36+
{
37+
["plus"] = ExecuteAddAsync,
38+
["subtract"] = ExecuteSubtractAsync,
39+
["multiply"] = ExecuteMultiplyAsync,
40+
["divide"] = ExecuteDivideAsync
41+
};
42+
43+
public IReadOnlyCollection<string> SupportedOperations => OperationMap.Keys;
44+
45+
public Task Initialize(IPluginLogger logger)
46+
{
47+
if (ReflectionHelper.IsCalledViaReflection())
48+
throw new InvalidOperationException("Reflection-based access is not allowed.");
49+
50+
ArgumentNullException.ThrowIfNull(logger);
51+
_logger = logger;
52+
_isInitialized = true;
53+
return Task.CompletedTask;
54+
}
55+
56+
public async Task<object?> ExecuteAsync(PluginParameters parameters, CancellationToken cancellationToken)
57+
{
58+
cancellationToken.ThrowIfCancellationRequested();
59+
60+
if (ReflectionHelper.IsCalledViaReflection())
61+
throw new InvalidOperationException("Reflection-based access is not allowed.");
62+
63+
if (!_isInitialized)
64+
throw new InvalidOperationException($"Plugin '{Metadata.Name}' v{Metadata.Version} is not initialized.");
65+
66+
var inputParameter = parameters.ToObject<InputParameter>();
67+
if (!OperationMap.TryGetValue(inputParameter.Operation, out var handler))
68+
throw new NotSupportedException($"Operation '{inputParameter.Operation}' is not supported.");
69+
70+
return await handler(inputParameter, cancellationToken);
71+
}
72+
73+
#region private methods
74+
private Task<object?> ExecuteAddAsync(InputParameter parameters, CancellationToken cancellationToken)
75+
{
76+
double result = parameters.Number1 + parameters.Number2;
77+
_logger?.LogInfo($"Adding {parameters.Number1} + {parameters.Number2} = {result}");
78+
return Task.FromResult<object?>(result);
79+
}
80+
81+
private Task<object?> ExecuteSubtractAsync(InputParameter parameters, CancellationToken cancellationToken)
82+
{
83+
double result = parameters.Number1 - parameters.Number2;
84+
_logger?.LogInfo($"Subtracting {parameters.Number1} - {parameters.Number2} = {result}");
85+
return Task.FromResult<object?>(result);
86+
}
87+
88+
private Task<object?> ExecuteMultiplyAsync(InputParameter parameters, CancellationToken cancellationToken)
89+
{
90+
double result = parameters.Number1 * parameters.Number2;
91+
_logger?.LogInfo($"Multiplying {parameters.Number1} * {parameters.Number2} = {result}");
92+
return Task.FromResult<object?>(result);
93+
}
94+
95+
private Task<object?> ExecuteDivideAsync(InputParameter parameters, CancellationToken cancellationToken)
96+
{
97+
if (parameters.Number2 == 0)
98+
{
99+
_logger?.LogError("Division by zero attempted.");
100+
throw new DivideByZeroException("Cannot divide by zero.");
101+
}
102+
double result = parameters.Number1 / parameters.Number2;
103+
_logger?.LogInfo($"Dividing {parameters.Number1} / {parameters.Number2} = {result}");
104+
return Task.FromResult<object?>(result);
105+
}
106+
#endregion
107+
}

src/Models/InputParameter.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace FlowSynx.Plugins.Template.Models;
2+
3+
internal class InputParameter
4+
{
5+
public string Operation { get; set; } = string.Empty;
6+
public double Number1 { get; set; }
7+
public double Number2 { get; set; }
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using FlowSynx.PluginCore;
2+
3+
namespace FlowSynx.Plugins.Template.Models;
4+
5+
public class MathPluginSpecifications : PluginSpecifications
6+
{
7+
8+
}

0 commit comments

Comments
 (0)