Communication Layer (WP-1–5): - 8 message patterns with correlation IDs, per-pattern timeouts - Central/Site communication actors, transport heartbeat config - Connection failure handling (no central buffering, debug streams killed) Data Connection Layer (WP-6–14, WP-34): - Connection actor with Become/Stash lifecycle (Connecting/Connected/Reconnecting) - OPC UA + LmxProxy adapters behind IDataConnection - Auto-reconnect, bad quality propagation, transparent re-subscribe - Write-back, tag path resolution with retry, health reporting - Protocol extensibility via DataConnectionFactory Site Runtime (WP-15–25, WP-32–33): - ScriptActor/ScriptExecutionActor (triggers, concurrent execution, blocking I/O dispatcher) - AlarmActor/AlarmExecutionActor (ValueMatch/RangeViolation/RateOfChange, in-memory state) - SharedScriptLibrary (inline execution), ScriptRuntimeContext (API) - ScriptCompilationService (Roslyn, forbidden API enforcement, execution timeout) - Recursion limit (default 10), call direction enforcement - SiteStreamManager (per-subscriber bounded buffers, fire-and-forget) - Debug view backend (snapshot + stream), concurrency serialization - Local artifact storage (4 SQLite tables) Health Monitoring (WP-26–28): - SiteHealthCollector (thread-safe counters, connection state) - HealthReportSender (30s interval, monotonic sequence numbers) - CentralHealthAggregator (offline detection 60s, online recovery) Site Event Logging (WP-29–31): - SiteEventLogger (SQLite, 6 event categories, ISO 8601 UTC) - EventLogPurgeService (30-day retention, 1GB cap) - EventLogQueryService (filters, keyword search, keyset pagination) 541 tests pass, zero warnings.
121 lines
3.8 KiB
C#
121 lines
3.8 KiB
C#
namespace ScadaLink.DataConnectionLayer.Adapters;
|
|
|
|
/// <summary>
|
|
/// WP-8: Abstraction over the LmxProxy SDK client for testability.
|
|
/// The actual LmxProxyClient SDK lives in a separate repo; this interface
|
|
/// defines the contract the adapter depends on.
|
|
///
|
|
/// LmxProxy uses gRPC streaming for subscriptions and a session-based model
|
|
/// with keep-alive for connection management.
|
|
/// </summary>
|
|
public interface ILmxProxyClient : IAsyncDisposable
|
|
{
|
|
/// <summary>
|
|
/// Opens a session to the LmxProxy server. Returns a session ID.
|
|
/// </summary>
|
|
Task<string> OpenSessionAsync(string host, int port, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Closes the current session.
|
|
/// </summary>
|
|
Task CloseSessionAsync(CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Sends a keep-alive to maintain the session.
|
|
/// </summary>
|
|
Task SendKeepAliveAsync(CancellationToken cancellationToken = default);
|
|
|
|
bool IsConnected { get; }
|
|
string? SessionId { get; }
|
|
|
|
/// <summary>
|
|
/// Subscribes to tag value changes via gRPC streaming. Returns a subscription handle.
|
|
/// </summary>
|
|
Task<string> SubscribeTagAsync(
|
|
string tagPath,
|
|
Action<string, object?, DateTime, bool> onValueChanged,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
Task UnsubscribeTagAsync(string subscriptionHandle, CancellationToken cancellationToken = default);
|
|
|
|
Task<(object? Value, DateTime Timestamp, bool IsGood)> ReadTagAsync(
|
|
string tagPath, CancellationToken cancellationToken = default);
|
|
|
|
Task<bool> WriteTagAsync(string tagPath, object? value, CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Factory for creating ILmxProxyClient instances.
|
|
/// </summary>
|
|
public interface ILmxProxyClientFactory
|
|
{
|
|
ILmxProxyClient Create();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Default factory that creates stub LmxProxy clients.
|
|
/// In production, this would create real LmxProxy SDK client instances.
|
|
/// </summary>
|
|
public class DefaultLmxProxyClientFactory : ILmxProxyClientFactory
|
|
{
|
|
public ILmxProxyClient Create() => new StubLmxProxyClient();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stub LmxProxy client for development/testing.
|
|
/// </summary>
|
|
internal class StubLmxProxyClient : ILmxProxyClient
|
|
{
|
|
public bool IsConnected { get; private set; }
|
|
public string? SessionId { get; private set; }
|
|
|
|
public Task<string> OpenSessionAsync(string host, int port, CancellationToken cancellationToken = default)
|
|
{
|
|
SessionId = Guid.NewGuid().ToString();
|
|
IsConnected = true;
|
|
return Task.FromResult(SessionId);
|
|
}
|
|
|
|
public Task CloseSessionAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
IsConnected = false;
|
|
SessionId = null;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task SendKeepAliveAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task<string> SubscribeTagAsync(
|
|
string tagPath, Action<string, object?, DateTime, bool> onValueChanged,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.FromResult(Guid.NewGuid().ToString());
|
|
}
|
|
|
|
public Task UnsubscribeTagAsync(string subscriptionHandle, CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task<(object? Value, DateTime Timestamp, bool IsGood)> ReadTagAsync(
|
|
string tagPath, CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.FromResult<(object?, DateTime, bool)>((null, DateTime.UtcNow, true));
|
|
}
|
|
|
|
public Task<bool> WriteTagAsync(string tagPath, object? value, CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.FromResult(true);
|
|
}
|
|
|
|
public ValueTask DisposeAsync()
|
|
{
|
|
IsConnected = false;
|
|
SessionId = null;
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
}
|