mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-18 22:55:08 +08:00
e1b9cea3ea
## Proposed changes Reduces sync-over-async in non-obsolete server APIs, removes stale `#region/#endregion` noise from the test suite, and fixes analyzer/test fallout from merging the Part 11 Historical Access framework (#3797). Follow-up review feedback is included: `FileSystemNodeManager` is now based on `AsyncCustomNodeManager`. ### Sync-over-async reduction (~24 `GetAwaiter().GetResult()` sites) **Server-side:** - `TrustList`: async `OnCallAsync` handlers added; sync `OnCall` handlers retained as compat shims so legacy `CustomNodeManager2` subclasses that host the TrustList but do not implement `ICallAsyncNodeManager` keep working through `MethodState.Call`. - `GDS ApplicationsNodeManager`: `RequestAccessToken`, `KeyCredentialStart/FinishRequest`, and `Revoke` moved to `OnCallAsync`. - `IKeyCredentialRequestStore`: interface + in-memory implementation converted to async; `FinishKeyCredentialRequestResult` record carries the previous out-set. Tests in `Tests/Opc.Ua.Gds.Tests/` updated to the new async API. - `FileSystem`: - `DirectoryObjectState` methods (`CreateDirectory` / `CreateFile` / `Delete` / `MoveOrCopy`) use `OnCallAsync`. - `FileSystemNodeManager` now derives from `AsyncCustomNodeManager` and overrides async address-space/node-resolution paths (`CreateAddressSpaceAsync`, `DeleteAddressSpaceAsync`, `GetManagerHandleAsync`, `ValidateNodeAsync`) to avoid sync-over-async in dynamic node validation. - `FileSystemNodeManagerFactory` now supports async creation (`IAsyncNodeManagerFactory`) while retaining sync factory compatibility. - Reference server registration of the FileSystem node manager is aligned to the async node manager list. - `ConfigurationNodeManager` namespace lookup uses sync `GetManagerHandle` to keep the remaining `GetResult` inside the documented `SyncNodeManagerAdapter` bridge. - `ServerBase`: new `OnServerStartingAsync`; `StartAsync` now awaits it. - `StandardServer.CreateMasterNodeManagerAsync` added; sync wrapper kept for backward compatibility. - `IServerInternal.CloseSession` marked `[Obsolete]` (`CloseSessionAsync` exists). - `IMasterNodeManager.RemoveReferences` marked `[Obsolete]`; in-tree sync callers remain with scoped `CS0618` pragmas + TODO. **Stack:** - `EncryptedSecret`: added `VerifyHeaderForEccAsync` / `DecryptAsync` / `TryDecryptAsync`; `UserNameIdentityTokenHandler.DecryptAsync` awaits ECC validation. - `CertificatePasswordProvider` ctor: `GetResult` fallback replaced with explicit `InvalidOperationException`. ### Code-style and post-merge cleanup - Removed unused `#region`/`#endregion` directives across test files. - Restored green build state after Part 11 merge fallout fixes (production + analyzer + test cleanup from earlier commits in this PR). ### CI / validation notes - This PR branch surfaced runtime regressions introduced by Part 11 after the build-breaker was fixed (outside scope of this async/code-style cleanup). - Follow-up feedback change validation for `FileSystemNodeManager`: - `dotnet build Libraries/Opc.Ua.Server/Opc.Ua.Server.csproj -f net10.0 --no-restore` ✅ - `dotnet test Tests/Opc.Ua.Server.Tests/Opc.Ua.Server.Tests.csproj -f net10.0 --filter FileSystemNodeIdTests` ✅ - `dotnet test Tests/Opc.Ua.History.Tests/Opc.Ua.History.Tests.csproj -f net10.0 --filter FileSystemSmokeTests` ✅ (test skipped in environment) ## Related Issues - None. ## Types of changes - [ ] Bugfix (non-breaking change which fixes an issue) - [x] Enhancement (non-breaking change which adds functionality) - [x] Test enhancement (non-breaking change to increase test coverage) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages) - [ ] Documentation Update (if none of the other choices apply) ## Checklist - [x] I have read the [CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md) doc. - [x] I have signed the [CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf). - [x] I ran tests locally with my changes, all passed. - [ ] I fixed all failing tests in the CI pipelines. - [ ] I fixed all introduced issues with CodeQL and LGTM. - [x] I have added tests that prove my fix is effective or that my feature works and increased code coverage. - [x] I have added necessary documentation (if appropriate). - [x] Any dependent changes have been merged and published in downstream modules.
197 lines
7.6 KiB
C#
197 lines
7.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/
|
|
* ======================================================================*/
|
|
|
|
using System;
|
|
|
|
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 ?? throw new ArgumentNullException(nameof(server))).Telemetry)
|
|
{
|
|
Server = server;
|
|
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 ?? throw new ArgumentNullException(nameof(server))).Telemetry)
|
|
{
|
|
Server = server;
|
|
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 ?? throw new ArgumentNullException(nameof(server))).Telemetry)
|
|
{
|
|
Server = server;
|
|
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 <see cref="IServerInternal"/> backing this system context.
|
|
/// Provides access to server-wide services (AggregateManager,
|
|
/// SessionManager, audit reporting, etc.) needed by infrastructure
|
|
/// components such as the historian dispatcher.
|
|
/// </summary>
|
|
public IServerInternal Server { get; }
|
|
|
|
/// <summary>
|
|
/// The operation context associated with system context.
|
|
/// </summary>
|
|
/// <value>The operation context.</value>
|
|
/// <remarks>
|
|
/// May return <c>null</c> if the underlying base context's operation context
|
|
/// has not been set or is not an <see cref="OperationContext"/> instance
|
|
/// (e.g. during NodeManager startup before any operation has begun).
|
|
/// </remarks>
|
|
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 = default;
|
|
}
|
|
|
|
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;
|
|
copy.NodeIdFactory = context.NodeIdFactory;
|
|
}
|
|
|
|
return copy;
|
|
}
|
|
}
|
|
}
|