48bd266e19
Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using Opc.Ua;
|
|
using Opc.Ua.Client;
|
|
using Serilog;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Client.Shared.Adapters;
|
|
|
|
/// <summary>
|
|
/// Production session factory that creates real OPC UA sessions.
|
|
/// </summary>
|
|
internal sealed class DefaultSessionFactory : ISessionFactory
|
|
{
|
|
private static readonly ILogger Logger = Log.ForContext<DefaultSessionFactory>();
|
|
|
|
/// <inheritdoc />
|
|
public async Task<ISessionAdapter> CreateSessionAsync(
|
|
ApplicationConfiguration config,
|
|
EndpointDescription endpoint,
|
|
string sessionName,
|
|
uint sessionTimeoutMs,
|
|
UserIdentity identity,
|
|
CancellationToken ct)
|
|
{
|
|
var endpointConfig = EndpointConfiguration.Create(config);
|
|
var configuredEndpoint = new ConfiguredEndpoint(null, endpoint, endpointConfig);
|
|
|
|
var created = await new Opc.Ua.Client.DefaultSessionFactory(ClientTelemetry.Context).CreateAsync(
|
|
config,
|
|
configuredEndpoint,
|
|
false,
|
|
sessionName,
|
|
sessionTimeoutMs,
|
|
identity,
|
|
null,
|
|
ct);
|
|
var session = created as Session
|
|
?? throw new InvalidOperationException(
|
|
$"Session factory returned {created.GetType().Name}, expected {nameof(Session)}.");
|
|
|
|
Logger.Information("Session created: {SessionName} -> {EndpointUrl}", sessionName, endpoint.EndpointUrl);
|
|
return new DefaultSessionAdapter(session);
|
|
}
|
|
} |