using Opc.Ua; using Opc.Ua.Client; using Serilog; namespace ZB.MOM.WW.OtOpcUa.Client.Shared.Adapters; /// /// Production session factory that creates real OPC UA sessions. /// internal sealed class DefaultSessionFactory : ISessionFactory { private static readonly ILogger Logger = Log.ForContext(); /// Creates a new OPC UA session. /// The OPC UA application configuration. /// The endpoint description to connect to. /// The name for the session. /// The session timeout in milliseconds. /// The user identity for the session. /// The cancellation token. /// An adapter wrapping the created session. public async Task 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 session = await Session.Create( config, configuredEndpoint, false, sessionName, sessionTimeoutMs, identity, null); Logger.Information("Session created: {SessionName} -> {EndpointUrl}", sessionName, endpoint.EndpointUrl); return new DefaultSessionAdapter(session); } }