Files
Marc Schier 01d7162313 Part 9 Alarms & Conditions: complete server + client implementation (#3805)
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`.
2026-05-29 23:24:53 +02:00

232 lines
16 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
{
internal static class Tokens
{
public static string ArrayDimensions => nameof(ArrayDimensions);
public static string BaseClassName => nameof(BaseClassName);
public static string BaseInterfaces => nameof(BaseInterfaces);
public static string BaseType => nameof(BaseType);
public static string BaseTypeNamespacePrefix => nameof(BaseTypeNamespacePrefix);
public static string BaseTypeNamespaceUri => nameof(BaseTypeNamespaceUri);
public static string BinaryEncodingId => nameof(BinaryEncodingId);
public static string BrowseName => nameof(BrowseName);
public static string BrowseNameNamespacePrefix => nameof(BrowseNameNamespacePrefix);
public static string BrowseNameNamespaceUri => nameof(BrowseNameNamespaceUri);
public static string BrowseNameSymbol => nameof(BrowseNameSymbol);
public static string SymbolicNameSymbol => nameof(SymbolicNameSymbol);
public static string BuiltInTypes => nameof(BuiltInTypes);
public static string ChildDataType => nameof(ChildDataType);
public static string ValueWrite => nameof(ValueWrite);
public static string ValueComparison => nameof(ValueComparison);
public static string ChildName => nameof(ChildName);
public static string ChildPath => nameof(ChildPath);
public static string ClassName => nameof(ClassName);
public static string ClassFactory => nameof(ClassFactory);
public static string ClientApi => nameof(ClientApi);
public static string ClientMethod => nameof(ClientMethod);
public static string CodeName => nameof(CodeName);
public static string CollectionType => nameof(CollectionType);
public static string DataType => nameof(DataType);
public static string StructureType => nameof(StructureType);
public static string FirstExplicitFieldIndex => nameof(FirstExplicitFieldIndex);
public static string DataTypeNamespacePrefix => nameof(DataTypeNamespacePrefix);
public static string DataTypeNamespaceUri => nameof(DataTypeNamespaceUri);
public static string DefaultValue => nameof(DefaultValue);
public static string Description => nameof(Description);
public static string DictionaryUri => nameof(DictionaryUri);
public static string Documentation => nameof(Documentation);
public static string EmitDefaultValue => nameof(EmitDefaultValue);
public static string EncodingMaskModifier => nameof(EncodingMaskModifier);
public static string EnumerationName => nameof(EnumerationName);
public static string EventNotifier => nameof(EventNotifier);
public static string FieldIndex => nameof(FieldIndex);
public static string ExtraInterfaces => nameof(ExtraInterfaces);
public static string FieldName => nameof(FieldName);
public static string ListOfChildOperations => nameof(ListOfChildOperations);
public static string Historizing => nameof(Historizing);
public static string Identifier => nameof(Identifier);
public static string IdType => nameof(IdType);
public static string Imports => nameof(Imports);
public static string InitializeOptionalChildren => nameof(InitializeOptionalChildren);
public static string InvokeServiceAsync => nameof(InvokeServiceAsync);
public static string Purpose => nameof(Purpose);
public static string IsAbstract => nameof(IsAbstract);
public static string IsOptionSet => nameof(IsOptionSet);
public static string IsRequired => nameof(IsRequired);
public static string LengthInBits => nameof(LengthInBits);
public static string ListOfBrowseNames => nameof(ListOfBrowseNames);
public static string ListOfChildInitializers => nameof(ListOfChildInitializers);
public static string ListOfChildMethods => nameof(ListOfChildMethods);
public static string ListOfClonedFields => nameof(ListOfClonedFields);
public static string ListOfAppendStringFields => nameof(ListOfAppendStringFields);
public static string ListOfComparedFields => nameof(ListOfComparedFields);
public static string ListOfDecodedFields => nameof(ListOfDecodedFields);
public static string ListOfEncodedFields => nameof(ListOfEncodedFields);
public static string ListOfEncodingMaskFields => nameof(ListOfEncodingMaskFields);
public static string ListOfFieldInitializers => nameof(ListOfFieldInitializers);
public static string ListOfFields => nameof(ListOfFields);
public static string ListOfSwitchFieldNames => nameof(ListOfSwitchFieldNames);
public static string ListOfEncodingMaskFieldNames => nameof(ListOfEncodingMaskFieldNames);
public static string ListOfFindChildCase => nameof(ListOfFindChildCase);
public static string ListOfFindChildren => nameof(ListOfFindChildren);
public static string ListOfIdentifiers => nameof(ListOfIdentifiers);
public static string ListOfIdentifersToNames => nameof(ListOfIdentifersToNames);
public static string ListOfNamesToIdentifiers => nameof(ListOfNamesToIdentifiers);
public static string ListOfImports => nameof(ListOfImports);
public static string ListOfInputArguments => nameof(ListOfInputArguments);
public static string ListOfNamespaceUris => nameof(ListOfNamespaceUris);
public static string ListOfNodeIds => nameof(ListOfNodeIds);
public static string ListOfOutputArguments => nameof(ListOfOutputArguments);
public static string ListOfOutputArgumentsFromResult => nameof(ListOfOutputArgumentsFromResult);
public static string ListOfOutputDeclarations => nameof(ListOfOutputDeclarations);
public static string ListOfProperties => nameof(ListOfProperties);
public static string ListOfNonMandatoryChildren => nameof(ListOfNonMandatoryChildren);
public static string ListOfRemoveChild => nameof(ListOfRemoveChild);
public static string ListOfChildCopies => nameof(ListOfChildCopies);
public static string ListOfChildHashes => nameof(ListOfChildHashes);
public static string ListOfEqualityComparers => nameof(ListOfEqualityComparers);
public static string ListOfCreateOrReplaceChild => nameof(ListOfCreateOrReplaceChild);
public static string ListOfResultProperties => nameof(ListOfResultProperties);
public static string ListOfSwitchFields => nameof(ListOfSwitchFields);
public static string ListOfTypes => nameof(ListOfTypes);
public static string ListOfTypeActivators => nameof(ListOfTypeActivators);
public static string ListOfDataTypeDefinitions => nameof(ListOfDataTypeDefinitions);
public static string ListOfUpdateChildrenChangeMasks => nameof(ListOfUpdateChildrenChangeMasks);
public static string ListOfValues => nameof(ListOfValues);
public static string ListOfActivatorRegistrations => nameof(ListOfActivatorRegistrations);
public static string ListOfChildren => nameof(ListOfChildren);
public static string MethodList => nameof(MethodList);
public static string Name => nameof(Name);
public static string IsOptional => nameof(IsOptional);
public static string Namespace => nameof(Namespace);
public static string NamespacePrefix => nameof(NamespacePrefix);
public static string NamespaceUri => nameof(NamespaceUri);
public static string NodeManagerClassName => nameof(NodeManagerClassName);
public static string NodeManagerFactoryClassName => nameof(NodeManagerFactoryClassName);
public static string Nillable => nameof(Nillable);
public static string NodeClass => nameof(NodeClass);
public static string OnCallAsyncDeclaration => nameof(OnCallAsyncDeclaration);
public static string OnCallAsyncImplementation => nameof(OnCallAsyncImplementation);
public static string OnCallDeclaration => nameof(OnCallDeclaration);
public static string OnCallImplementation => nameof(OnCallImplementation);
public static string Prefix => nameof(Prefix);
public static string PropertyName => nameof(PropertyName);
public static string RequestParameters => nameof(RequestParameters);
public static string ResponseParameters => nameof(ResponseParameters);
public static string ServerApi => nameof(ServerApi);
public static string ServerStubs => nameof(ServerStubs);
public static string ServiceSet => nameof(ServiceSet);
public static string ServiceSets => nameof(ServiceSets);
public static string SymbolicId => nameof(SymbolicId);
public static string SymbolicName => nameof(SymbolicName);
public static string TypedVariableType => nameof(TypedVariableType);
public static string TypeName => nameof(TypeName);
public static string ValueRank => nameof(ValueRank);
public static string VariableTypeValue => nameof(VariableTypeValue);
public static string Version => nameof(Version);
public static string Tool => nameof(Tool);
public static string XmlEncodingId => nameof(XmlEncodingId);
public static string VariantFrom => nameof(VariantFrom);
public static string VariantTryGet => nameof(VariantTryGet);
public static string XmlIdentifier => nameof(XmlIdentifier);
public static string XmlNamespaceUri => nameof(XmlNamespaceUri);
public static string XmlnsS0ListOfNamespaces => nameof(XmlnsS0ListOfNamespaces);
public static string TypeList => nameof(TypeList);
public static string BasicType => nameof(BasicType);
public static string Flags => nameof(Flags);
public static string AddKnownType => nameof(AddKnownType);
public static string ModelUri => nameof(ModelUri);
public static string TargetPublicationDate => nameof(TargetPublicationDate);
public static string TargetVersion => nameof(TargetVersion);
public static string BaseT => nameof(BaseT);
public static string XsRestrictionBaseType => nameof(XsRestrictionBaseType);
public static string AccessorSymbol => nameof(AccessorSymbol);
public static string ServerMethodAsync => nameof(ServerMethodAsync);
public static string ClientMethodAsync => nameof(ClientMethodAsync);
public static string ClientMethodSync => nameof(ClientMethodSync);
public static string ClientMethodBegin => nameof(ClientMethodBegin);
public static string ClientMethodEnd => nameof(ClientMethodEnd);
public static string CodeHeader => nameof(CodeHeader);
public static string XmlHeader => nameof(XmlHeader);
public static string ResourceName => nameof(ResourceName);
public static string Resource => nameof(Resource);
public static string ListOfResourceGroups => nameof(ListOfResourceGroups);
public static string ListOfResourceDeclarations => nameof(ListOfResourceDeclarations);
public static string ListOfModelDependencies => nameof(ListOfModelDependencies);
public static string ModelVersion => nameof(ModelVersion);
public static string ModelPublicationDate => nameof(ModelPublicationDate);
public static string AccessModifier => nameof(AccessModifier);
public static string IdentifierReflection => nameof(IdentifierReflection);
public static string ListOfNodeStateInitializers => nameof(ListOfNodeStateInitializers);
public static string ListOfNodeStateTypeFactories => nameof(ListOfNodeStateTypeFactories);
public static string ListOfNodeStateInstanceFactories => nameof(ListOfNodeStateInstanceFactories);
public static string ListOfChildNodeStates => nameof(ListOfChildNodeStates);
public static string ListOfOptionalChildNodeStates => nameof(ListOfOptionalChildNodeStates);
public static string ListOfReferences => nameof(ListOfReferences);
public static string NodeIdConstant => nameof(NodeIdConstant);
public static string SuperTypeId => nameof(SuperTypeId);
public static string TypeDefinitionId => nameof(TypeDefinitionId);
public static string ReferenceTypeId => nameof(ReferenceTypeId);
public static string ModellingRuleId => nameof(ModellingRuleId);
public static string StateClassName => nameof(StateClassName);
public static string StateClassFactory => nameof(StateClassFactory);
public static string DisplayName => nameof(DisplayName);
public static string DataTypeDefinition => nameof(DataTypeDefinition);
public static string DescriptionValue => nameof(DescriptionValue);
public static string ValueCode => nameof(ValueCode);
public static string DataTypeIdConstant => nameof(DataTypeIdConstant);
public static string InverseNameValue => nameof(InverseNameValue);
public static string SymmetricValue => nameof(SymmetricValue);
public static string ReleaseStatusValue => nameof(ReleaseStatusValue);
public static string CategoriesValue => nameof(CategoriesValue);
public static string SpecificationValue => nameof(SpecificationValue);
public static string WriteMaskValue => nameof(WriteMaskValue);
public static string UserWriteMaskValue => nameof(UserWriteMaskValue);
public static string NumericIdValue => nameof(NumericIdValue);
public static string AccessRestrictionsValue => nameof(AccessRestrictionsValue);
public static string ListOfRolePermissions => nameof(ListOfRolePermissions);
public static string RoleIdConstant => nameof(RoleIdConstant);
public static string PermissionsValue => nameof(PermissionsValue);
public static string ContainsNoLoopsValue => nameof(ContainsNoLoopsValue);
public static string ExecutableValue => nameof(ExecutableValue);
public static string MethodDeclarationId => nameof(MethodDeclarationId);
public static string MinimumSamplingIntervalValue => nameof(MinimumSamplingIntervalValue);
public static string HistorizingValue => nameof(HistorizingValue);
public static string AccessLevelValue => nameof(AccessLevelValue);
public static string UserAccessLevelValue => nameof(UserAccessLevelValue);
public static string ListOfInitOnlyBackingFields => nameof(ListOfInitOnlyBackingFields);
public static string ListOfPooledExtensions => nameof(ListOfPooledExtensions);
public static string ListOfFieldResets => nameof(ListOfFieldResets);
}
}