Skip to content

Commit 1e8ecb2

Browse files
committed
Add CompanyName property and other properties to make a reach plugin with more metadata as well as add comments for all classes and intetfaces
#9
1 parent 628a2bd commit 1e8ecb2

14 files changed

Lines changed: 408 additions & 69 deletions
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
11
namespace FlowSynx.PluginCore.Exceptions;
22

3+
/// <summary>
4+
/// Represents a structured error message with a numeric code and descriptive text.
5+
/// </summary>
36
public class ErrorMessage
47
{
8+
/// <summary>
9+
/// The prefix used in the formatted error message, typically identifying the system (e.g., "FSX" for FlowSynX).
10+
/// </summary>
511
private const string PrefixErrorMessage = "FSX"; // Abbreviation for FlowSynX
612

13+
/// <summary>
14+
/// Gets the numeric error code associated with the error.
15+
/// </summary>
716
public int Code { get; }
17+
18+
/// <summary>
19+
/// Gets the descriptive message explaining the error.
20+
/// </summary>
821
public string Message { get; }
922

23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="ErrorMessage"/> class with the specified code and message.
25+
/// </summary>
26+
/// <param name="code">The unique error code.</param>
27+
/// <param name="message">A human-readable message describing the error.</param>
1028
public ErrorMessage(int code, string message)
1129
{
1230
Code = code;
1331
Message = message;
1432
}
1533

34+
/// <summary>
35+
/// Returns a formatted string representation of the error message.
36+
/// </summary>
37+
/// <returns>A string in the format "[FSX{Code}] {Message}".</returns>
1638
public override string ToString() => $"[{PrefixErrorMessage}{Code}] {Message}";
17-
}
39+
}
Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,56 @@
11
namespace FlowSynx.PluginCore.Exceptions;
22

3+
/// <summary>
4+
/// Represents errors that occur during FlowSynX operations and includes an error code and message.
5+
/// </summary>
36
public class FlowSynxException : Exception
47
{
8+
/// <summary>
9+
/// Gets the custom error code associated with this exception.
10+
/// </summary>
511
public int ErrorCode { get; }
12+
13+
/// <summary>
14+
/// Gets the human-readable error message associated with this exception.
15+
/// </summary>
616
public string ErrorMessage { get; }
717

18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="FlowSynxException"/> class using an <see cref="ErrorMessage"/> object.
20+
/// </summary>
21+
/// <param name="errorMessage">The structured error message object containing the code and message.</param>
822
public FlowSynxException(ErrorMessage errorMessage) : this(errorMessage.Code, errorMessage.Message)
923
{
10-
1124
}
1225

13-
public FlowSynxException(int errorCode, string errorMessage) : base(errorMessage)
26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="FlowSynxException"/> class with a specified error code and message.
28+
/// </summary>
29+
/// <param name="errorCode">The custom error code.</param>
30+
/// <param name="errorMessage">The human-readable error message.</param>
31+
public FlowSynxException(int errorCode, string errorMessage)
32+
: base(errorMessage)
1433
{
1534
ErrorCode = errorCode;
1635
ErrorMessage = errorMessage;
1736
}
1837

19-
public FlowSynxException(int errorCode, string errorMessage, Exception innerException) : base(errorMessage, innerException)
38+
/// <summary>
39+
/// Initializes a new instance of the <see cref="FlowSynxException"/> class with a specified error code, message, and inner exception.
40+
/// </summary>
41+
/// <param name="errorCode">The custom error code.</param>
42+
/// <param name="errorMessage">The human-readable error message.</param>
43+
/// <param name="innerException">The exception that is the cause of this exception.</param>
44+
public FlowSynxException(int errorCode, string errorMessage, Exception innerException)
45+
: base(errorMessage, innerException)
2046
{
2147
ErrorCode = errorCode;
2248
ErrorMessage = errorMessage;
2349
}
2450

51+
/// <summary>
52+
/// Returns a formatted string representation of the exception, including the prefixed error code and message.
53+
/// </summary>
54+
/// <returns>A string in the format "[FSX{Code}] {Message}".</returns>
2555
public override string ToString() => new ErrorMessage(ErrorCode, ErrorMessage).ToString();
2656
}

src/FlowSynx.PluginCore/Extensions/PluginLoggerExtensions.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
namespace FlowSynx.PluginCore.Extensions;
22

3+
/// <summary>
4+
/// Provides extension methods for simplified logging using <see cref="IPluginLogger"/>.
5+
/// </summary>
36
public static class PluginLoggerExtensions
47
{
8+
/// <summary>
9+
/// Logs an informational message using the <see cref="PluginLoggerLevel.Information"/> level.
10+
/// </summary>
11+
/// <param name="logger">The logger to write to.</param>
12+
/// <param name="message">The message to log.</param>
513
public static void LogInfo(this IPluginLogger logger, string message)
614
{
715
logger.Log(PluginLoggerLevel.Information, message);
816
}
917

18+
/// <summary>
19+
/// Logs an error message using the <see cref="PluginLoggerLevel.Error"/> level.
20+
/// </summary>
21+
/// <param name="logger">The logger to write to.</param>
22+
/// <param name="message">The message to log.</param>
1023
public static void LogError(this IPluginLogger logger, string message)
1124
{
1225
logger.Log(PluginLoggerLevel.Error, message);
1326
}
1427

28+
/// <summary>
29+
/// Logs a debug message using the <see cref="PluginLoggerLevel.Debug"/> level.
30+
/// </summary>
31+
/// <param name="logger">The logger to write to.</param>
32+
/// <param name="message">The message to log.</param>
1533
public static void LogDebug(this IPluginLogger logger, string message)
1634
{
1735
logger.Log(PluginLoggerLevel.Debug, message);
1836
}
1937

38+
/// <summary>
39+
/// Logs a warning message using the <see cref="PluginLoggerLevel.Warning"/> level.
40+
/// </summary>
41+
/// <param name="logger">The logger to write to.</param>
42+
/// <param name="message">The message to log.</param>
2043
public static void LogWarning(this IPluginLogger logger, string message)
2144
{
2245
logger.Log(PluginLoggerLevel.Warning, message);

src/FlowSynx.PluginCore/IPlugin.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
11
namespace FlowSynx.PluginCore;
22

3+
/// <summary>
4+
/// Represents a plugin with metadata, specifications, and execution capabilities.
5+
/// </summary>
36
public interface IPlugin
47
{
8+
/// <summary>
9+
/// Gets the metadata describing the plugin, including its name, version, author, and other identifying information.
10+
/// </summary>
511
PluginMetadata Metadata { get; }
12+
13+
/// <summary>
14+
/// Gets or sets the plugin-specific configuration or specifications used during execution.
15+
/// </summary>
616
PluginSpecifications? Specifications { get; set; }
17+
18+
/// <summary>
19+
/// Gets the <see cref="Type"/> of the <see cref="Specifications"/> object.
20+
/// Useful for deserialization or dynamic creation of the specification instance.
21+
/// </summary>
722
Type SpecificationsType { get; }
23+
24+
/// <summary>
25+
/// Initializes the plugin with the provided logger. This method is called once before execution.
26+
/// </summary>
27+
/// <param name="logger">The logger to be used by the plugin for diagnostics and tracing.</param>
28+
/// <returns>A task representing the asynchronous initialization operation.</returns>
829
Task Initialize(IPluginLogger logger);
30+
31+
/// <summary>
32+
/// Executes the plugin asynchronously with the provided parameters.
33+
/// </summary>
34+
/// <param name="parameters">The input parameters required for plugin execution.</param>
35+
/// <param name="cancellationToken">A token to observe for cancellation requests.</param>
36+
/// <returns>A task that represents the asynchronous operation, containing an optional result object.</returns>
937
Task<object?> ExecuteAsync(PluginParameters parameters, CancellationToken cancellationToken);
10-
}
38+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
namespace FlowSynx.PluginCore;
22

3+
/// <summary>
4+
/// Defines a logging interface for plugins to emit messages with various log levels.
5+
/// </summary>
36
public interface IPluginLogger
47
{
8+
/// <summary>
9+
/// Logs a message with the specified severity level.
10+
/// </summary>
11+
/// <param name="level">The severity level of the log message (e.g., Debug, Info, Warning, Error).</param>
12+
/// <param name="message">The log message to record.</param>
513
void Log(PluginLoggerLevel level, string message);
614
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
namespace FlowSynx.PluginCore;
22

3+
/// <summary>
4+
/// Specifies the severity level of a log message emitted by a plugin.
5+
/// </summary>
36
public enum PluginLoggerLevel
47
{
8+
/// <summary>
9+
/// Debug-level messages used for development and diagnostic purposes.
10+
/// Typically only enabled in development environments.
11+
/// </summary>
512
Debug = 0,
13+
14+
/// <summary>
15+
/// Informational messages that highlight the progress or state of the plugin at a high level.
16+
/// </summary>
617
Information,
18+
19+
/// <summary>
20+
/// Warning messages that indicate a potential issue or important situation that does not prevent execution.
21+
/// </summary>
722
Warning,
23+
24+
/// <summary>
25+
/// Error messages that indicate a failure or problem that has impacted or halted execution.
26+
/// </summary>
827
Error
928
}
Lines changed: 121 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,130 @@
1-
namespace FlowSynx.PluginCore;
1+
using System.Text.RegularExpressions;
22

3+
namespace FlowSynx.PluginCore;
4+
5+
/// <summary>
6+
/// Represents metadata information about a plugin including its identity, version,
7+
/// company, descriptive details, and repository information.
8+
/// Constructs a fully-qualified plugin type identifier based on the company name, namespace, and plugin name.
9+
/// </summary>
310
public class PluginMetadata
411
{
5-
private const string PrefixTypeName = "FlowSynx";
12+
private string _companyName = default!;
13+
private string _name = default!;
14+
15+
/// <summary>
16+
/// A regular expression to validate identifiers.
17+
/// Identifiers must start with a letter and contain only letters and digits.
18+
/// </summary>
19+
private static readonly Regex ValidIdentifierRegex = new(@"^[A-Za-z][A-Za-z0-9]*$", RegexOptions.Compiled);
620

21+
/// <summary>
22+
/// Gets or sets the unique identifier of the plugin.
23+
/// </summary>
724
public required Guid Id { get; set; }
8-
public required string Name { get; set; }
25+
26+
/// <summary>
27+
/// Gets or sets the name of the plugin.
28+
/// The name must start with a letter and contain only letters and digits.
29+
/// </summary>
30+
public required string Name
31+
{
32+
get => _name;
33+
set => _name = ValidateIdentifier(value, nameof(Name));
34+
}
35+
36+
/// <summary>
37+
/// Gets or sets the version of the plugin.
38+
/// </summary>
939
public required PluginVersion Version { get; set; }
40+
41+
/// <summary>
42+
/// Gets or sets the name of the company that created the plugin.
43+
/// The name must start with a letter and contain only letters and digits.
44+
/// </summary>
45+
public required string CompanyName
46+
{
47+
get => _companyName;
48+
set => _companyName = ValidateIdentifier(value, nameof(CompanyName));
49+
}
50+
51+
/// <summary>
52+
/// Gets or sets an optional description of the plugin.
53+
/// </summary>
1054
public string? Description { get; set; }
11-
public string? Author { get; set; }
12-
public string? Url { get; set; }
55+
56+
/// <summary>
57+
/// Gets or sets the list of authors or maintainers of the plugin.
58+
/// </summary>
59+
public List<string> Authors { get; set; } = new List<string>();
60+
61+
/// <summary>
62+
/// Gets or sets the license name under which the plugin is distributed.
63+
/// </summary>
64+
public string? License { get; set; }
65+
66+
/// <summary>
67+
/// Gets or sets the URL to the license text or license information.
68+
/// </summary>
69+
public string? LicenseUrl { get; set; }
70+
71+
/// <summary>
72+
/// Gets or sets the relative or absolute path/URL to the plugin icon.
73+
/// </summary>
74+
public string? Icon { get; set; }
75+
76+
/// <summary>
77+
/// Gets or sets the URL to the project or documentation related to the plugin.
78+
/// </summary>
79+
public string? ProjectUrl { get; set; }
80+
81+
/// <summary>
82+
/// Gets or sets the copyright notice for the plugin.
83+
/// </summary>
84+
public string? Copyright { get; set; }
85+
86+
/// <summary>
87+
/// Gets or sets a simicolon-delimited list of tags used to categorize or describe the plugin.
88+
/// Useful for search and filtering.
89+
/// </summary>
90+
public List<string> Tags { get; set; } = new List<string>();
91+
92+
/// <summary>
93+
/// Gets or sets the URL to the source code repository of the plugin.
94+
/// </summary>
95+
public string? RepositoryUrl { get; set; }
96+
97+
/// <summary>
98+
/// Gets or sets the namespace the plugin belongs to.
99+
/// Used as the middle component in the plugin's type identifier.
100+
/// </summary>
13101
public required PluginNamespace Namespace { get; set; }
14-
public string Type => $"{PrefixTypeName}.{Namespace}.{Name}";
102+
103+
/// <summary>
104+
/// Gets the full plugin type name in the format: CompanyName.Namespace.PluginName.
105+
/// This is used for plugin resolution, identification, or registration.
106+
/// </summary>
107+
public string Type => $"{CompanyName}.{Namespace}.{Name}";
108+
109+
/// <summary>
110+
/// Validates that an identifier is non-empty, starts with a letter,
111+
/// and contains only letters and digits.
112+
/// </summary>
113+
/// <param name="input">The string to validate.</param>
114+
/// <param name="fieldName">The name of the field being validated, used in the error message.</param>
115+
/// <returns>The validated input string.</returns>
116+
/// <exception cref="ArgumentException">
117+
/// Thrown if the input is null, whitespace, or contains invalid characters.
118+
/// </exception>
119+
private static string ValidateIdentifier(string input, string fieldName)
120+
{
121+
if (string.IsNullOrWhiteSpace(input))
122+
throw new ArgumentException($"{fieldName} cannot be null or whitespace.");
123+
124+
if (!ValidIdentifierRegex.IsMatch(input))
125+
throw new ArgumentException($"{fieldName} must start with a letter and contain only letters and " +
126+
$"digits (no underscores, spaces, or symbols).");
127+
128+
return input;
129+
}
15130
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
namespace FlowSynx.PluginCore;
22

3+
/// <summary>
4+
/// Defines the logical categorization or role of a plugin within the system.
5+
/// </summary>
36
public enum PluginNamespace
47
{
8+
/// <summary>
9+
/// Represents plugins that contain core business logic or decision-making rules.
10+
/// </summary>
511
Logics,
12+
13+
/// <summary>
14+
/// Represents plugins that connect to external systems, services, or data sources.
15+
/// </summary>
616
Connectors,
17+
18+
/// <summary>
19+
/// Represents plugins that modify, transform, or enrich data as it flows through the system.
20+
/// </summary>
721
Transformers
822
}

0 commit comments

Comments
 (0)