Phase 0 WP-0.2–0.9: Implement Commons (types, entities, interfaces, messages, protocol, tests)
- WP-0.2: Namespace/folder skeleton (26 directories) - WP-0.3: Shared data types (6 enums, RetryPolicy, Result<T>) - WP-0.4: 24 domain entity POCOs across 10 domain areas - WP-0.5: 7 repository interfaces with full CRUD signatures - WP-0.6: IAuditService cross-cutting interface - WP-0.7: 26 message contract records across 8 concern areas - WP-0.8: IDataConnection protocol abstraction with batch ops - WP-0.9: 8 architectural constraint enforcement tests All 40 tests pass, zero warnings.
This commit is contained in:
22
src/ScadaLink.Commons/Entities/Audit/AuditLogEntry.cs
Normal file
22
src/ScadaLink.Commons/Entities/Audit/AuditLogEntry.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace ScadaLink.Commons.Entities.Audit;
|
||||
|
||||
public class AuditLogEntry
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string User { get; set; }
|
||||
public string Action { get; set; }
|
||||
public string EntityType { get; set; }
|
||||
public string EntityId { get; set; }
|
||||
public string EntityName { get; set; }
|
||||
public string? AfterStateJson { get; set; }
|
||||
public DateTimeOffset Timestamp { get; set; }
|
||||
|
||||
public AuditLogEntry(string user, string action, string entityType, string entityId, string entityName)
|
||||
{
|
||||
User = user ?? throw new ArgumentNullException(nameof(user));
|
||||
Action = action ?? throw new ArgumentNullException(nameof(action));
|
||||
EntityType = entityType ?? throw new ArgumentNullException(nameof(entityType));
|
||||
EntityId = entityId ?? throw new ArgumentNullException(nameof(entityId));
|
||||
EntityName = entityName ?? throw new ArgumentNullException(nameof(entityName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using ScadaLink.Commons.Types.Enums;
|
||||
|
||||
namespace ScadaLink.Commons.Entities.Deployment;
|
||||
|
||||
public class DeploymentRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int InstanceId { get; set; }
|
||||
public DeploymentStatus Status { get; set; }
|
||||
public string DeploymentId { get; set; }
|
||||
public string? RevisionHash { get; set; }
|
||||
public string DeployedBy { get; set; }
|
||||
public DateTimeOffset DeployedAt { get; set; }
|
||||
public DateTimeOffset? CompletedAt { get; set; }
|
||||
|
||||
public DeploymentRecord(string deploymentId, string deployedBy)
|
||||
{
|
||||
DeploymentId = deploymentId ?? throw new ArgumentNullException(nameof(deploymentId));
|
||||
DeployedBy = deployedBy ?? throw new ArgumentNullException(nameof(deployedBy));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace ScadaLink.Commons.Entities.Deployment;
|
||||
|
||||
public class SystemArtifactDeploymentRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ArtifactType { get; set; }
|
||||
public string DeployedBy { get; set; }
|
||||
public DateTimeOffset DeployedAt { get; set; }
|
||||
public string? PerSiteStatus { get; set; }
|
||||
|
||||
public SystemArtifactDeploymentRecord(string artifactType, string deployedBy)
|
||||
{
|
||||
ArtifactType = artifactType ?? throw new ArgumentNullException(nameof(artifactType));
|
||||
DeployedBy = deployedBy ?? throw new ArgumentNullException(nameof(deployedBy));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace ScadaLink.Commons.Entities.ExternalSystems;
|
||||
|
||||
public class DatabaseConnectionDefinition
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ConnectionString { get; set; }
|
||||
public int MaxRetries { get; set; }
|
||||
public TimeSpan RetryDelay { get; set; }
|
||||
|
||||
public DatabaseConnectionDefinition(string name, string connectionString)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
ConnectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace ScadaLink.Commons.Entities.ExternalSystems;
|
||||
|
||||
public class ExternalSystemDefinition
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string EndpointUrl { get; set; }
|
||||
public string AuthType { get; set; }
|
||||
public string? AuthConfiguration { get; set; }
|
||||
public int MaxRetries { get; set; }
|
||||
public TimeSpan RetryDelay { get; set; }
|
||||
|
||||
public ExternalSystemDefinition(string name, string endpointUrl, string authType)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
EndpointUrl = endpointUrl ?? throw new ArgumentNullException(nameof(endpointUrl));
|
||||
AuthType = authType ?? throw new ArgumentNullException(nameof(authType));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace ScadaLink.Commons.Entities.ExternalSystems;
|
||||
|
||||
public class ExternalSystemMethod
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ExternalSystemDefinitionId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string HttpMethod { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string? ParameterDefinitions { get; set; }
|
||||
public string? ReturnDefinition { get; set; }
|
||||
|
||||
public ExternalSystemMethod(string name, string httpMethod, string path)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
HttpMethod = httpMethod ?? throw new ArgumentNullException(nameof(httpMethod));
|
||||
Path = path ?? throw new ArgumentNullException(nameof(path));
|
||||
}
|
||||
}
|
||||
15
src/ScadaLink.Commons/Entities/InboundApi/ApiKey.cs
Normal file
15
src/ScadaLink.Commons/Entities/InboundApi/ApiKey.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace ScadaLink.Commons.Entities.InboundApi;
|
||||
|
||||
public class ApiKey
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string KeyValue { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
public ApiKey(string name, string keyValue)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
KeyValue = keyValue ?? throw new ArgumentNullException(nameof(keyValue));
|
||||
}
|
||||
}
|
||||
18
src/ScadaLink.Commons/Entities/InboundApi/ApiMethod.cs
Normal file
18
src/ScadaLink.Commons/Entities/InboundApi/ApiMethod.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace ScadaLink.Commons.Entities.InboundApi;
|
||||
|
||||
public class ApiMethod
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Script { get; set; }
|
||||
public string? ApprovedApiKeyIds { get; set; }
|
||||
public string? ParameterDefinitions { get; set; }
|
||||
public string? ReturnDefinition { get; set; }
|
||||
public int TimeoutSeconds { get; set; }
|
||||
|
||||
public ApiMethod(string name, string script)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
Script = script ?? throw new ArgumentNullException(nameof(script));
|
||||
}
|
||||
}
|
||||
15
src/ScadaLink.Commons/Entities/Instances/Area.cs
Normal file
15
src/ScadaLink.Commons/Entities/Instances/Area.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace ScadaLink.Commons.Entities.Instances;
|
||||
|
||||
public class Area
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int SiteId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int? ParentAreaId { get; set; }
|
||||
public ICollection<Area> Children { get; set; } = new List<Area>();
|
||||
|
||||
public Area(string name)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
}
|
||||
20
src/ScadaLink.Commons/Entities/Instances/Instance.cs
Normal file
20
src/ScadaLink.Commons/Entities/Instances/Instance.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using ScadaLink.Commons.Types.Enums;
|
||||
|
||||
namespace ScadaLink.Commons.Entities.Instances;
|
||||
|
||||
public class Instance
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int TemplateId { get; set; }
|
||||
public int SiteId { get; set; }
|
||||
public int? AreaId { get; set; }
|
||||
public string UniqueName { get; set; }
|
||||
public InstanceState State { get; set; }
|
||||
public ICollection<InstanceAttributeOverride> AttributeOverrides { get; set; } = new List<InstanceAttributeOverride>();
|
||||
public ICollection<InstanceConnectionBinding> ConnectionBindings { get; set; } = new List<InstanceConnectionBinding>();
|
||||
|
||||
public Instance(string uniqueName)
|
||||
{
|
||||
UniqueName = uniqueName ?? throw new ArgumentNullException(nameof(uniqueName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace ScadaLink.Commons.Entities.Instances;
|
||||
|
||||
public class InstanceAttributeOverride
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int InstanceId { get; set; }
|
||||
public string AttributeName { get; set; }
|
||||
public string? OverrideValue { get; set; }
|
||||
|
||||
public InstanceAttributeOverride(string attributeName)
|
||||
{
|
||||
AttributeName = attributeName ?? throw new ArgumentNullException(nameof(attributeName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace ScadaLink.Commons.Entities.Instances;
|
||||
|
||||
public class InstanceConnectionBinding
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int InstanceId { get; set; }
|
||||
public string AttributeName { get; set; }
|
||||
public int DataConnectionId { get; set; }
|
||||
|
||||
public InstanceConnectionBinding(string attributeName)
|
||||
{
|
||||
AttributeName = attributeName ?? throw new ArgumentNullException(nameof(attributeName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace ScadaLink.Commons.Entities.Notifications;
|
||||
|
||||
public class NotificationList
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public ICollection<NotificationRecipient> Recipients { get; set; } = new List<NotificationRecipient>();
|
||||
|
||||
public NotificationList(string name)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace ScadaLink.Commons.Entities.Notifications;
|
||||
|
||||
public class NotificationRecipient
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int NotificationListId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string EmailAddress { get; set; }
|
||||
|
||||
public NotificationRecipient(string name, string emailAddress)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
EmailAddress = emailAddress ?? throw new ArgumentNullException(nameof(emailAddress));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace ScadaLink.Commons.Entities.Notifications;
|
||||
|
||||
public class SmtpConfiguration
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string AuthType { get; set; }
|
||||
public string? Credentials { get; set; }
|
||||
public string? TlsMode { get; set; }
|
||||
public string FromAddress { get; set; }
|
||||
public int ConnectionTimeoutSeconds { get; set; }
|
||||
public int MaxConcurrentConnections { get; set; }
|
||||
public int MaxRetries { get; set; }
|
||||
public TimeSpan RetryDelay { get; set; }
|
||||
|
||||
public SmtpConfiguration(string host, string authType, string fromAddress)
|
||||
{
|
||||
Host = host ?? throw new ArgumentNullException(nameof(host));
|
||||
AuthType = authType ?? throw new ArgumentNullException(nameof(authType));
|
||||
FromAddress = fromAddress ?? throw new ArgumentNullException(nameof(fromAddress));
|
||||
}
|
||||
}
|
||||
16
src/ScadaLink.Commons/Entities/Scripts/SharedScript.cs
Normal file
16
src/ScadaLink.Commons/Entities/Scripts/SharedScript.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace ScadaLink.Commons.Entities.Scripts;
|
||||
|
||||
public class SharedScript
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Code { get; set; }
|
||||
public string? ParameterDefinitions { get; set; }
|
||||
public string? ReturnDefinition { get; set; }
|
||||
|
||||
public SharedScript(string name, string code)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
Code = code ?? throw new ArgumentNullException(nameof(code));
|
||||
}
|
||||
}
|
||||
14
src/ScadaLink.Commons/Entities/Security/LdapGroupMapping.cs
Normal file
14
src/ScadaLink.Commons/Entities/Security/LdapGroupMapping.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace ScadaLink.Commons.Entities.Security;
|
||||
|
||||
public class LdapGroupMapping
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string LdapGroupName { get; set; }
|
||||
public string Role { get; set; }
|
||||
|
||||
public LdapGroupMapping(string ldapGroupName, string role)
|
||||
{
|
||||
LdapGroupName = ldapGroupName ?? throw new ArgumentNullException(nameof(ldapGroupName));
|
||||
Role = role ?? throw new ArgumentNullException(nameof(role));
|
||||
}
|
||||
}
|
||||
8
src/ScadaLink.Commons/Entities/Security/SiteScopeRule.cs
Normal file
8
src/ScadaLink.Commons/Entities/Security/SiteScopeRule.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace ScadaLink.Commons.Entities.Security;
|
||||
|
||||
public class SiteScopeRule
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int LdapGroupMappingId { get; set; }
|
||||
public int SiteId { get; set; }
|
||||
}
|
||||
15
src/ScadaLink.Commons/Entities/Sites/DataConnection.cs
Normal file
15
src/ScadaLink.Commons/Entities/Sites/DataConnection.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace ScadaLink.Commons.Entities.Sites;
|
||||
|
||||
public class DataConnection
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Protocol { get; set; }
|
||||
public string? Configuration { get; set; }
|
||||
|
||||
public DataConnection(string name, string protocol)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
Protocol = protocol ?? throw new ArgumentNullException(nameof(protocol));
|
||||
}
|
||||
}
|
||||
15
src/ScadaLink.Commons/Entities/Sites/Site.cs
Normal file
15
src/ScadaLink.Commons/Entities/Sites/Site.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace ScadaLink.Commons.Entities.Sites;
|
||||
|
||||
public class Site
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string SiteIdentifier { get; set; }
|
||||
public string? Description { get; set; }
|
||||
|
||||
public Site(string name, string siteIdentifier)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
SiteIdentifier = siteIdentifier ?? throw new ArgumentNullException(nameof(siteIdentifier));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace ScadaLink.Commons.Entities.Sites;
|
||||
|
||||
public class SiteDataConnectionAssignment
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int SiteId { get; set; }
|
||||
public int DataConnectionId { get; set; }
|
||||
}
|
||||
18
src/ScadaLink.Commons/Entities/Templates/Template.cs
Normal file
18
src/ScadaLink.Commons/Entities/Templates/Template.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace ScadaLink.Commons.Entities.Templates;
|
||||
|
||||
public class Template
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public int? ParentTemplateId { get; set; }
|
||||
public ICollection<TemplateAttribute> Attributes { get; set; } = new List<TemplateAttribute>();
|
||||
public ICollection<TemplateAlarm> Alarms { get; set; } = new List<TemplateAlarm>();
|
||||
public ICollection<TemplateScript> Scripts { get; set; } = new List<TemplateScript>();
|
||||
public ICollection<TemplateComposition> Compositions { get; set; } = new List<TemplateComposition>();
|
||||
|
||||
public Template(string name)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
}
|
||||
21
src/ScadaLink.Commons/Entities/Templates/TemplateAlarm.cs
Normal file
21
src/ScadaLink.Commons/Entities/Templates/TemplateAlarm.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using ScadaLink.Commons.Types.Enums;
|
||||
|
||||
namespace ScadaLink.Commons.Entities.Templates;
|
||||
|
||||
public class TemplateAlarm
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int TemplateId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public int PriorityLevel { get; set; }
|
||||
public bool IsLocked { get; set; }
|
||||
public AlarmTriggerType TriggerType { get; set; }
|
||||
public string? TriggerConfiguration { get; set; }
|
||||
public int? OnTriggerScriptId { get; set; }
|
||||
|
||||
public TemplateAlarm(string name)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using ScadaLink.Commons.Types.Enums;
|
||||
|
||||
namespace ScadaLink.Commons.Entities.Templates;
|
||||
|
||||
public class TemplateAttribute
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int TemplateId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Value { get; set; }
|
||||
public DataType DataType { get; set; }
|
||||
public bool IsLocked { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? DataSourceReference { get; set; }
|
||||
|
||||
public TemplateAttribute(string name)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace ScadaLink.Commons.Entities.Templates;
|
||||
|
||||
public class TemplateComposition
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int TemplateId { get; set; }
|
||||
public int ComposedTemplateId { get; set; }
|
||||
public string InstanceName { get; set; }
|
||||
|
||||
public TemplateComposition(string instanceName)
|
||||
{
|
||||
InstanceName = instanceName ?? throw new ArgumentNullException(nameof(instanceName));
|
||||
}
|
||||
}
|
||||
21
src/ScadaLink.Commons/Entities/Templates/TemplateScript.cs
Normal file
21
src/ScadaLink.Commons/Entities/Templates/TemplateScript.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace ScadaLink.Commons.Entities.Templates;
|
||||
|
||||
public class TemplateScript
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int TemplateId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool IsLocked { get; set; }
|
||||
public string Code { get; set; }
|
||||
public string? TriggerType { get; set; }
|
||||
public string? TriggerConfiguration { get; set; }
|
||||
public string? ParameterDefinitions { get; set; }
|
||||
public string? ReturnDefinition { get; set; }
|
||||
public TimeSpan? MinTimeBetweenRuns { get; set; }
|
||||
|
||||
public TemplateScript(string name, string code)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
Code = code ?? throw new ArgumentNullException(nameof(code));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user