mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-24 19:13:02 +08:00
# Description Builds on #4428, which is now merged; this branch is rebased onto master. The GDS `ApplicationsNodeManager` becomes a source-generated `[NodeManager]`: the companion model, its loader and the fluent plumbing are emitted, and what stays hand-written is the behaviour. Getting there needed three things from the shared surface, which are the first two commits. ## Commits **1. Add the fluent hooks a hand-written manager needs at startup** - `OnReadRolePermissions` / `OnReadUserRolePermissions` on the node builder. Every other `NodeState` `On*` hook was already fluent; these were not, and a server that grants access on something the static model cannot express has to compute the permission set per request. - `Node<TState>(TState)` returns a builder over a node the caller already holds, for nodes materialised after `Configure` resolved its graph. - `OnAddressSpaceReadyAsync` on `FluentNodeManagerBase` — the one seam between the address space existing and the wiring being applied, for managers whose wiring depends on asynchronous setup. `Configure` is a `partial void` and cannot await. `DiNodeManager` had already invented the hook privately, so its declaration becomes an `override`. **2. Let a `[NodeManager]` bind to a model a referenced assembly supplies** A model belongs to the assembly that emits its types, which leaves a node manager for it homeless whenever that assembly cannot reference `Opc.Ua.Server` — a model-only package shared with clients, for instance. Binding was rejected twice over: the design was skipped before the binding was matched (`MODELGEN010`), and fluent-accessors-only mode refused to run alongside manager generation (`MODELGEN014`). The binding is now matched before the skip decision, and a matched binding puts that design into accessors-only mode. A design nothing binds to is still skipped, so this cannot start duplicating types by accident. The emitted manager also gains what a real manager needs: `DefaultNamespaceUris()` plus a protected constructor taking a replacement set; `GenerateDefaultConstructor=false` to suppress the two-argument form; its own logger category; and the call to `OnAddressSpaceReadyAsync`. Generated fluent accessors also stop re-enabling nullable warnings — a bare `#nullable enable` undid the shared header's `disable warnings`, so any model with a structure-typed method argument reported CS8600 on every generated `out T` in a project that builds warnings as errors. **3. Reimplement the GDS `ApplicationsNodeManager` as a generated node manager** The design stays owned by `Opc.Ua.Gds.Common`; the server assembly only binds a manager to it. **NodeIds do not move.** `NamespaceIndexes[0]` must stay the application record namespace — it is the one the application database, the certificate request store and the base allocator mint ids in — so the constructor passes the namespace order explicitly rather than adopting the generated model-first default. A test pins both ends against a live server. Four overrides go, leaving `OnAddressSpaceReadyAsync` and `Dispose(bool)` — no address-space overrides at all: | Removed | Why it was unnecessary | | --- | --- | | `New` | The base allocator already mints into `NamespaceIndexes[0]`, with a thread-safe counter. The override existed only because `Create(assignNodeIds: true)` asks the factory with the declaration id still set; `AssignInstanceNodeId` nulls it and re-asks, documented as being there for exactly this allocator. | | `AddBehaviourToPredefinedNodeAsync` | Its `AuthorizationServiceType` branch re-wired a node that was already wired, and its `KeyCredentialServiceType` branch had nothing to wire — the model ships that folder empty. | | `GetManagerHandleAsync`, `ValidateNodeAsync` | Verbatim reimplementations of the base that also blocked the fluent base's virtual-node support. | | `DeleteAddressSpaceAsync` | A `// TBD` passthrough. | Everything else — all sixteen directory methods with their self-administration permissions, the certificate groups' concrete types and trust-list flags, and the authorization service (created through this PR's `Add` surface and wired in the same place) — is one `Configure` pass. **4. Bind the certificate groups from the `Configure` pass** Acquiring a certificate group and binding it to its nodes are different kinds of work: the first is I/O (`InitAsync` opens certificate stores and creates CA certificates), the second only touches the address space. Each now runs in the phase it belongs to, which puts the whole of the wiring in one place. Ownership no longer rides on the binding. A group joins `m_ownedCertificateGroups` the moment it is constructed, before `InitAsync` can throw, so a group that fails half way through is still disposed — which the previous code could not manage, keying ownership off a dictionary it filled only after initialization succeeded. > Commit 3's message says this move is impossible and blames `PushTest`. **That was a wrong diagnosis, and this commit supersedes it.** Two real defects were hiding behind those failures: - **`Create(..., NodeId.Null, ..., assignNodeIds: false)` does not null the NodeId.** `NodeState.Create` overrides it only when handed a non-null one, so a custom group node kept the namespace-0 id of its type declaration. `AssignInstanceNodeId` hid this by re-asking the factory with the id nulled; the builder validates instead, and rejected it. The node is now created with an id in the manager's own namespace, as the `Default` authorization service already was. - **The custom certificate group node was not browseable.** It answered `GetCertificateGroups` and `ReadNode`, but a type-filtered recursive browse from the Objects folder never returned it — which OPC 10000-12 §7.8.2 requires of a certificate group. Staging the node through the builder gives it the reference it was missing. ### Two `PushTest` methods change — please review these closely The second defect had been masking what those tests actually did. Selecting the group positionally, `groups[3]` resolved to the server's **own `ServerConfiguration` group** while the custom one stayed invisible, so `UpdateTrustListOfCustomGroupAsync` and `AddRemoveCertOfCustomGroupAsync` were exercising a *transactional* trust list under a custom-group name. Browse results, before and after: | # | Before (baseline) | After | | --- | --- | --- | | 0-2 | GDS Directory groups (`ns=3`) | GDS Directory groups (`ns=3`) | | 3 | **`DefaultApplicationGroup` `i=14156`** — the server's own | **`MyCustomGroup` `ns=2`** | | 4 | — | `DefaultApplicationGroup` `i=14156` | They now resolve the group by browse name — which asserts it is browseable at all — and expect the immediate-apply semantics the GDS actually gives the groups of its own `Directory`: `CloseAndUpdate` writes the stores at once and reports `applyChangesRequired == false`, so the `ApplyChanges` calls go away (they would return `Bad_NothingToDo`). The read-back assertions are what prove the writes landed, and they are unchanged. This is a genuine loss of the *transactional* trust-list coverage those two methods were accidentally providing — the server's own group is still covered by the other `PushTest` methods, which target it deliberately. **5. Select `GetCertificates` results by type instead of by position** `GetCertificatesAsync` checked entry zero of a parallel-array result. Which entry that is depends on the order the server reports its certificate types in, an empty result throws `IndexOutOfRange` rather than failing an assertion, and a second type going missing or unparseable would not be noticed. Every returned pair is now checked, and a failure names the certificate type. **6. Drop the `.Common` suffix from the three GDS projects** Every other companion specification ships as `<Family>` / `<Family>.Client` / `<Family>.Server` — Di, ISA95, Positioning, Robotics, Vision, WotCon, XRegistry. GDS was the exception, with a `.Common` suffix that named nothing. | Before | After | | --- | --- | | `src/Opc.Ua.Gds.Common` | `src/Opc.Ua.Gds` | | `src/Opc.Ua.Gds.Client.Common` | `src/Opc.Ua.Gds.Client` | | `src/Opc.Ua.Gds.Server.Common` | `src/Opc.Ua.Gds.Server` | **No source changes were needed.** `RootNamespace` was already the final name in all three projects — the namespaces have always been `Opc.Ua.Gds`, `Opc.Ua.Gds.Client` and `Opc.Ua.Gds.Server`, and only the assembly and package ids disagreed. Nothing compiling against these assemblies changes a `using`. The package ids do change, which is consumer-visible, so `docs/migrate/2.0.x/packages.md` gains a renamed-packages section — it is the document that undertakes to cover NuGet renames — and the migration skill's package table gains the two rows a 1.5.378 consumer needs. Build infrastructure that names the projects or their output moves with them: both solution files, `expected-packages.txt` (re-sorted — it is maintained alphabetically), both signing manifests, the reference-server Dockerfile, the metapackage nuspecs, and the analyzer's package dependencies. `preview-pack.slnx` is derived from `UA.slnx` and needs no edit. The migration analyzer's shim tree mirrors the source layout by its own documented convention, so `Gds.Client.Common/` becomes `Gds.Client/`. Prose naming past work is left alone — plan 23 still records that its deferral happened during the "GDS Client.Common modernization", which is the name that effort had. ## Validation `net10.0`, on master + these four commits, from a clean GDS PKI: - `UA.slnx`: 0 errors, 0 warnings in changed files (the solution's 30 pre-existing warning lines are CA1861/CA1850/CA1307 in `XRegistry`, `Types.Tests` and `WotCon.Tests` — same rules and projects as the base). - `Opc.Ua.Gds.Tests`: 1,117 passed, 0 failed, 54 skipped — identical to the base branch. - `Opc.Ua.Server.Tests`: 4,961 passed, 0 failed, 5 skipped (measured before commit 4, which touches only the GDS assembly and its tests). - `Opc.Ua.SourceGeneration.Tests`: 169 passed. - `Opc.Ua.SourceGeneration.Core.Tests`, NodeManager/Generators/Fluent: 84 passed; `GenerateCode`: 21 passed, 4 skipped. - `Opc.Ua.MigrationAnalyzer.Core.Tests`: 10 passed, 3 skipped. - After the rename: assemblies build as `Opc.Ua.Gds.dll` / `.Client.dll` / `.Server.dll`, with no `*.Common.dll` produced anywhere. - Commits 1-3 build standalone. - `Opc.Ua.Gds.Server.Common` also builds for `net48` and `netstandard2.1` (checked before the rebase onto #4428). Not yet run: the full `Opc.Ua.SourceGeneration.Core.Tests` suite (~3,800), and the older target frameworks since the rebase. ## Checklist - [x] Existing tests pass - [x] New tests cover the new surface (role permissions, resolved-node builder, referenced-model binding, constructor/namespace control, GDS namespace invariant, custom-group node namespace) - [ ] Full Core.Tests sweep and net48/netstandard2.1 re-run after the rebase 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
434 lines
23 KiB
C#
434 lines
23 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.SourceGeneration
|
|
{
|
|
/// <summary>
|
|
/// Templates emitted by the <see cref="NodeManagerGenerator"/>.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// All emitted code uses fully-qualified type names so the consuming
|
|
/// project only needs to reference <c>Opc.Ua.Server</c> (which itself
|
|
/// transitively brings in <c>Opc.Ua.Core</c>).
|
|
/// </remarks>
|
|
internal static class NodeManagerTemplates
|
|
{
|
|
/// <summary>
|
|
/// Top-level template for the partial <c>NodeManager</c> class.
|
|
/// </summary>
|
|
public static readonly TemplateString File = TemplateString.Parse(
|
|
$$"""
|
|
{{Tokens.CodeHeader}}
|
|
|
|
// The namespace-taking constructor is emitted for every manager,
|
|
// but the user's partial decides whether the class is sealed and
|
|
// the generator cannot see that. In a sealed manager the protected
|
|
// constructor is merely unreachable, not wrong.
|
|
#pragma warning disable CS0628 // New protected member in sealed type
|
|
|
|
namespace {{Tokens.NamespacePrefix}}
|
|
{
|
|
/// <summary>
|
|
/// Source-generated node manager for the
|
|
/// <c>{{Tokens.NamespaceUri}}</c> namespace.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Implement <c>partial void Configure(INodeManagerBuilder builder)</c>
|
|
/// in a sibling partial to wire per-node callbacks using the
|
|
/// fluent API in <c>Opc.Ua.Server.Fluent</c>. Wiring that has to
|
|
/// await — materialising instances, reading a store — goes into
|
|
/// an override of
|
|
/// <c>ConfigureAsync(INodeManagerBuilder, CancellationToken)</c>,
|
|
/// which runs first so <c>Configure</c> sees the nodes it created.
|
|
/// </remarks>
|
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("{{Tokens.Tool}}", "{{Tokens.Version}}")]
|
|
public partial class {{Tokens.NodeManagerClassName}} :
|
|
global::Opc.Ua.Server.Fluent.FluentNodeManagerBase,
|
|
global::Opc.Ua.Server.Nodes.INodeSetImportFactoryProvider
|
|
{
|
|
private global::Opc.Ua.Server.Fluent.NodeManagerBuilder? __m_builder;
|
|
|
|
/// <summary>
|
|
/// The namespace URIs this manager owns, in the order they
|
|
/// are reported to the master node manager. The first entry
|
|
/// becomes <c>NamespaceIndexes[0]</c> and therefore the
|
|
/// manager's own <c>NamespaceIndex</c>: the namespace an
|
|
/// unqualified browse path resolves in. Where runtime
|
|
/// NodeIds are minted is the NodeId factory's to decide,
|
|
/// not this order's. Pass a different array to the
|
|
/// protected constructor to change the set or the order.
|
|
/// </summary>
|
|
public static string[] DefaultNamespaceUris()
|
|
{
|
|
return new string[] { {{Tokens.NamespaceUri}}{{Tokens.AdditionalNamespaceUris}} };
|
|
}
|
|
|
|
{{Tokens.NodeManagerDefaultConstructor}}
|
|
|
|
/// <summary>
|
|
/// Initializes a new <see cref="{{Tokens.NodeManagerClassName}}"/>
|
|
/// that owns <paramref name="namespaceUris"/>. Chain to this
|
|
/// from a constructor of your own to take collaborators the
|
|
/// generated signature does not carry, to change which
|
|
/// namespaces the manager owns, or to change their order.
|
|
/// </summary>
|
|
/// <param name="server">The hosting server.</param>
|
|
/// <param name="configuration">The application configuration.</param>
|
|
/// <param name="namespaceUris">
|
|
/// The namespace URIs to report, in order. <c>null</c> adopts
|
|
/// <see cref="DefaultNamespaceUris"/>.
|
|
/// </param>
|
|
protected {{Tokens.NodeManagerClassName}}(
|
|
global::Opc.Ua.Server.IServerInternal server,
|
|
global::Opc.Ua.ApplicationConfiguration configuration,
|
|
string[]? namespaceUris)
|
|
: base(
|
|
server,
|
|
configuration,
|
|
global::Opc.Ua.TelemetryExtensions.CreateLogger<{{Tokens.NodeManagerClassName}}>(
|
|
server.Telemetry),
|
|
namespaceUris ?? DefaultNamespaceUris())
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// User extensibility hook. Implement in a sibling
|
|
/// <c>partial</c> to wire callbacks via the fluent builder.
|
|
/// Override
|
|
/// <c>FluentNodeManagerBase.ConfigureAsync</c> instead when
|
|
/// the wiring has to await.
|
|
/// </summary>
|
|
partial void Configure(global::Opc.Ua.Server.Fluent.INodeManagerBuilder builder);
|
|
|
|
/// <summary>
|
|
/// Source-generated typed counterpart of
|
|
/// <see cref="Configure(global::Opc.Ua.Server.Fluent.INodeManagerBuilder)"/>.
|
|
/// Implement in a sibling <c>partial</c> to wire callbacks via the
|
|
/// strongly-typed model-traversal surface generated for this manager.
|
|
/// </summary>
|
|
partial void Configure(I{{Tokens.NodeManagerClassName}}Builder builder);
|
|
|
|
/// <summary>
|
|
/// Supplies the concrete states used when a NodeSet2
|
|
/// document imported through
|
|
/// <c>INodeManagerBuilder.Import</c> declares a node of
|
|
/// this model.
|
|
/// </summary>
|
|
public global::Opc.Ua.ArrayOf<
|
|
global::Opc.Ua.Server.Nodes.INodeSetImportFactory>
|
|
GetNodeSetImportFactories()
|
|
{
|
|
var __factories = new global::System.Collections.Generic.List<
|
|
global::Opc.Ua.Server.Nodes.INodeSetImportFactory>();
|
|
global::Opc.Ua.ArrayOf<
|
|
global::Opc.Ua.Server.Nodes.INodeSetImportFactory>
|
|
__generatedFactories =
|
|
global::{{Tokens.Prefix}}.
|
|
{{Tokens.NodeSetImportFactoryProviderClassName}}.Instance.
|
|
GetNodeSetImportFactories();
|
|
for (int __index = 0;
|
|
__index < __generatedFactories.Count;
|
|
__index++)
|
|
{
|
|
__factories.Add(__generatedFactories[__index]);
|
|
}
|
|
AddNodeSetImportFactories(__factories);
|
|
return new global::Opc.Ua.ArrayOf<
|
|
global::Opc.Ua.Server.Nodes.INodeSetImportFactory>(
|
|
__factories.ToArray());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds import factories supplied by dependency models or
|
|
/// by the application. Implement in a sibling
|
|
/// <c>partial</c>.
|
|
/// </summary>
|
|
partial void AddNodeSetImportFactories(
|
|
global::System.Collections.Generic.List<
|
|
global::Opc.Ua.Server.Nodes.INodeSetImportFactory> factories);
|
|
|
|
/// <inheritdoc/>
|
|
protected override global::System.Threading.Tasks.ValueTask<global::Opc.Ua.NodeStateCollection> LoadPredefinedNodesAsync(
|
|
global::Opc.Ua.ISystemContext context,
|
|
global::System.Threading.CancellationToken cancellationToken = default)
|
|
{
|
|
return new global::System.Threading.Tasks.ValueTask<global::Opc.Ua.NodeStateCollection>(
|
|
global::{{Tokens.Prefix}}.{{Tokens.Namespace}}Extensions.Add{{Tokens.Namespace}}(
|
|
new global::Opc.Ua.NodeStateCollection(),
|
|
context));
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override async global::System.Threading.Tasks.ValueTask CreateAddressSpaceAsync(
|
|
global::System.Collections.Generic.IDictionary<global::Opc.Ua.NodeId,
|
|
global::System.Collections.Generic.IList<global::Opc.Ua.IReference>> externalReferences,
|
|
global::System.Threading.CancellationToken cancellationToken = default)
|
|
{
|
|
await base.CreateAddressSpaceAsync(externalReferences, cancellationToken).ConfigureAwait(false);
|
|
|
|
ushort __nsIndex = Server.NamespaceUris.GetIndexOrAppend({{Tokens.NamespaceUri}});
|
|
|
|
__m_builder = new global::Opc.Ua.Server.Fluent.NodeManagerBuilder(
|
|
SystemContext,
|
|
this,
|
|
__nsIndex,
|
|
__FindRootByBrowseName,
|
|
__FindRootByNodeId,
|
|
__FindByTypeDefinitionId,
|
|
__FindByDataTypeId);
|
|
|
|
// Attach the FluentNodeManagerBase event-source registry
|
|
// to the builder so Publish(...) extensions can resolve
|
|
// it before the user's Configure partial(s) run.
|
|
AttachToBuilder(__m_builder);
|
|
|
|
// The awaitable wiring seam. Runs before the synchronous
|
|
// Configure partial(s) so instances it materialises are in
|
|
// the address space by the time they wire callbacks.
|
|
await ConfigureAsync(__m_builder, cancellationToken).ConfigureAwait(false);
|
|
|
|
Configure(__m_builder);
|
|
Configure(new {{Tokens.NodeManagerClassName}}TypedBuilder(__m_builder));
|
|
|
|
// Register nodes created by the Configure partial(s)
|
|
// through the builder's Add* methods before the
|
|
// reverse-reference pass runs, so their references to
|
|
// externally owned nodes are mirrored too.
|
|
await RegisterAuthoredNodesAsync(__m_builder, cancellationToken).ConfigureAwait(false);
|
|
|
|
// Mirror references from configure-created nodes to
|
|
// nodes owned by other node managers (e.g. the Objects
|
|
// folder) into the externalReferences dictionary.
|
|
await CompleteConfigureAsync(externalReferences, cancellationToken).ConfigureAwait(false);
|
|
|
|
// Seals the builder, replays NotifyNodeAdded for every
|
|
// predefined node so per-node lifecycle hooks fire
|
|
// deterministically, and only then completes the
|
|
// registrations Configure could not await (root
|
|
// notifiers) and starts the simulations, so no
|
|
// simulated value change can precede the OnNodeAdded
|
|
// handler of its own node.
|
|
await SealConfigurationAsync(__m_builder, cancellationToken).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override async global::System.Threading.Tasks.ValueTask AddPredefinedNodeAsync(
|
|
global::Opc.Ua.ISystemContext context,
|
|
global::Opc.Ua.NodeState node,
|
|
global::System.Threading.CancellationToken cancellationToken = default)
|
|
{
|
|
await base.AddPredefinedNodeAsync(context, node, cancellationToken).ConfigureAwait(false);
|
|
if (__m_builder is { } __b)
|
|
{
|
|
__b.Dispatcher.NotifyNodeAdded(context, node);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override async global::System.Threading.Tasks.ValueTask RemovePredefinedNodeAsync(
|
|
global::Opc.Ua.ISystemContext context,
|
|
global::Opc.Ua.NodeState node,
|
|
global::System.Collections.Generic.List<global::Opc.Ua.Server.LocalReference> referencesToRemove,
|
|
global::System.Threading.CancellationToken cancellationToken = default)
|
|
{
|
|
if (__m_builder is { } __b)
|
|
{
|
|
__b.Dispatcher.NotifyNodeRemoved(context, node);
|
|
}
|
|
await base.RemovePredefinedNodeAsync(context, node, referencesToRemove, cancellationToken).ConfigureAwait(false);
|
|
}
|
|
|
|
private global::Opc.Ua.NodeState __FindRootByBrowseName(global::Opc.Ua.QualifiedName browseName)
|
|
{
|
|
if (browseName == null)
|
|
{
|
|
return null;
|
|
}
|
|
foreach (global::Opc.Ua.NodeState __node in PredefinedNodes.Values)
|
|
{
|
|
if (__node.BrowseName == browseName)
|
|
{
|
|
return __node;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private global::Opc.Ua.NodeState __FindRootByNodeId(global::Opc.Ua.NodeId nodeId)
|
|
{
|
|
if (nodeId.IsNull)
|
|
{
|
|
return null;
|
|
}
|
|
return PredefinedNodes.TryGetValue(nodeId, out global::Opc.Ua.NodeState __node) ? __node : null;
|
|
}
|
|
|
|
private global::System.Collections.Generic.IReadOnlyList<global::Opc.Ua.NodeState> __FindByTypeDefinitionId(
|
|
global::Opc.Ua.NodeId typeDefinitionId)
|
|
{
|
|
if (typeDefinitionId == null || typeDefinitionId.IsNull)
|
|
{
|
|
return global::System.Array.Empty<global::Opc.Ua.NodeState>();
|
|
}
|
|
|
|
var __matches = new global::System.Collections.Generic.List<global::Opc.Ua.NodeState>();
|
|
var __queue = new global::System.Collections.Generic.Queue<global::Opc.Ua.NodeState>();
|
|
var __seen = new global::System.Collections.Generic.HashSet<global::Opc.Ua.NodeState>();
|
|
var __scratch = new global::System.Collections.Generic.List<global::Opc.Ua.BaseInstanceState>();
|
|
foreach (global::Opc.Ua.NodeState __root in PredefinedNodes.Values)
|
|
{
|
|
if (__root != null && __seen.Add(__root))
|
|
{
|
|
__queue.Enqueue(__root);
|
|
}
|
|
}
|
|
while (__queue.Count > 0)
|
|
{
|
|
global::Opc.Ua.NodeState __current = __queue.Dequeue();
|
|
if (__current is global::Opc.Ua.BaseInstanceState __instance &&
|
|
__instance.TypeDefinitionId == typeDefinitionId)
|
|
{
|
|
__matches.Add(__current);
|
|
}
|
|
__scratch.Clear();
|
|
__current.GetChildren(SystemContext, __scratch);
|
|
for (int __i = 0; __i < __scratch.Count; __i++)
|
|
{
|
|
global::Opc.Ua.BaseInstanceState __child = __scratch[__i];
|
|
if (__child != null && __seen.Add(__child))
|
|
{
|
|
__queue.Enqueue(__child);
|
|
}
|
|
}
|
|
}
|
|
return __matches;
|
|
}
|
|
|
|
private global::Opc.Ua.ArrayOf<global::Opc.Ua.NodeState> __FindByDataTypeId(
|
|
global::Opc.Ua.NodeId dataTypeId)
|
|
{
|
|
if (dataTypeId == null || dataTypeId.IsNull)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
var __matches = new global::System.Collections.Generic.List<global::Opc.Ua.NodeState>();
|
|
var __queue = new global::System.Collections.Generic.Queue<global::Opc.Ua.NodeState>();
|
|
var __seen = new global::System.Collections.Generic.HashSet<global::Opc.Ua.NodeState>();
|
|
var __scratch = new global::System.Collections.Generic.List<global::Opc.Ua.BaseInstanceState>();
|
|
foreach (global::Opc.Ua.NodeState __root in PredefinedNodes.Values)
|
|
{
|
|
if (__root != null && __seen.Add(__root))
|
|
{
|
|
__queue.Enqueue(__root);
|
|
}
|
|
}
|
|
while (__queue.Count > 0)
|
|
{
|
|
global::Opc.Ua.NodeState __current = __queue.Dequeue();
|
|
if (__current is global::Opc.Ua.BaseVariableState __variable &&
|
|
__variable.DataType == dataTypeId)
|
|
{
|
|
__matches.Add(__current);
|
|
}
|
|
__scratch.Clear();
|
|
__current.GetChildren(SystemContext, __scratch);
|
|
for (int __i = 0; __i < __scratch.Count; __i++)
|
|
{
|
|
global::Opc.Ua.BaseInstanceState __child = __scratch[__i];
|
|
if (__child != null && __seen.Add(__child))
|
|
{
|
|
__queue.Enqueue(__child);
|
|
}
|
|
}
|
|
}
|
|
return new global::Opc.Ua.ArrayOf<global::Opc.Ua.NodeState>(
|
|
__matches.ToArray());
|
|
}
|
|
}
|
|
}
|
|
""");
|
|
|
|
/// <summary>
|
|
/// The public <c>(server, configuration)</c> constructor. Emitted
|
|
/// unless the binding sets <c>GenerateDefaultConstructor=false</c>,
|
|
/// which managers do when they cannot be built from those two
|
|
/// arguments alone.
|
|
/// </summary>
|
|
public static readonly TemplateString DefaultConstructor = TemplateString.Parse(
|
|
$$"""
|
|
/// <summary>
|
|
/// Initializes a new <see cref="{{Tokens.NodeManagerClassName}}"/>
|
|
/// owning <see cref="DefaultNamespaceUris"/>.
|
|
/// </summary>
|
|
/// <param name="server">The hosting server.</param>
|
|
/// <param name="configuration">The application configuration.</param>
|
|
public {{Tokens.NodeManagerClassName}}(
|
|
global::Opc.Ua.Server.IServerInternal server,
|
|
global::Opc.Ua.ApplicationConfiguration configuration)
|
|
: this(server, configuration, null)
|
|
{
|
|
}
|
|
""");
|
|
|
|
/// <summary>
|
|
/// Top-level template for the generated factory class.
|
|
/// </summary>
|
|
public static readonly TemplateString FactoryFile = TemplateString.Parse(
|
|
$$"""
|
|
{{Tokens.CodeHeader}}
|
|
|
|
namespace {{Tokens.NamespacePrefix}}
|
|
{
|
|
/// <summary>
|
|
/// Source-generated <see cref="global::Opc.Ua.Server.INodeManagerFactory"/>
|
|
/// for the <c>{{Tokens.NamespaceUri}}</c> namespace.
|
|
/// </summary>
|
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("{{Tokens.Tool}}", "{{Tokens.Version}}")]
|
|
public partial class {{Tokens.NodeManagerFactoryClassName}} : global::Opc.Ua.Server.IAsyncNodeManagerFactory
|
|
{
|
|
/// <inheritdoc/>
|
|
public virtual global::Opc.Ua.ArrayOf<string> NamespacesUris
|
|
=> new global::Opc.Ua.ArrayOf<string>(new string[] { {{Tokens.NamespaceUri}}{{Tokens.AdditionalNamespaceUris}} });
|
|
|
|
/// <inheritdoc/>
|
|
public virtual global::System.Threading.Tasks.ValueTask<global::Opc.Ua.Server.IAsyncNodeManager> CreateAsync(
|
|
global::Opc.Ua.Server.IServerInternal server,
|
|
global::Opc.Ua.ApplicationConfiguration configuration,
|
|
global::System.Threading.CancellationToken cancellationToken = default)
|
|
{
|
|
return new global::System.Threading.Tasks.ValueTask<global::Opc.Ua.Server.IAsyncNodeManager>(
|
|
new {{Tokens.NodeManagerClassName}}(server, configuration));
|
|
}
|
|
}
|
|
}
|
|
""");
|
|
}
|
|
}
|