Skip to content

refactor(Opc): rename server services to clients - #1120

Merged
ArgoZhang merged 6 commits into
masterfrom
dev-opc
Aug 30, 2026
Merged

refactor(Opc): rename server services to clients#1120
ArgoZhang merged 6 commits into
masterfrom
dev-opc

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Aug 30, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #1119

Summary By Copilot

  • rename OpcUa service APIs from Server to Client terminology
  • add IOpcDaClient, OpcDaClient, and AddOpcDaClient
  • retain obsolete OpcDa server-named APIs through an isolated compatibility implementation
  • align OpcDa XML documentation with the bilingual OpcUa style
  • update OpcDa and OpcUa tests for the client API names
  • bump the OpcDa package version to 10.0.2

Regression?

  • Yes
  • No

Existing OpcDa consumers can continue using IOpcDaServer and AddOpcDaServer, which now provide migration guidance through Obsolete attributes.

Risk

  • High
  • Medium
  • Low

The change is primarily API naming and documentation. The OpcDa compatibility path resolves the same implementation behavior without compiler warnings inside the package.

Verification

  • Manual (required)

  • Automated

  • built BootstrapBlazor.OpcDa and UnitTestOpcDa for net10.0 with no warnings or errors

  • built BootstrapBlazor.OpcUa for all target frameworks with no warnings or errors

  • passed all 5 UnitTestOpcUa tests on net10.0

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

Rename OPC DA and OPC UA service APIs from server to client terminology while preserving an obsolete OpcDa compatibility path for existing consumers.

New Features:

  • Introduce client-oriented OpcDa APIs through IOpcDaClient, OpcDaClient, and AddOpcDaClient.
  • Rename the OpcUa service API and implementation to client terminology.

Enhancements:

  • Retain the former OpcDa server-named APIs as obsolete compatibility interfaces and registrations with migration guidance.
  • Align OpcDa public API documentation with bilingual Chinese and English formatting.

Build:

  • Bump the BootstrapBlazor.OpcDa package version to 10.0.2.

Documentation:

  • Update OpcDa API documentation to describe client terminology and provide bilingual descriptions.

Tests:

  • Update OpcDa and OpcUa tests to validate the renamed client APIs.

@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

@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

@sourcery-ai

sourcery-ai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR standardizes OPC service terminology around clients across OpcDa and OpcUa, implements the new client-facing APIs and registrations, preserves OpcDa server-named consumers through obsolete compatibility types, updates bilingual documentation, bumps the OpcDa package version, and migrates the tests.

File-Level Changes

Change Details Files
Introduces the client-oriented OpcDa API while preserving the existing server-oriented API as an obsolete compatibility layer.
  • Adds IOpcDaClient and the OpcDaClient implementation with the existing connection, subscription, read/write, browse, and disposal behavior.
  • Registers the new client implementation through AddOpcDaClient using singleton services.
  • Makes IOpcDaServer, OpcDaServer, and AddOpcDaServer obsolete adapters that reuse the client implementation and provide migration guidance.
  • Updates the OpcDa package version to 10.0.2.
src/extensions/BootstrapBlazor.OpcDa/BootstrapBlazor.OpcDa.csproj
src/extensions/BootstrapBlazor.OpcDa/IOpcDaClient.cs
src/extensions/BootstrapBlazor.OpcDa/OpcDaClient.cs
src/extensions/BootstrapBlazor.OpcDa/IOpcDaServer.cs
src/extensions/BootstrapBlazor.OpcDa/OpcDaServer.cs
src/extensions/BootstrapBlazor.OpcDa/Extensions/ServiceCollectionExtensions.cs
Renames the OpcUa public service API and implementation from Server to Client.
  • Renames IOpcUaServer to IOpcUaClient and OpcUaServer to OpcUaClient.
  • Renames AddOpcUaServer to AddOpcUaClient and updates dependency injection registration.
  • Updates OpcUa tests to validate the renamed API and retain scoped lifetime and behavioral assertions.
src/extensions/BootstrapBlazor.OpcUa/Extensions/ServiceCollectionExtensions.cs
src/extensions/BootstrapBlazor.OpcUa/IOpcUaClient.cs
src/extensions/BootstrapBlazor.OpcUa/OpcUaClient.cs
test/UnitTestOpcUa/UnitTest1.cs
Aligns OpcDa public XML documentation with the bilingual documentation style used by the newer client APIs.
  • Adds Chinese and English documentation to interfaces, models, enums, members, and extension methods.
  • Reclassifies server terminology in the compatibility API while retaining OPC Server terminology where it describes the underlying OPC DA endpoint.
src/extensions/BootstrapBlazor.OpcDa/Extensions/Extensions.cs
src/extensions/BootstrapBlazor.OpcDa/Extensions/ServiceCollectionExtensions.cs
src/extensions/BootstrapBlazor.OpcDa/IOpcItem.cs
src/extensions/BootstrapBlazor.OpcDa/IOpcSubscription.cs
src/extensions/BootstrapBlazor.OpcDa/OpcBrowseElement.cs
src/extensions/BootstrapBlazor.OpcDa/OpcBrowseFilterType.cs
src/extensions/BootstrapBlazor.OpcDa/OpcBrowseFilters.cs
src/extensions/BootstrapBlazor.OpcDa/OpcBrowsePosition.cs
src/extensions/BootstrapBlazor.OpcDa/OpcItemEqualityComparer.cs
src/extensions/BootstrapBlazor.OpcDa/OpcReadItem.cs
src/extensions/BootstrapBlazor.OpcDa/OpcWriteItem.cs
src/extensions/BootstrapBlazor.OpcDa/Quality.cs
Migrates OpcDa tests to the new client naming and registration path.
  • Replaces AddOpcDaServer and IOpcDaServer usage with AddOpcDaClient and IOpcDaClient in integration tests.
  • Continues covering read/write, subscription, and browse operations.
test/UnitTestOpcDa/UnitTest1.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#1119 Rename the OpcUa dependency-injection and service APIs from server terminology to IOpcUaClient, OpcUaClient, and AddOpcUaClient.
#1119 Add the OpcDa client API with IOpcDaClient, OpcDaClient, and AddOpcDaClient while retaining the existing server-named API as an obsolete compatibility layer with migration guidance.
#1119 Align OpcDa XML documentation with the bilingual OpcUa documentation style, update tests, and bump the OpcDa package version.

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

@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 found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/extensions/BootstrapBlazor.OpcDa/OpcDaClient.cs" line_range="49-54" />
<code_context>
+    }
+
+    /// <inheritdoc/>
+    public void Disconnect()
+    {
+        ServerName = string.Empty;
+
+        if (_server is { IsConnected: true })
+        {
+            foreach (Subscription sub in _server.Subscriptions)
+            {
+                _server.CancelSubscription(sub);
+            }
+
+            _server.Disconnect();
+            _server = null;
+        }
+    }
+
+    /// <inheritdoc/>
+    public IOpcSubscription CreateSubscription(string name, int updateRate = 1000, bool active = true)
+    {
+        var server = GetOpcServer();
+        if (_subscriptions.TryGetValue(name, out var subscription))
+        {
+            // 已经存在该订阅
+            server.CancelSubscription(subscription);
+        }
+
+        subscription = server.CreateSubscription(name, updateRate, active);
+        _subscriptions.Add(name, subscription);
+        return subscription.ToOpcSubscription();
+    }
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Disconnect cancels the underlying subscriptions but never clears `_subscriptions`. After reconnecting, creating a subscription with a previously used name reuses the old server-bound subscription and then `_subscriptions.Add` throws because the name is still present, so subscription recreation fails.

**Triggers:** When a client disconnects, reconnects, and recreates a subscription with the same name.

**Suggested fix:** Clear `_subscriptions` after cancelling the subscriptions during `Disconnect`.

```suggestion
            foreach (Subscription sub in _server.Subscriptions)
            {
                _server.CancelSubscription(sub);
            }

            _subscriptions.Clear();

            _server.Disconnect();
```
</issue_to_address>

### Comment 2
<location path="src/extensions/BootstrapBlazor.OpcUa/Extensions/ServiceCollectionExtensions.cs" line_range="21" />
<code_context>
     /// </summary>
     /// <param name="services"></param>
     /// <returns></returns>
-    public static IServiceCollection AddOpcUaServer(this IServiceCollection services)
+    public static IServiceCollection AddOpcUaClient(this IServiceCollection services)
     {
-        services.AddScoped<IOpcUaServer, OpcUaServer>();
</code_context>
<issue_to_address>
**issue (bug_risk):** The 10.0.1 OpcUa package removes the public `AddOpcUaServer` and `IOpcUaServer` symbols without obsolete aliases or a package-version bump. Existing OpcUa consumers therefore fail to compile when upgrading to this package version.

**Triggers:** When an existing consumer upgrades the OpcUa package and still uses the server-named registration or interface.

**Suggested fix:** Retain obsolete forwarding aliases for the old OpcUa API, or publish the breaking rename under a new major package version.
</issue_to_address>

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.

Comment thread src/extensions/BootstrapBlazor.OpcDa/OpcDaClient.cs
@ArgoZhang
ArgoZhang merged commit 21f27d1 into master Aug 30, 2026
3 checks passed
@ArgoZhang
ArgoZhang deleted the dev-opc branch August 30, 2026 02:25
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.

refactor(Opc): rename server services to clients

1 participant