refactor(site-runtime): route OPC UA connection JSON through serializer
This commit is contained in:
@@ -405,8 +405,7 @@ public class DeploymentManagerActor : ReceiveActor, IWithTimers
|
|||||||
private readonly HashSet<string> _createdConnections = new();
|
private readonly HashSet<string> _createdConnections = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses the flattened config to find bound data connections and ensures
|
/// Sets up DCL connections from the flattened config (idempotent: tracks created connections).
|
||||||
/// the DCL Manager has corresponding connection actors created.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void EnsureDclConnections(string configJson)
|
private void EnsureDclConnections(string configJson)
|
||||||
{
|
{
|
||||||
@@ -422,35 +421,10 @@ public class DeploymentManagerActor : ReceiveActor, IWithTimers
|
|||||||
if (_createdConnections.Contains(name))
|
if (_createdConnections.Contains(name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var primaryDetails = new Dictionary<string, string>();
|
var primaryDetails = FlattenConnectionConfig(connConfig.Protocol, connConfig.ConfigurationJson);
|
||||||
if (!string.IsNullOrEmpty(connConfig.ConfigurationJson))
|
var backupDetails = string.IsNullOrEmpty(connConfig.BackupConfigurationJson)
|
||||||
{
|
? null
|
||||||
try
|
: FlattenConnectionConfig(connConfig.Protocol, connConfig.BackupConfigurationJson);
|
||||||
{
|
|
||||||
// Parse as JsonElement to handle mixed value types (string, int, bool)
|
|
||||||
using var doc = System.Text.Json.JsonDocument.Parse(connConfig.ConfigurationJson);
|
|
||||||
foreach (var prop in doc.RootElement.EnumerateObject())
|
|
||||||
{
|
|
||||||
primaryDetails[prop.Name] = prop.Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch { /* Ignore parse errors */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
Dictionary<string, string>? backupDetails = null;
|
|
||||||
if (!string.IsNullOrEmpty(connConfig.BackupConfigurationJson))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
backupDetails = new Dictionary<string, string>();
|
|
||||||
using var doc = System.Text.Json.JsonDocument.Parse(connConfig.BackupConfigurationJson);
|
|
||||||
foreach (var prop in doc.RootElement.EnumerateObject())
|
|
||||||
{
|
|
||||||
backupDetails[prop.Name] = prop.Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch { backupDetails = null; /* Ignore parse errors */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
_dclManager.Tell(new Commons.Messages.DataConnection.CreateConnectionCommand(
|
_dclManager.Tell(new Commons.Messages.DataConnection.CreateConnectionCommand(
|
||||||
name, connConfig.Protocol, primaryDetails, backupDetails, connConfig.FailoverRetryCount));
|
name, connConfig.Protocol, primaryDetails, backupDetails, connConfig.FailoverRetryCount));
|
||||||
@@ -467,6 +441,32 @@ public class DeploymentManagerActor : ReceiveActor, IWithTimers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IDictionary<string, string> FlattenConnectionConfig(string protocol, string? json)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(json))
|
||||||
|
return new Dictionary<string, string>();
|
||||||
|
|
||||||
|
if (string.Equals(protocol, "OpcUa", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
var (config, _) = Commons.Serialization.OpcUaEndpointConfigSerializer.Deserialize(json);
|
||||||
|
return Commons.Serialization.OpcUaEndpointConfigSerializer.ToFlatDict(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: assume legacy flat-dict shape for any future / unknown protocol.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var dict = new Dictionary<string, string>();
|
||||||
|
using var doc = System.Text.Json.JsonDocument.Parse(json);
|
||||||
|
foreach (var prop in doc.RootElement.EnumerateObject())
|
||||||
|
dict[prop.Name] = prop.Value.ToString();
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return new Dictionary<string, string>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Shared Script Loading ──
|
// ── Shared Script Loading ──
|
||||||
|
|
||||||
private void LoadSharedScriptsFromStorage()
|
private void LoadSharedScriptsFromStorage()
|
||||||
|
|||||||
Reference in New Issue
Block a user