Skip to content

feat(OpcDa): add Mock function#516

Merged
ArgoZhang merged 8 commits intomasterfrom
refactor-opc
Aug 6, 2025
Merged

feat(OpcDa): add Mock function#516
ArgoZhang merged 8 commits intomasterfrom
refactor-opc

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Aug 6, 2025

Link issues

fixes #515

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

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

Provide a mockable OPC DA server implementation and streamline the existing service by renaming, refactoring subscription handling, adding helper extensions, and updating tests to use the new API.

New Features:

  • Add MockOpcDaServer and MockOpcDaSubscription for simulated OPC DA operations
  • Introduce AddMockOpcDaServer DI extension to register the mock server

Enhancements:

  • Rename IOpcServer to IOpcDaServer and OpcServer to OpcDaServer and update DI registration to AddOpcDaServer
  • Manage subscriptions by name in OpcDaServer and refactor creation and cancellation flows
  • Add extension methods for subscription creation and quality conversion

Tests:

  • Update unit tests to use IOpcDaServer and AddOpcDaServer extension

@bb-auto bb-auto Bot added the enhancement New feature or request label Aug 6, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Aug 6, 2025
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Aug 6, 2025

Reviewer's Guide

This PR refactors the OPC DA server implementation by renaming core services and interfaces, improving subscription handling with name-keyed tracking and duplicate cancellation, updating the subscription interface and extension methods, and introducing mock server/subscription implementations with DI registration.

File-Level Changes

Change Details Files
Renamed core server types and updated DI registrations.
  • Renamed OpcServer to OpcDaServer and IOpcServer to IOpcDaServer
  • Updated ServiceCollectionExtensions to AddOpcDaServer and AddMockOpcDaServer
  • Adjusted tests to use IOpcDaServer and sc.AddOpcDaServer()
OpcDaServer.cs
ServiceCollectionExtensions.cs
IOpcDaServer.cs
UnitTest1.cs
Enhanced subscription management with name-keyed tracking and duplicate cancellation.
  • Introduced _subscriptions dictionary to track active subscriptions
  • Cancel existing subscription before creating a new one with the same name
  • Removed reliance on server.Subscriptions enumeration
OpcDaServer.cs
Refined subscription interface and its implementation.
  • Renamed ISubscription to IOpcSubscription, added Name property, removed GetSubscription
  • Updated OpcSubscription to implement IOpcSubscription and adapt DataChanged handling
  • Extended CreateSubscription extension method signature
IOpcSubscription.cs
OpcSubscription.cs
Extensions.cs
Added mock OPC DA server and subscription implementations with DI support.
  • Created MockOpcDaServer implementing IOpcDaServer
  • Implemented MockOpcDaSubscription with background update loop
  • Registered MockOpcDaServer via AddMockOpcDaServer extension
MockOpcDaServer.cs
MockOpcSubscription.cs
ServiceCollectionExtensions.cs
Fixed quality conversion logic using correct qualityBits value.
  • Updated Extensions.ToQuality to compare against qualityBits.good
Extensions.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#515 Add a mock implementation (Mock function) for the OpcDa server to allow simulated usage/testing.

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

@ArgoZhang ArgoZhang merged commit 851dad0 into master Aug 6, 2025
1 check passed
@ArgoZhang ArgoZhang deleted the refactor-opc branch August 6, 2025 10:02
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

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

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

### Comment 1
<location> `src/extensions/BootstrapBlazor.OpcDa/Mock/MockOpcDaServer.cs:25` </location>
<code_context>
+        return true;
+    }
+
+    public void Disconnect()
+    {
+        IsConnected = false;
+        ServerName = null;
+    }
+
</code_context>

<issue_to_address>
Disconnect does not clear or dispose subscriptions.

Please ensure all items in _subscriptions are disposed and cleared in Disconnect to prevent resource leaks or unintended background activity.
</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 on lines +25 to +28
public void Disconnect()
{
IsConnected = false;
ServerName = null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Disconnect does not clear or dispose subscriptions.

Please ensure all items in _subscriptions are disposed and cleared in Disconnect to prevent resource leaks or unintended background activity.

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(OpcDa): add Mock function

1 participant