mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-19 07:02:16 +08:00
01d7162313
Complete implementation of **OPC UA Part 9 ΓÇö Alarms & Conditions** for
both server and client, **OPC UA Part 16 ΓÇö State Machines** (generic
extensible client + server API), and the supporting infrastructure
(source-generated event records, source-generated ObjectType proxies,
`IAsyncEnumerable` streaming subscriptions, address-space model change
tracking, per-node `INodeCache` invalidation, unified DI integration).
### Server-side (Part 9 complete)
- **`AlarmConditionState`** ΓÇö every Part 9 method wired automatically
in `OnAfterCreate`: `Silence`, `Suppress`/`Suppress2`,
`Unsuppress`/`Unsuppress2`, `RemoveFromService`/`RemoveFromService2`,
`PlaceInService`/`PlaceInService2`, `Reset`/`Reset2`,
`GetGroupMemberships`. Each method generates the spec-mandated audit
event and supports an optional veto-delegate hook.
- **Latched alarms** ΓÇö `ActiveState` reflects real process state;
`LatchedState` persists until explicit `Reset` (with full precondition
validation).
- **Re-alarming** ΓÇö
`ProcessReAlarm`/`ResetReAlarmRepeatCount`/`IsReAlarmEnabled` helpers
(opt-in, no hidden timer).
- **Audible alarms** ΓÇö `UpdateAudibleState` for
`AudibleEnabled`/`AudibleSound`/`SilenceState` lifecycle.
- **Suppression + groups** ΓÇö `AlarmGroup`, `AlarmSuppressionEngine`
(with first-in-group), `AlarmRateTracker` (for `AlarmMetricsType`).
- **Spec-compliance fixes** ΓÇö `SuppressedOrShelved` now includes
`OutOfServiceState`; `GetRetainState` includes `LatchedState`;
`EffectiveDisplayName` composition includes `OutOfServiceState` +
`LatchedState`.
### Client-side Part 9 API
- **`AlarmClient`** ΓÇö typed Part 9 operations. Each method delegates
to the matching source-generated `*TypeClient` proxy
(`ConditionTypeClient`, `AcknowledgeableConditionTypeClient`,
`AlarmConditionTypeClient`, `DialogConditionTypeClient`,
`ShelvedStateMachineTypeClient`) ΓÇö one source of truth for every
method NodeId.
- **Interface hierarchy** — `IConditionOperations` →
`IAcknowledgeableConditionOperations` → `IAlarmOperations` +
`IDialogConditionOperations`.
- **Source-generated event records** ΓÇö new `EventRecordGenerator`
(alongside `ObjectTypeProxyGenerator`) emits `{Type}TypeRecord` per OPC
UA event type: `ConditionTypeRecord` →
`AcknowledgeableConditionTypeRecord` → `AlarmConditionTypeRecord` →
`LimitAlarmTypeRecord`/`ExclusiveLimitAlarmTypeRecord`/… all the way
to vendor subtypes. **Vendor alarm types get records automatically.**
- **`AlarmEventDecoder`** ΓÇö decodes `EventNotification.Fields` into
the most-specific generated record.
- **`AlarmEventFilterBuilder`** ΓÇö fluent builder for Part 9
`EventFilter`s.
- **`ISession.GetAlarmClient(telemetry)`** convenience extension.
### Part 16 state machines (generic, extensible)
- **Client**: extension methods on the source-generated
`StateMachineTypeClient` / `FiniteStateMachineTypeClient` ΓÇö
`GetCurrentStateAsync`, `ObserveFiniteTransitionsAsync`
(`IAsyncEnumerable<FiniteStateSnapshot>`), `WaitForStateAsync`,
`GetAvailableStatesAsync` / `GetAvailableTransitionsAsync`. **Vendor
proxies inherit the API automatically** through the generated
inheritance chain.
- **Server**: `StateMachineBuilder` (fluent: `AddState` /
`AddTransition` / `OnCause` / validation) +
`FluentFiniteStateMachineState` ΓÇö declare a Part 16 state machine
without subclassing the abstract base.
- **Alarms alignment**: `AlarmClient.GetShelvingStateAsync` /
`ObserveShelvingTransitionsAsync` surface the API for every alarm's
`ShelvingState` child.
### IAsyncEnumerable streaming subscription
- **`IStreamingSubscription`** with
`SubscribeDataChangesAsync`/`SubscribeEventsAsync` returning
`IAsyncEnumerable<T>` (Channel-backed).
- **`ManagedSession.DefaultStreaming`** ΓÇö lazy shared subscription;
disposed with the session.
- **Helpers** ΓÇö `TakeUntilAsync`, `WithTimeoutAsync`, `TakeAsync`,
`BufferedAsync` for state-machine waits and bounded observation windows.
- **`AlarmStreamExtensions`** ΓÇö
`SubscribeAlarmsAsync`/`SubscribeConditionsAsync`/`SubscribeDialogsAsync`
returning the source-generated record types.
### Address-space model change tracking
- **Server**: `RaiseGeneralModelChangeEvent` on both `CustomNodeManager`
and `AsyncCustomNodeManager`; `ModelChangeAggregator` (in
`Opc.Ua.Server.NodeManager`, used by every node manager) batches changes
per service call; **auto-emit** from `CreateNode`/`DeleteNode` (opt-out
via `ModelChangeEmissionEnabled = false`).
- **Client**: `IModelChangeTracker` subscribes to
`BaseModelChangeEventType` via the streaming subscription, decodes
`ModelChangeStructureDataType` payloads, invalidates the `INodeCache`
per-node.
- **`INodeCache.InvalidateNode(NodeId)`** ΓÇö new interface member (true
per-node eviction in `NodeCache`).
- **`ManagedSession.EnableModelChangeTrackingAsync()`** +
`ManagedSessionOptions.ModelChangeTracking` +
`ManagedSessionBuilder.WithModelChangeTracking()` fluent method.
### Dependency Injection integration
- **`services.AddOpcUa().AddClient(...).AddAlarms()`** ΓÇö registers
`AlarmClientFactory` so DI-hosted apps can resolve a Part 9 client per
session without `new`-ing one manually.
- Cross-link added to the unified DI surface (`AddServer` / `AddClient`
/ `AddComplexTypes` / `AddGdsServer` / `AddLdsServer` /
`AddWotConServer`).
### Quickstart server modernization
- `Quickstarts.Servers/Alarms/AlarmNodeManager.cs` ported to
`AsyncCustomNodeManager` and demonstrates the new `AlarmGroup` +
`AlarmSuppressionEngine` end-to-end via a writable `MaintenanceMode`
boolean that suppresses every member alarm.
### Documentation
- New: `Docs/AlarmsAndConditions.md`, `Docs/StreamingSubscription.md`,
`Docs/ModelChangeTracking.md`, `Docs/StateMachines.md` ΓÇö full
developer guides.
- Updated: `Docs/DependencyInjection.md` (`AddAlarms()` row + section),
`Docs/README.md` index, `Docs/MigrationGuide.md` (Part 9 / Part 16 /
model change tracking sections covering behavior changes + breaking API
surface).
- Sample: `Applications/ConsoleReferenceClient/AlarmClientSample.cs`.
572 lines
25 KiB
C#
572 lines
25 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;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
using Opc.Ua.Schema.Model;
|
|
|
|
namespace Opc.Ua.SourceGeneration
|
|
{
|
|
/// <summary>
|
|
/// Source Generation API
|
|
/// </summary>
|
|
public static class Generators
|
|
{
|
|
/// <summary>
|
|
/// Generate code from design files
|
|
/// </summary>
|
|
/// <param name="designFiles">Design files to process</param>
|
|
/// <param name="fileSystem">File system abstraction to use</param>
|
|
/// <param name="outputDir">Output folder or null</param>
|
|
/// <param name="telemetry">Telemetry context for logging</param>
|
|
/// <param name="options">Generator options</param>
|
|
/// <param name="useAllowSubtypes">allow subtypes</param>
|
|
/// <param name="identifierFiles">Any additional csv files</param>
|
|
/// <param name="referencedModels">Models supplied by referenced
|
|
/// assemblies (keyed by model URI). Used to seed the assembly
|
|
/// dependency closure and may be empty.</param>
|
|
/// <param name="nodeManagerBindings">
|
|
/// Optional <c>[NodeManager]</c> attribute bindings discovered in
|
|
/// the consuming compilation. When supplied, each binding is
|
|
/// matched to a design by <see cref="NodeManagerAttributeBinding.NamespaceUri"/>
|
|
/// (preferred) or, if no URI is given, by single-design fallback.
|
|
/// Matched bindings force <c>GenerateNodeManager = true</c> for the
|
|
/// design and override the manager class name and namespace.
|
|
/// </param>
|
|
/// <param name="reportBindingDiagnostic">
|
|
/// Optional callback invoked for each binding-related warning or
|
|
/// error (e.g. unmatched URI, ambiguous fallback). Implementations
|
|
/// typically convert these into Roslyn diagnostics.
|
|
/// </param>
|
|
public static void GenerateCode(
|
|
this DesignFileCollection designFiles,
|
|
IFileSystem fileSystem,
|
|
string outputDir,
|
|
ITelemetryContext telemetry,
|
|
GeneratorOptions options = null,
|
|
bool useAllowSubtypes = false,
|
|
List<string> identifierFiles = null,
|
|
IReadOnlyDictionary<string, ModelDependencyReference> referencedModels = null,
|
|
IReadOnlyList<NodeManagerAttributeBinding> nodeManagerBindings = null,
|
|
Action<NodeManagerAttributeBinding, string> reportBindingDiagnostic = null)
|
|
{
|
|
if (designFiles.Targets == null || designFiles.Targets.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
options ??= new GeneratorOptions();
|
|
referencedModels ??= ImmutableDictionary<string, ModelDependencyReference>.Empty;
|
|
|
|
// Combine with embedded resources in this assembly.
|
|
fileSystem = typeof(Generators).Assembly
|
|
.AsFileSystem("Opc.Ua.SourceGeneration.Design")
|
|
.WithFallback(fileSystem);
|
|
|
|
HashSet<NodeManagerAttributeBinding> usedBindings = nodeManagerBindings is { Count: > 0 }
|
|
? []
|
|
: null;
|
|
|
|
int totalDesigns = designFiles.Targets.Count;
|
|
|
|
foreach (DesignFileCollection model in designFiles.Group(identifierFiles))
|
|
{
|
|
IModelDesign modelDesign = fileSystem.OpenModelDesign(
|
|
model,
|
|
options.Exclusions,
|
|
telemetry,
|
|
useAllowSubtypes);
|
|
|
|
// Override resolution: if a referenced assembly already
|
|
// provides this model under the same C# prefix, silently
|
|
// skip local generation to avoid duplicate type emission.
|
|
Namespace target = modelDesign.TargetNamespace;
|
|
if (target != null &&
|
|
!string.IsNullOrEmpty(target.Value) &&
|
|
referencedModels.TryGetValue(target.Value,
|
|
out ModelDependencyReference referenced) &&
|
|
string.Equals(referenced.Prefix, target.Prefix,
|
|
StringComparison.Ordinal))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
DesignFileOptions effectiveOptions = ApplyNodeManagerBinding(
|
|
model,
|
|
modelDesign,
|
|
nodeManagerBindings,
|
|
usedBindings,
|
|
totalDesigns,
|
|
reportBindingDiagnostic);
|
|
|
|
Generate(new GeneratorContext
|
|
{
|
|
FileSystem = fileSystem,
|
|
OutputFolder = outputDir,
|
|
ModelDesign = modelDesign,
|
|
Telemetry = telemetry,
|
|
Options = options,
|
|
ReferencedModels = referencedModels
|
|
},
|
|
validateSchemas: false,
|
|
designOptions: effectiveOptions);
|
|
}
|
|
|
|
if (usedBindings != null && nodeManagerBindings != null && reportBindingDiagnostic != null)
|
|
{
|
|
foreach (NodeManagerAttributeBinding binding in nodeManagerBindings)
|
|
{
|
|
if (!usedBindings.Contains(binding))
|
|
{
|
|
string selector = !string.IsNullOrEmpty(binding.NamespaceUri)
|
|
? "NamespaceUri='" + binding.NamespaceUri + "'"
|
|
: !string.IsNullOrEmpty(binding.Design)
|
|
? "Design='" + binding.Design + "'"
|
|
: "(no selector)";
|
|
reportBindingDiagnostic(
|
|
binding,
|
|
"[NodeManager] on '" +
|
|
binding.TargetNamespace +
|
|
"." +
|
|
binding.TargetClassName +
|
|
"' did not match any model design (" +
|
|
selector +
|
|
").");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resolve the effective per-design options by overlaying any
|
|
/// matching <c>[NodeManager]</c> attribute binding on top of the
|
|
/// existing <see cref="DesignFileCollection.Options"/>.
|
|
/// </summary>
|
|
private static DesignFileOptions ApplyNodeManagerBinding(
|
|
DesignFileCollection model,
|
|
IModelDesign modelDesign,
|
|
IReadOnlyList<NodeManagerAttributeBinding> bindings,
|
|
HashSet<NodeManagerAttributeBinding> usedBindings,
|
|
int totalDesigns,
|
|
Action<NodeManagerAttributeBinding, string> reportBindingDiagnostic)
|
|
{
|
|
DesignFileOptions effective = model.Options;
|
|
if (bindings == null || bindings.Count == 0)
|
|
{
|
|
return effective;
|
|
}
|
|
|
|
string uri = modelDesign?.TargetNamespace?.Value;
|
|
string designName = model.Targets.Count == 1
|
|
? System.IO.Path.GetFileNameWithoutExtension(model.Targets[0])
|
|
: null;
|
|
|
|
NodeManagerAttributeBinding match = null;
|
|
// 1) exact URI match
|
|
if (!string.IsNullOrEmpty(uri))
|
|
{
|
|
match = bindings.FirstOrDefault(b =>
|
|
string.Equals(b.NamespaceUri, uri, StringComparison.Ordinal));
|
|
}
|
|
// 2) design file name match
|
|
if (match == null && !string.IsNullOrEmpty(designName))
|
|
{
|
|
match = bindings.FirstOrDefault(b =>
|
|
!string.IsNullOrEmpty(b.Design) &&
|
|
string.Equals(b.Design, designName, StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
// 3) single-design / single-binding fallback
|
|
if (match == null &&
|
|
totalDesigns == 1 &&
|
|
bindings.Count == 1 &&
|
|
string.IsNullOrEmpty(bindings[0].NamespaceUri) &&
|
|
string.IsNullOrEmpty(bindings[0].Design))
|
|
{
|
|
match = bindings[0];
|
|
}
|
|
|
|
if (match == null)
|
|
{
|
|
return effective;
|
|
}
|
|
|
|
// Detect ambiguity: multiple designs but binding has no selector.
|
|
if (totalDesigns > 1 &&
|
|
string.IsNullOrEmpty(match.NamespaceUri) &&
|
|
string.IsNullOrEmpty(match.Design) &&
|
|
reportBindingDiagnostic != null)
|
|
{
|
|
reportBindingDiagnostic(
|
|
match,
|
|
"[NodeManager] on '" +
|
|
match.TargetNamespace +
|
|
"." +
|
|
match.TargetClassName +
|
|
"' has no NamespaceUri/Design selector but the project " +
|
|
"contains multiple designs. Specify NamespaceUri to " +
|
|
"disambiguate.");
|
|
return effective;
|
|
}
|
|
|
|
usedBindings?.Add(match);
|
|
|
|
return (effective ?? new DesignFileOptions()) with
|
|
{
|
|
GenerateNodeManager = true,
|
|
NodeManagerNamespace = match.TargetNamespace,
|
|
NodeManagerClassName = match.TargetClassName,
|
|
EmitNodeManagerFactory = match.GenerateFactory
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generate from nodesets
|
|
/// </summary>
|
|
/// <param name="nodesets">Nodesets to process</param>
|
|
/// <param name="fileSystem">File system abstraction to use</param>
|
|
/// <param name="outputDir">Output folder or null</param>
|
|
/// <param name="telemetry">Telemetry context for logging</param>
|
|
/// <param name="options">Generator options</param>
|
|
/// <param name="useAllowSubtypes">allow subtypes</param>
|
|
/// <param name="referencedModels">Models supplied by referenced
|
|
/// assemblies (keyed by model URI). When a target's model URI
|
|
/// is in this map the nodeset is skipped (referenced assembly
|
|
/// already supplies the types). Transitive nodeset dependencies
|
|
/// found in the map are also satisfied without erroring.</param>
|
|
/// <param name="nodeManagerBindings">
|
|
/// Optional <c>[NodeManager]</c> attribute bindings discovered in
|
|
/// the consuming compilation. When supplied, each binding is
|
|
/// matched to a nodeset model by
|
|
/// <see cref="NodeManagerAttributeBinding.NamespaceUri"/> (preferred)
|
|
/// or, if no URI is given, by single-design fallback. Matched
|
|
/// bindings force <c>GenerateNodeManager = true</c> for the model
|
|
/// and override the manager class name and namespace.
|
|
/// </param>
|
|
/// <param name="reportBindingDiagnostic">
|
|
/// Optional callback invoked for each binding-related warning or
|
|
/// error (e.g. unmatched URI, ambiguous fallback).
|
|
/// </param>
|
|
public static void GenerateCode(
|
|
this NodesetFileCollection nodesets,
|
|
IFileSystem fileSystem,
|
|
string outputDir,
|
|
ITelemetryContext telemetry,
|
|
GeneratorOptions options = null,
|
|
bool useAllowSubtypes = false,
|
|
IReadOnlyDictionary<string, ModelDependencyReference> referencedModels = null,
|
|
IReadOnlyList<NodeManagerAttributeBinding> nodeManagerBindings = null,
|
|
Action<NodeManagerAttributeBinding, string> reportBindingDiagnostic = null)
|
|
{
|
|
if (nodesets.Files.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
options ??= new GeneratorOptions();
|
|
referencedModels ??= ImmutableDictionary<string, ModelDependencyReference>.Empty;
|
|
|
|
// Combine with embedded resources in this assembly.
|
|
fileSystem = typeof(Generators).Assembly
|
|
.AsFileSystem("Opc.Ua.SourceGeneration.Design")
|
|
.WithFallback(fileSystem);
|
|
|
|
HashSet<NodeManagerAttributeBinding> usedBindings = nodeManagerBindings is { Count: > 0 }
|
|
? []
|
|
: null;
|
|
|
|
int totalDesigns = nodesets.ModelUris.Count();
|
|
|
|
foreach (string modelUri in nodesets.ModelUris)
|
|
{
|
|
List<string> designFilesForModel =
|
|
nodesets.GetDesignFileListForModel(
|
|
modelUri,
|
|
out NodesetFile nodeset,
|
|
referencedModels);
|
|
if (designFilesForModel == null || nodeset.Info.Ignore)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Override resolution: if a referenced assembly already
|
|
// provides this model under the same C# prefix, silently
|
|
// skip local generation to avoid duplicate type emission.
|
|
if (referencedModels.TryGetValue(modelUri,
|
|
out ModelDependencyReference referenced) &&
|
|
string.Equals(referenced.Prefix, nodeset.Info.Prefix,
|
|
StringComparison.Ordinal))
|
|
{
|
|
continue;
|
|
}
|
|
// The rest of the input is processed as design files
|
|
var model = new DesignFileCollection
|
|
{
|
|
Targets = designFilesForModel
|
|
};
|
|
IModelDesign modelDesign = fileSystem.OpenModelDesign(
|
|
model,
|
|
options.Exclusions,
|
|
telemetry,
|
|
useAllowSubtypes);
|
|
|
|
DesignFileOptions effectiveOptions = ApplyNodeManagerBinding(
|
|
model,
|
|
modelDesign,
|
|
nodeManagerBindings,
|
|
usedBindings,
|
|
totalDesigns,
|
|
reportBindingDiagnostic);
|
|
|
|
Generate(new GeneratorContext
|
|
{
|
|
FileSystem = fileSystem,
|
|
OutputFolder = outputDir,
|
|
ModelDesign = modelDesign,
|
|
Telemetry = telemetry,
|
|
Options = options,
|
|
ReferencedModels = referencedModels
|
|
},
|
|
validateSchemas: false,
|
|
designOptions: effectiveOptions);
|
|
// TODO {
|
|
// TODO AvailableNodeSets = nodesets.Files
|
|
// TODO };
|
|
}
|
|
|
|
if (usedBindings != null && nodeManagerBindings != null && reportBindingDiagnostic != null)
|
|
{
|
|
foreach (NodeManagerAttributeBinding binding in nodeManagerBindings)
|
|
{
|
|
if (!usedBindings.Contains(binding))
|
|
{
|
|
string selector = !string.IsNullOrEmpty(binding.NamespaceUri)
|
|
? "NamespaceUri='" + binding.NamespaceUri + "'"
|
|
: !string.IsNullOrEmpty(binding.Design)
|
|
? "Design='" + binding.Design + "'"
|
|
: "(no selector)";
|
|
reportBindingDiagnostic(
|
|
binding,
|
|
"[NodeManager] on '" +
|
|
binding.TargetNamespace +
|
|
"." +
|
|
binding.TargetClassName +
|
|
"' did not match any model design (" +
|
|
selector +
|
|
").");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generate the .net stack code
|
|
/// </summary>
|
|
/// <param name="generatorType">Generator type</param>
|
|
/// <param name="fileSystem">The root file system to use</param>
|
|
/// <param name="outputDir">Output folder or null</param>
|
|
/// <param name="telemetry">A telemetry context for logging</param>
|
|
/// <param name="options">Generator options</param>
|
|
public static void GenerateStack(
|
|
StackGenerationType generatorType,
|
|
IFileSystem fileSystem,
|
|
string outputDir,
|
|
ITelemetryContext telemetry,
|
|
GeneratorOptions options = null)
|
|
{
|
|
options ??= new GeneratorOptions();
|
|
// Combine with embedded resources in this assembly.
|
|
fileSystem = typeof(Generators).Assembly
|
|
.AsFileSystem("Opc.Ua.SourceGeneration.Design")
|
|
.WithFallback(fileSystem);
|
|
|
|
IModelDesign modelDesign = fileSystem.OpenModelDesign(
|
|
new DesignFileCollection
|
|
{
|
|
Targets =
|
|
[
|
|
BuiltInDesignFiles.StandardTypesXml,
|
|
BuiltInDesignFiles.UACoreServicesXml
|
|
],
|
|
IdentifierFilePath = BuiltInDesignFiles.StandardTypesCsv,
|
|
Options = new DesignFileOptions
|
|
{
|
|
StartId = 0,
|
|
ModelVersion = "1.05.06",
|
|
ModelPublicationDate = "2025-11-08",
|
|
ReleaseCandidate = true
|
|
}
|
|
},
|
|
options.Exclusions,
|
|
telemetry,
|
|
false);
|
|
|
|
var generatorContext = new GeneratorContext
|
|
{
|
|
FileSystem = fileSystem,
|
|
OutputFolder = outputDir,
|
|
ModelDesign = modelDesign,
|
|
Telemetry = telemetry,
|
|
Options = options
|
|
};
|
|
if ((generatorType & StackGenerationType.Stack) != 0)
|
|
{
|
|
var clientApiGenerator = new ClientApiGenerator(generatorContext);
|
|
clientApiGenerator.Emit();
|
|
var serverApiGenerator = new ServerApiGenerator(generatorContext);
|
|
serverApiGenerator.Emit();
|
|
var endpointsGenerator = new EndpointsGenerator(generatorContext);
|
|
endpointsGenerator.Emit();
|
|
// Emit ObjectType client proxies for every standard UA
|
|
// ObjectType so downstream model proxies (e.g. GDS) can
|
|
// derive from them. Proxies are emitted into the model's
|
|
// own namespace (Opc.Ua for the standard NodeSet) — no
|
|
// namespace override. Suppressed when the consumer opts
|
|
// out via OmitObjectTypeProxies.
|
|
if (!options.OmitObjectTypeProxies)
|
|
{
|
|
var stackProxyContext = new GeneratorContext
|
|
{
|
|
FileSystem = generatorContext.FileSystem,
|
|
OutputFolder = generatorContext.OutputFolder,
|
|
ModelDesign = generatorContext.ModelDesign,
|
|
Telemetry = generatorContext.Telemetry,
|
|
Options = new GeneratorOptions
|
|
{
|
|
OptimizeForCompileSpeed = options.OptimizeForCompileSpeed,
|
|
Exclusions = options.Exclusions,
|
|
Cancellation = options.Cancellation,
|
|
UseUtf8StringLiterals = options.UseUtf8StringLiterals
|
|
}
|
|
};
|
|
var stackProxyGenerator = new ObjectTypeProxyGenerator(stackProxyContext);
|
|
stackProxyGenerator.Emit();
|
|
}
|
|
|
|
// Emit event-record records for every standard UA
|
|
// event type. Records reference EventRecord (in
|
|
// Opc.Ua.Core) so they are only emitted in the Stack
|
|
// path (which runs against Opc.Ua.Core), not in the
|
|
// Models path (which runs against Opc.Ua.Core.Types).
|
|
var stackRecordContext = new GeneratorContext
|
|
{
|
|
FileSystem = generatorContext.FileSystem,
|
|
OutputFolder = generatorContext.OutputFolder,
|
|
ModelDesign = generatorContext.ModelDesign,
|
|
Telemetry = generatorContext.Telemetry,
|
|
Options = new GeneratorOptions
|
|
{
|
|
OptimizeForCompileSpeed = options.OptimizeForCompileSpeed,
|
|
Exclusions = options.Exclusions,
|
|
Cancellation = options.Cancellation,
|
|
UseUtf8StringLiterals = options.UseUtf8StringLiterals
|
|
}
|
|
};
|
|
var stackRecordGenerator = new EventRecordGenerator(stackRecordContext);
|
|
stackRecordGenerator.Emit();
|
|
}
|
|
|
|
if ((generatorType & StackGenerationType.Models) != 0)
|
|
{
|
|
var attributesGenerator = new AttributesGenerator(generatorContext);
|
|
attributesGenerator.Emit();
|
|
var statusCodesGenerator = new StatusCodesGenerator(generatorContext);
|
|
statusCodesGenerator.Emit();
|
|
var serverCapabilitiesGenerator = new ServerCapabilitiesGenerator(generatorContext);
|
|
serverCapabilitiesGenerator.Emit();
|
|
|
|
Generate(generatorContext, !options.OptimizeForCompileSpeed);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generates all files
|
|
/// </summary>
|
|
private static void Generate(
|
|
GeneratorContext context,
|
|
bool validateSchemas = false,
|
|
DesignFileOptions designOptions = null)
|
|
{
|
|
// Generate schemas
|
|
var xmlSchemaGenerator = new XmlSchemaGenerator(context)
|
|
{
|
|
ValidateOutput = validateSchemas
|
|
};
|
|
IEnumerable<Resource> xmlSchemaResource = xmlSchemaGenerator.Emit();
|
|
var binarySchemaGenerator = new BinarySchemaGenerator(context)
|
|
{
|
|
ValidateOutput = validateSchemas
|
|
};
|
|
IEnumerable<Resource> binarySchemaResource = binarySchemaGenerator.Emit();
|
|
var schemaResources = new ResourceGenerator(context);
|
|
schemaResources.Embed(
|
|
context.ModelDesign.TargetNamespace.Prefix,
|
|
"XmlSchemas",
|
|
false,
|
|
[.. binarySchemaResource, .. xmlSchemaResource]);
|
|
|
|
// Must run after schema generation to initilize the dictionaries.
|
|
var constantsGenerator = new ConstantsGenerator(context);
|
|
constantsGenerator.Emit();
|
|
var nodeIdGenerator = new NodeIdGenerator(context);
|
|
nodeIdGenerator.Emit();
|
|
var nodeStateCodeGenerator = new NodeStateGenerator(context);
|
|
nodeStateCodeGenerator.Emit();
|
|
var dataTypesGenerator = new DataTypeGenerator(context);
|
|
dataTypesGenerator.Emit();
|
|
|
|
if (designOptions?.GenerateNodeManager == true)
|
|
{
|
|
new NodeManagerGenerator(context)
|
|
{
|
|
OverrideNamespace = designOptions.NodeManagerNamespace,
|
|
OverrideClassName = designOptions.NodeManagerClassName,
|
|
EmitFactory = designOptions.EmitNodeManagerFactory
|
|
}.Emit();
|
|
|
|
new FluentBuilderGenerator(context)
|
|
{
|
|
OverrideManagerNamespace = designOptions.NodeManagerNamespace,
|
|
OverrideManagerClassName = designOptions.NodeManagerClassName
|
|
}.Emit();
|
|
}
|
|
|
|
if (context.Options?.OmitObjectTypeProxies != true)
|
|
{
|
|
var objectTypeProxyGenerator = new ObjectTypeProxyGenerator(context);
|
|
objectTypeProxyGenerator.Emit();
|
|
}
|
|
// Event records are emitted only in the Stack path (alongside
|
|
// the proxies) because they reference the EventRecord anchor
|
|
// in Opc.Ua.Core. Models (Core.Types) skips them.
|
|
var modelDependencyGenerator = new ModelDependencyGenerator(context);
|
|
modelDependencyGenerator.Emit();
|
|
}
|
|
}
|
|
}
|