Skip to content

feat(OpcUa): implement OPC UA client - #1118

Merged
ArgoZhang merged 11 commits into
masterfrom
chore-ua
Aug 30, 2026
Merged

feat(OpcUa): implement OPC UA client#1118
ArgoZhang merged 11 commits into
masterfrom
chore-ua

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Aug 30, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #1117

Summary By Copilot

  • move the OpcUa project into the extensions directory and register a scoped IOpcUaServer
  • implement asynchronous connection, read, write, browse, and monitored-item subscription APIs
  • support configurable identities, endpoint security, timeouts, certificate stores, and multi-target SDK compatibility
  • manage session and subscription cleanup, cancellation, concurrency, and failed-operation rollback
  • replace server-dependent tests with isolated service, model, guard, and lifecycle tests
  • bump the OpcUa package version to 10.0.1

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

This introduces a new stateful network client and certificate configuration surface. The implementation uses scoped ownership, explicit cancellation, serialized session operations, and deterministic cleanup to limit lifecycle risk.

Verification

  • Manual (required)
  • Automated

dotnet test test\UnitTestOpcUa\UnitTestOpcUa.csproj -f net10.0 --no-restore --nologo --verbosity:minimal passed all 5 tests.

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Implement a production-ready OPC UA client extension with configurable connectivity, data access, browsing, and monitored subscriptions.

New Features:

  • Add a scoped OPC UA client service with asynchronous connection, disconnection, read, write, browse, and subscription operations.
  • Support configurable OPC UA identities, security, certificates, locales, session settings, and operation timeouts.
  • Expose OPC UA read, write, browse, connection, and subscription models for application integration.

Enhancements:

  • Serialize client session operations and provide deterministic cleanup for sessions, subscriptions, cancellation, and failed subscription creation.

Build:

  • Move the OPC UA extension into the extensions directory and update project and solution registration.
  • Update the OPC UA package version to 10.0.1.

Tests:

  • Replace server-dependent OPC UA tests with isolated coverage for service registration, models, validation, connection options, and disposal.

@bb-auto bb-auto Bot added the enhancement New feature or request label Aug 30, 2026
@bb-auto bb-auto Bot added this to the v10.0.0 milestone Aug 30, 2026
@sourcery-ai

sourcery-ai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces a multi-target OPC UA client extension with scoped DI registration, asynchronous session/read/write/browse APIs, configurable security and identities, monitored subscriptions, serialized lifecycle management, deterministic cleanup, and isolated automated coverage; the package is relocated to extensions and versioned 10.0.1.

Sequence diagram for OPC UA connection and operations

sequenceDiagram
    participant Consumer
    participant IOpcUaServer
    participant OpcUaServer
    participant OpcUaSdk

    Consumer->>IOpcUaServer: ConnectAsync(endpointUrl, options, cancellationToken)
    IOpcUaServer->>OpcUaServer: ConnectAsync(endpointUrl, options, cancellationToken)
    OpcUaServer->>OpcUaSdk: SelectEndpointAsync(...)
    OpcUaServer->>OpcUaSdk: CreateAsync(...)
    OpcUaSdk-->>OpcUaServer: Connected session
    OpcUaServer-->>Consumer: true

    Consumer->>IOpcUaServer: ReadAsync(nodeIds, cancellationToken)
    IOpcUaServer->>OpcUaServer: ReadAsync(nodeIds, cancellationToken)
    OpcUaServer->>OpcUaSdk: ReadAsync(...)
    OpcUaSdk-->>OpcUaServer: Read results
    OpcUaServer-->>Consumer: IReadOnlyList<OpcUaReadItem>

    Consumer->>IOpcUaServer: WriteAsync(items, cancellationToken)
    IOpcUaServer->>OpcUaServer: WriteAsync(items, cancellationToken)
    OpcUaServer->>OpcUaSdk: WriteAsync(...)
    OpcUaSdk-->>OpcUaServer: Status codes
    OpcUaServer-->>Consumer: IReadOnlyList<OpcUaWriteItem>
Loading

Sequence diagram for monitored OPC UA subscription

sequenceDiagram
    participant Consumer
    participant IOpcUaServer
    participant OpcUaServer
    participant IOpcUaSubscription
    participant OpcUaSdk

    Consumer->>IOpcUaServer: CreateSubscriptionAsync(name, publishingInterval, active, cancellationToken)
    IOpcUaServer->>OpcUaServer: CreateSubscriptionAsync(name, publishingInterval, active, cancellationToken)
    OpcUaServer->>OpcUaSdk: CreateAsync(cancellationToken)
    OpcUaSdk-->>OpcUaServer: Created subscription
    OpcUaServer-->>Consumer: IOpcUaSubscription

    Consumer->>IOpcUaSubscription: AddItemsAsync(nodeIds, samplingInterval, cancellationToken)
    IOpcUaSubscription->>OpcUaSdk: ApplyChangesAsync(cancellationToken)
    OpcUaSdk-->>IOpcUaSubscription: Monitored items active
    OpcUaSdk-->>IOpcUaSubscription: Notification
    IOpcUaSubscription->>IOpcUaSubscription: DataChanged(results)
    IOpcUaSubscription-->>Consumer: Action<IReadOnlyList<OpcUaReadItem>>
Loading

File-Level Changes

Change Details Files
Moved the OPC UA extension into the extensions area and exposed it through scoped dependency injection.
  • Relocated and updated the project and solution registration.
  • Replaced the previous registration method with AddOpcUaServer.
  • Registered IOpcUaServer with scoped OpcUaServer lifetime.
  • Added cross-target argument and disposal guards.
BootstrapBlazor.Extensions.slnx
src/components/BootstrapBlazor.OpcUa/BootstrapBlazor.OpcUa.csproj
src/extensions/BootstrapBlazor.OpcUa/BootstrapBlazor.OpcUa.csproj
src/extensions/BootstrapBlazor.OpcUa/Extensions/ServiceCollectionExtensions.cs
src/extensions/BootstrapBlazor.OpcUa/Guard.cs
Implemented a stateful asynchronous OPC UA client with serialized session lifecycle and operational APIs.
  • Added connect and disconnect flows with endpoint selection, session creation, cancellation, timeouts, identities, locales, and security configuration.
  • Added batched read, write, and browse operations with node parsing and OPC UA response/status validation.
  • Serialized session and subscription operations with a semaphore and rejected operations when disconnected or disposed.
  • Added session replacement, disconnect cleanup, and failed-connection/subscription rollback handling.
src/extensions/BootstrapBlazor.OpcUa/IOpcUaServer.cs
src/extensions/BootstrapBlazor.OpcUa/OpcUaServer.cs
src/extensions/BootstrapBlazor.OpcUa/OpcUaConnectionOptions.cs
src/extensions/BootstrapBlazor.OpcUa/OpcUaBrowseOptions.cs
src/extensions/BootstrapBlazor.OpcUa/OpcUaBrowseElement.cs
src/extensions/BootstrapBlazor.OpcUa/OpcUaReadItem.cs
src/extensions/BootstrapBlazor.OpcUa/OpcUaWriteItem.cs
Added monitored-item subscription support with callback delivery and optional previous-value tracking.
  • Created and cancelled named subscriptions with publishing interval and active-state configuration.
  • Added monitored nodes with sampling intervals and ApplyChangesAsync rollback on failure.
  • Mapped notifications to read-result models and optionally populated LastValue.
  • Detached handlers and disposed subscription resources during cancellation and client teardown.
src/extensions/BootstrapBlazor.OpcUa/IOpcUaSubscription.cs
src/extensions/BootstrapBlazor.OpcUa/OpcUaSubscription.cs
src/extensions/BootstrapBlazor.OpcUa/OpcUaServer.cs
Reworked tests around isolated registration, validation, models, and disposal behavior instead of requiring a live OPC UA server.
  • Verified scoped service identity and disconnected-operation failures.
  • Covered model status helpers, disposal behavior, and connection-option validation.
  • Updated test project references for the relocated extension and new package version.
test/UnitTestOpcUa/UnitTest1.cs
test/UnitTestOpcUa/UnitTestOpcUa.csproj
src/extensions/BootstrapBlazor.OpcUa/BootstrapBlazor.OpcUa.csproj

Assessment against linked issues

Issue Objective Addressed Explanation
#1117 Implement a scoped OPC UA client service that supports asynchronous connection and disconnection, node reading and writing, browsing, and OPC UA status codes and timestamps.
#1117 Implement monitored-item subscriptions with data-change callbacks and deterministic session, subscription, cancellation, concurrency, and failure-cleanup lifecycle management.
#1117 Provide configurable security, identity, timeouts, certificate stores, cross-target support, and isolated unit tests that do not require a local OPC UA server, while registering the service through dependency injection.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved by bb-auto

@ArgoZhang
ArgoZhang merged commit 02cb93c into master Aug 30, 2026
3 checks passed
@ArgoZhang
ArgoZhang deleted the chore-ua branch August 30, 2026 01:49

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(OpcUa): implement OPC UA client

1 participant