/* ======================================================================== * Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved. * * OPC Foundation MIT License 1.00 * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * The complete license agreement can be found here: * http://opcfoundation.org/License/MIT/1.00/ * ======================================================================*/ using System.Threading; using System.Threading.Tasks; using Opc.Ua.Security.Certificates; namespace Opc.Ua.Client { /// /// The default session factory that creates /// instances which automatically handle reconnection and failover. /// /// /// /// Each CreateAsync overload creates a raw /// via an inner /// and wraps it in a . /// /// /// Use directly if you need raw /// instances without automatic reconnection. /// /// public class ManagedSessionFactory : ISessionFactory { private readonly DefaultSessionFactory m_innerFactory; /// public ITelemetryContext Telemetry { get; init; } /// public DiagnosticsMasks ReturnDiagnostics { get => m_innerFactory.ReturnDiagnostics; set => m_innerFactory.ReturnDiagnostics = value; } /// /// Creates a new instance of the . /// /// The telemetry context to use. public ManagedSessionFactory(ITelemetryContext telemetry) { Telemetry = telemetry; m_innerFactory = new DefaultSessionFactory(telemetry); } /// public virtual async Task CreateAsync( ApplicationConfiguration configuration, ConfiguredEndpoint endpoint, bool updateBeforeConnect, string sessionName, uint sessionTimeout, IUserIdentity? identity, ArrayOf preferredLocales, CancellationToken ct = default) { return await CreateManagedSessionAsync( configuration, endpoint, identity, sessionName, sessionTimeout, preferredLocales, checkDomain: false, ct).ConfigureAwait(false); } /// public virtual async Task CreateAsync( ApplicationConfiguration configuration, ConfiguredEndpoint endpoint, bool updateBeforeConnect, bool checkDomain, string sessionName, uint sessionTimeout, IUserIdentity? identity, ArrayOf preferredLocales, CancellationToken ct = default) { return await CreateManagedSessionAsync( configuration, endpoint, identity, sessionName, sessionTimeout, preferredLocales, checkDomain, ct).ConfigureAwait(false); } /// public virtual async Task CreateAsync( ApplicationConfiguration configuration, ITransportWaitingConnection connection, ConfiguredEndpoint endpoint, bool updateBeforeConnect, bool checkDomain, string sessionName, uint sessionTimeout, IUserIdentity? identity, ArrayOf preferredLocales, CancellationToken ct = default) { return await CreateManagedSessionAsync( configuration, endpoint, identity, sessionName, sessionTimeout, preferredLocales, checkDomain, ct).ConfigureAwait(false); } /// public virtual async Task CreateAsync( ApplicationConfiguration configuration, ReverseConnectManager reverseConnectManager, ConfiguredEndpoint endpoint, bool updateBeforeConnect, bool checkDomain, string sessionName, uint sessionTimeout, IUserIdentity? userIdentity, ArrayOf preferredLocales, CancellationToken ct = default) { return await CreateManagedSessionAsync( configuration, endpoint, userIdentity, sessionName, sessionTimeout, preferredLocales, checkDomain, ct).ConfigureAwait(false); } /// public virtual Task CreateChannelAsync( ApplicationConfiguration configuration, ITransportWaitingConnection? connection, ConfiguredEndpoint endpoint, bool updateBeforeConnect, bool checkDomain, CancellationToken ct = default) { return m_innerFactory.CreateChannelAsync( configuration, connection, endpoint, updateBeforeConnect, checkDomain, ct); } /// public virtual Task RecreateAsync( ISession sessionTemplate, CancellationToken ct = default) { return m_innerFactory.RecreateAsync(sessionTemplate, ct); } /// public virtual Task RecreateAsync( ISession sessionTemplate, ITransportWaitingConnection connection, CancellationToken ct = default) { return m_innerFactory.RecreateAsync(sessionTemplate, connection, ct); } /// public virtual Task RecreateAsync( ISession sessionTemplate, ITransportChannel transportChannel, CancellationToken ct = default) { return m_innerFactory.RecreateAsync(sessionTemplate, transportChannel, ct); } /// public virtual ISession Create( ITransportChannel channel, ApplicationConfiguration configuration, ConfiguredEndpoint endpoint, Certificate? clientCertificate = null, CertificateCollection? clientCertificateChain = null, ArrayOf availableEndpoints = default, ArrayOf discoveryProfileUris = default) { return m_innerFactory.Create( channel, configuration, endpoint, clientCertificate, clientCertificateChain, availableEndpoints, discoveryProfileUris); } private Task CreateManagedSessionAsync( ApplicationConfiguration configuration, ConfiguredEndpoint endpoint, IUserIdentity? identity, string sessionName, uint sessionTimeout, ArrayOf preferredLocales, bool checkDomain, CancellationToken ct) { return ManagedSession.CreateAsync( configuration, endpoint, m_innerFactory, identity, telemetry: Telemetry, sessionName: sessionName, sessionTimeout: sessionTimeout, preferredLocales: preferredLocales, checkDomain: checkDomain, ct: ct); } } }