Skip to content

Commit e4d5582

Browse files
committed
Initial commit
#1
1 parent 40a7e6e commit e4d5582

16 files changed

Lines changed: 979 additions & 2 deletions

Plugins.Csv.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35728.132 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowSynx.Plugins.Csv", "src\FlowSynx.Plugins.Csv.csproj", "{ECD2DE21-BABA-4282-BD92-716CB6754967}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{ECD2DE21-BABA-4282-BD92-716CB6754967}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{ECD2DE21-BABA-4282-BD92-716CB6754967}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{ECD2DE21-BABA-4282-BD92-716CB6754967}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{ECD2DE21-BABA-4282-BD92-716CB6754967}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
1-
# plugin-csv
2-
FlowSynx plugin to reads and writes CSV files, enabling easy batch data import/export operations and integration with spreadsheet-based data workflows.
1+
# FlowSynx CSV Plugin – FlowSynx Platform Integration
2+
3+
The CSV Plugin is a pre-packaged, plug-and-play integration component for the FlowSynx engine. It enables reading from and writing to CSV files with configurable parameters such as file path, delimiter, headers, and encoding. Designed for FlowSynx’s no-code/low-code automation workflows, this plugin simplifies data extraction and transformation tasks.
4+
5+
This plugin is automatically installed by the FlowSynx engine when selected within the platform. It is not intended for manual installation or standalone developer use outside the FlowSynx environment.
6+
7+
---
8+
9+
## Purpose
10+
11+
This plugin allows FlowSynx users to interact with CSV data within workflows without writing code. Once installed, it appears as a connector in the platform’s workflow builder, enabling seamless integration of CSV-based data operations such as importing, exporting, and transformation into automated processes.
12+
13+
---
14+
15+
## Notes
16+
17+
- This plugin is exclusively supported on the FlowSynx platform.
18+
- It is installed automatically by the FlowSynx engine.
19+
- All operational logic is securely managed and executed by FlowSynx.
20+
- File access paths and related settings are configured via platform settings or workflow parameters.
21+
22+
---
23+
24+
## License
25+
26+
© FlowSynx. All rights reserved.

src/CsvPlugin.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using FlowSynx.PluginCore.Helpers;
2+
using FlowSynx.PluginCore;
3+
using FlowSynx.Plugins.Csv.Models;
4+
using FlowSynx.PluginCore.Extensions;
5+
using FlowSynx.Plugins.Csv.Services;
6+
7+
namespace FlowSynx.Plugins.Csv;
8+
9+
public class CsvPlugin: IPlugin
10+
{
11+
private IPluginLogger? _logger;
12+
private ICsvManger _manager = null!;
13+
private CsvPluginSpecifications _csvSenderSpecifications = null!;
14+
private bool _isInitialized;
15+
16+
public PluginMetadata Metadata
17+
{
18+
get
19+
{
20+
return new PluginMetadata
21+
{
22+
Id = Guid.Parse("81c99765-9581-4f13-ba77-86c32ae21d97"),
23+
Name = "Csv",
24+
CompanyName = "FlowSynx",
25+
Description = Resources.PluginDescription,
26+
Version = new PluginVersion(1, 0, 0),
27+
Namespace = PluginNamespace.Connectors,
28+
Authors = new List<string> { "FlowSynx" },
29+
Copyright = "© FlowSynx. All rights reserved.",
30+
Icon = "flowsynx.png",
31+
ReadMe = "README.md",
32+
RepositoryUrl = "https://github.com/flowsynx/plugin-csv",
33+
ProjectUrl = "https://flowsynx.io",
34+
Tags = new List<string>() { "flowSynx", "csv", "comma-separated-values)", "data-platform", "bi-plugins" },
35+
Category = PluginCategories.DataPlatformAndBI
36+
};
37+
}
38+
}
39+
40+
public PluginSpecifications? Specifications { get; set; }
41+
42+
public Type SpecificationsType => typeof(CsvPluginSpecifications);
43+
44+
public Task Initialize(IPluginLogger logger)
45+
{
46+
if (ReflectionHelper.IsCalledViaReflection())
47+
throw new InvalidOperationException(Resources.ReflectionBasedAccessIsNotAllowed);
48+
49+
ArgumentNullException.ThrowIfNull(logger);
50+
_csvSenderSpecifications = Specifications.ToObject<CsvPluginSpecifications>();
51+
_logger = logger;
52+
_manager = new CsvManager(logger);
53+
_isInitialized = true;
54+
return Task.CompletedTask;
55+
}
56+
57+
public Task<object?> ExecuteAsync(PluginParameters parameters, CancellationToken cancellationToken)
58+
{
59+
if (ReflectionHelper.IsCalledViaReflection())
60+
throw new InvalidOperationException(Resources.ReflectionBasedAccessIsNotAllowed);
61+
62+
if (!_isInitialized)
63+
throw new InvalidOperationException($"Plugin '{Metadata.Name}' v{Metadata.Version} is not initialized.");
64+
65+
var operationParameter = parameters.ToObject<OperationParameter>();
66+
var operation = operationParameter.Operation;
67+
68+
if (OperationMap.TryGetValue(operation, out var handler))
69+
{
70+
return handler(parameters, cancellationToken);
71+
}
72+
73+
throw new NotSupportedException($"CSV plugin: Operation '{operation}' is not supported.");
74+
}
75+
76+
private Dictionary<string, Func<PluginParameters, CancellationToken, Task<object?>>> OperationMap => new(StringComparer.OrdinalIgnoreCase)
77+
{
78+
["read"] = async (parameters, cancellationToken) => await _manager.Read(parameters, cancellationToken),
79+
["write"] = async (parameters, cancellationToken) => { await _manager.Write(parameters, cancellationToken); return null; },
80+
};
81+
82+
public IReadOnlyCollection<string> SupportedOperations => OperationMap.Keys;
83+
}

src/Extensions/StringExtensions.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Text;
2+
3+
namespace FlowSynx.Plugins.Csv.Extensions;
4+
5+
internal static class StringExtensions
6+
{
7+
public static bool IsBase64String(this string value)
8+
{
9+
if (string.IsNullOrEmpty(value) || value.Length % 4 != 0
10+
|| value.Contains(' ') || value.Contains('\t')
11+
|| value.Contains('\r') || value.Contains('\n'))
12+
return false;
13+
14+
var index = value.Length - 1;
15+
16+
if (value[index] == '=')
17+
index--;
18+
19+
if (value[index] == '=')
20+
index--;
21+
22+
for (var i = 0; i <= index; i++)
23+
if (IsInvalid(value[i]))
24+
return false;
25+
26+
return true;
27+
}
28+
29+
private static bool IsInvalid(char value)
30+
{
31+
var intValue = (int)value;
32+
switch (intValue)
33+
{
34+
case >= 48 and <= 57:
35+
case >= 65 and <= 90:
36+
case >= 97 and <= 122:
37+
return false;
38+
default:
39+
return intValue != 43 && intValue != 47;
40+
}
41+
}
42+
43+
public static byte[] ToByteArray(this string value)
44+
{
45+
return Encoding.UTF8.GetBytes(value);
46+
}
47+
48+
public static byte[] Base64ToByteArray(this string value)
49+
{
50+
return Convert.FromBase64String(value);
51+
}
52+
}

src/FlowSynx.Plugins.Csv.csproj

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
<PackageReference Include="CsvHelper" Version="33.1.0" />
11+
<PackageReference Include="FlowSynx.PluginCore" Version="1.2.7" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Compile Update="Resources.Designer.cs">
16+
<DesignTime>True</DesignTime>
17+
<AutoGen>True</AutoGen>
18+
<DependentUpon>Resources.resx</DependentUpon>
19+
</Compile>
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<EmbeddedResource Update="Resources.resx">
24+
<Generator>ResXFileCodeGenerator</Generator>
25+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
26+
</EmbeddedResource>
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<None Update="flowsynx.png">
31+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
32+
</None>
33+
<None Update="README.md">
34+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
35+
</None>
36+
</ItemGroup>
37+
38+
</Project>
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.Csv.Models;
4+
5+
public class CsvPluginSpecifications: PluginSpecifications
6+
{
7+
8+
}

src/Models/OperationParameter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace FlowSynx.Plugins.Csv.Models;
2+
3+
internal class OperationParameter
4+
{
5+
public string Operation { get; set; } = string.Empty;
6+
}

src/Models/ReadParameters.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace FlowSynx.Plugins.Csv.Models;
2+
3+
internal class ReadParameters
4+
{
5+
public string Path { get; set; } = string.Empty;
6+
public string? Delimiter { get; set; } = ",";
7+
public bool? HasHader { get; set; } = true;
8+
}

src/Models/WriteParameters.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace FlowSynx.Plugins.Csv.Models;
2+
3+
internal class WriteParameters
4+
{
5+
public string Path { get; set; } = string.Empty;
6+
public string? Delimiter { get; set; } = ",";
7+
public bool? WriteHader { get; set; } = true;
8+
public object? Data { get; set; }
9+
public bool Overwrite { get; set; } = false;
10+
}

0 commit comments

Comments
 (0)