mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-21 09:06:37 +08:00
43ce7ed229
This pull request modernizes the OPC UA .NET codebase and tests, removes .NET Standard 2.0 support from certificate/security code, and updates test code to use C# 12 and .NET 8+ features for clarity and maintainability. - Certificate and BouncyCastle interop files (e.g., CertificateBuilder.cs, X509Extensions.cs, X509SignatureFactory.cs) are refactored to drop NETSTANDARD2_0 support and use modern .NET APIs and conditional compilation. - Test code across the codebase is updated to use default, strongly-typed Parse methods, collection expressions, and improved async/await patterns. - Exception handling and assertions in tests are modernized, and test method naming is made consistent with Async suffixes. - The project and build files are updated to clarify Roslynator analyzer usage and remove obsolete netstandard tags. - General code and test cleanup includes improved null safety, type safety, and removal of deprecated or unused code.
178 lines
6.6 KiB
C#
178 lines
6.6 KiB
C#
/* ========================================================================
|
|
* 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/
|
|
* ======================================================================*/
|
|
|
|
namespace Opc.Ua.Server
|
|
{
|
|
/// <summary>
|
|
/// A generic implementation for ISystemContext interface.
|
|
/// </summary>
|
|
public class ServerSystemContext : SessionSystemContext
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="SystemContext"/> class.
|
|
/// </summary>
|
|
/// <param name="server">The server.</param>
|
|
public ServerSystemContext(IServerInternal server)
|
|
: base(server.Telemetry)
|
|
{
|
|
OperationContext = null;
|
|
NamespaceUris = server.NamespaceUris;
|
|
ServerUris = server.ServerUris;
|
|
TypeTable = server.TypeTree;
|
|
EncodeableFactory = server.Factory;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="SystemContext"/> class.
|
|
/// </summary>
|
|
/// <param name="server">The server.</param>
|
|
/// <param name="context">The context.</param>
|
|
public ServerSystemContext(IServerInternal server, OperationContext context)
|
|
: base(server.Telemetry)
|
|
{
|
|
OperationContext = context;
|
|
NamespaceUris = server.NamespaceUris;
|
|
ServerUris = server.ServerUris;
|
|
TypeTable = server.TypeTree;
|
|
EncodeableFactory = server.Factory;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="SystemContext"/> class.
|
|
/// </summary>
|
|
/// <param name="server">The server.</param>
|
|
/// <param name="session">The session.</param>
|
|
public ServerSystemContext(IServerInternal server, ISession session)
|
|
: base(server.Telemetry)
|
|
{
|
|
OperationContext = null;
|
|
SessionId = session.Id;
|
|
UserIdentity = session.Identity;
|
|
PreferredLocales = session.PreferredLocales;
|
|
NamespaceUris = server.NamespaceUris;
|
|
ServerUris = server.ServerUris;
|
|
TypeTable = server.TypeTree;
|
|
EncodeableFactory = server.Factory;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The operation context associated with system context.
|
|
/// </summary>
|
|
/// <value>The operation context.</value>
|
|
public new OperationContext OperationContext
|
|
{
|
|
get => base.OperationContext as OperationContext;
|
|
set => base.OperationContext = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a copy of the context that can be used with the specified operation context.
|
|
/// </summary>
|
|
/// <returns>A copy of the system context.</returns>
|
|
public ServerSystemContext Copy()
|
|
{
|
|
return (ServerSystemContext)MemberwiseClone();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a copy of the context that can be used with the specified operation context.
|
|
/// </summary>
|
|
/// <param name="context">The operation context to use.</param>
|
|
/// <returns>
|
|
/// A copy of the system context that references the new operation context.
|
|
/// </returns>
|
|
public ServerSystemContext Copy(OperationContext context)
|
|
{
|
|
var copy = (ServerSystemContext)MemberwiseClone();
|
|
|
|
if (context != null)
|
|
{
|
|
copy.OperationContext = context;
|
|
}
|
|
|
|
return copy;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a copy of the context that can be used with the specified session.
|
|
/// </summary>
|
|
/// <param name="session">The session to use.</param>
|
|
/// <returns>
|
|
/// A copy of the system context that references the new session.
|
|
/// </returns>
|
|
public ServerSystemContext Copy(ISession session)
|
|
{
|
|
var copy = (ServerSystemContext)MemberwiseClone();
|
|
|
|
copy.OperationContext = null;
|
|
|
|
if (session != null)
|
|
{
|
|
copy.SessionId = session.Id;
|
|
copy.UserIdentity = session.Identity;
|
|
copy.PreferredLocales = session.PreferredLocales;
|
|
}
|
|
else
|
|
{
|
|
copy.SessionId = default;
|
|
copy.UserIdentity = null;
|
|
copy.PreferredLocales = null;
|
|
}
|
|
|
|
return copy;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a copy of the context that can be used with the specified server context.
|
|
/// </summary>
|
|
/// <param name="context">The server context to use.</param>
|
|
/// <returns>
|
|
/// A copy of the system context that references the new server context.
|
|
/// </returns>
|
|
public ServerSystemContext Copy(ServerSystemContext context)
|
|
{
|
|
var copy = (ServerSystemContext)MemberwiseClone();
|
|
|
|
if (context != null)
|
|
{
|
|
copy.OperationContext = context.OperationContext;
|
|
copy.SessionId = context.SessionId;
|
|
copy.UserIdentity = context.UserIdentity;
|
|
copy.PreferredLocales = context.PreferredLocales;
|
|
copy.NamespaceUris = context.NamespaceUris;
|
|
copy.ServerUris = context.ServerUris;
|
|
copy.TypeTable = context.TypeTable;
|
|
copy.EncodeableFactory = context.EncodeableFactory;
|
|
}
|
|
|
|
return copy;
|
|
}
|
|
}
|
|
}
|