Skip to content

feat(OpcDa): bump version 10.0.1#8070

Merged
ArgoZhang merged 5 commits into
mainfrom
feat-da
May 31, 2026
Merged

feat(OpcDa): bump version 10.0.1#8070
ArgoZhang merged 5 commits into
mainfrom
feat-da

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented May 31, 2026

Link issues

fixes #8069

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

Localize the OpcDa sample UI and add mock OPC DA server implementations for demonstration and testing.

New Features:

  • Add localized labels and instructional text to the OpcDa sample using resource-based Localizer strings.
  • Introduce a mock IOpcDaServer and subscription implementation with DI registration for simulating OPC DA behavior without a real server.

Enhancements:

  • Ensure OpcDa subscription callbacks update Blazor component state on the correct synchronization context while preserving request cultures.

Copilot AI review requested due to automatic review settings May 31, 2026 02:46
@bb-auto bb-auto Bot added the enhancement New feature or request label May 31, 2026
@bb-auto bb-auto Bot added this to the v10.6.0 milestone May 31, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 31, 2026

Reviewer's Guide

Updates the OpcDa sample to use localized UI text, ensures culture is preserved when processing subscription callbacks, and introduces mock OpcDa server/subscription services for testing or non-Windows environments.

Sequence diagram for OpcDa subscription callback with culture preservation

sequenceDiagram
    actor User
    participant OpcDaComponent as OpcDa
    participant IOpcDaServer
    participant Subscription as MockOpcDaSubscription

    User->>OpcDaComponent: OnCreateSubscription()
    OpcDaComponent->>OpcDaComponent: _culture = CultureInfo.CurrentCulture
    OpcDaComponent->>OpcDaComponent: _uiCulture = CultureInfo.CurrentUICulture
    OpcDaComponent->>IOpcDaServer: CreateSubscription(Subscription1, 1000, true)
    IOpcDaServer-->>OpcDaComponent: IOpcSubscription
    OpcDaComponent->>Subscription: AddItems([Tag1, Tag2])
    Subscription->>Subscription: DoTask(token)
    loop every updateRate
        Subscription->>Subscription: UpdateValues()
        Subscription-->>OpcDaComponent: DataChanged(items)
        OpcDaComponent->>OpcDaComponent: UpdateValues(items)
        OpcDaComponent->>OpcDaComponent: InvokeAsync(lambda)
        activate OpcDaComponent
        OpcDaComponent->>OpcDaComponent: CultureInfo.CurrentCulture = _culture
        OpcDaComponent->>OpcDaComponent: CultureInfo.CurrentUICulture = _uiCulture
        OpcDaComponent->>OpcDaComponent: StateHasChanged()
        deactivate OpcDaComponent
    end
Loading

File-Level Changes

Change Details Files
Localize OpcDa sample UI texts and usage instructions.
  • Replaced hard-coded Chinese labels, button texts, and step descriptions with Localizer-based resources.
  • Added code snippets in the sample showing how to register and inject IOpcDaServer using localized labels.
  • Updated button and label bindings to use new localization keys for server, speed, flow, subscription, and browse actions.
src/BootstrapBlazor.Server/Components/Samples/OpcDa.razor
src/BootstrapBlazor.Server/Locales/en-US.json
src/BootstrapBlazor.Server/Locales/zh-CN.json
Preserve and restore culture when handling OpcDa subscription callbacks.
  • Imported System.Globalization and added private fields to store CultureInfo.CurrentCulture and CultureInfo.CurrentUICulture when creating a subscription.
  • Wrapped UpdateValues body in InvokeAsync and explicitly set CultureInfo.CurrentCulture and CultureInfo.CurrentUICulture before processing items.
  • Updated StateHasChanged invocation to run inside the same InvokeAsync callback.
src/BootstrapBlazor.Server/Components/Samples/OpcDa.razor.cs
Introduce mock OpcDa server and subscription implementations plus DI extension for tests/demo.
  • Added MockOpcDaServer implementing IOpcDaServer with in-memory connection handling, subscription tracking, random read/write values, and static browse tree.
  • Added MockOpcDaSubscription implementing IOpcSubscription with a background task that periodically raises DataChanged with random values.
  • Added AddMockOpcDaServer DI extension method that registers IOpcDaServer as MockOpcDaServer via AddSingleton.
src/BootstrapBlazor.Server/Services/Mocks/MockOpcDaServer.cs
src/BootstrapBlazor.Server/Services/Mocks/MockOpcSubscription.cs
src/BootstrapBlazor.Server/Services/Mocks/MockOpcServicesExtensions.cs
src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj

Assessment against linked issues

Issue Objective Addressed Explanation
#8069 Update the project to use BootstrapBlazor.OpcDa version 10.0.2 wherever it is referenced (e.g., project/package configuration).

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 changed the title feat(OpcDa): bump version 10.0.2 feat(OpcDa): bump version 10.0.1 May 31, 2026
Copy link
Copy Markdown
Contributor

@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 - I've found 3 issues, and left some high level feedback:

  • In OpcDa.UpdateValues, you override CultureInfo.CurrentCulture/CurrentUICulture without restoring the previous values; consider capturing the original cultures and restoring them in a try/finally to avoid leaking culture changes into unrelated UI callbacks on the same synchronization context.
  • In MockOpcDaServer.Dispose you currently do nothing; if this mock is reused across the app lifetime, consider iterating existing subscriptions and calling CancelSubscription to ensure timers/tasks from MockOpcDaSubscription are properly stopped and disposed.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `OpcDa.UpdateValues`, you override `CultureInfo.CurrentCulture`/`CurrentUICulture` without restoring the previous values; consider capturing the original cultures and restoring them in a `try/finally` to avoid leaking culture changes into unrelated UI callbacks on the same synchronization context.
- In `MockOpcDaServer.Dispose` you currently do nothing; if this mock is reused across the app lifetime, consider iterating existing subscriptions and calling `CancelSubscription` to ensure timers/tasks from `MockOpcDaSubscription` are properly stopped and disposed.

## Individual Comments

### Comment 1
<location path="src/BootstrapBlazor.Server/Components/Samples/OpcDa.razor.cs" line_range="68-72" />
<code_context>
     private void OnCreateSubscription()
     {
         _subscribed = true;
+        _culture = CultureInfo.CurrentCulture;
+        _uiCulture = CultureInfo.CurrentUICulture;
         _subscription = OpcDaServer.CreateSubscription("Subscription1", 1000, true);
</code_context>
<issue_to_address>
**issue (bug_risk):** Persisting and globally setting cultures in subscription callbacks can have side effects and is not reverted.

The callback captures `CurrentCulture`/`CurrentUICulture` once and then reapplies them on every `UpdateValues` via `InvokeAsync`, without restoring the prior values. Since these are ambient thread-wide settings, this can cause subtle issues if other code changes culture or if the culture changes after the subscription is created. Prefer using the captured cultures only where needed (e.g., `value1.ToString(_culture)`) instead of setting `CurrentCulture`/`CurrentUICulture`, or at least capture and restore the previous culture inside `UpdateValues`.
</issue_to_address>

### Comment 2
<location path="src/BootstrapBlazor.Server/Components/Samples/OpcDa.razor.cs" line_range="84-87" />
<code_context>

     private void UpdateValues(List<OpcReadItem> items)
     {
-        var value1 = items.Find(i => i.Name == Tag1).Value;
-        if (value1 != null)
-        {
-            _tagValue3 = value1.ToString();
-        }
-        var value2 = items.Find(i => i.Name == Tag2).Value;
-        if (value2 != null)
+        _ = InvokeAsync(() =>
</code_context>
<issue_to_address>
**issue (bug_risk):** Potential null dereference when an expected tag is missing from the subscription update list.

`items.Find(i => i.Name == Tag1)` and `items.Find(i => i.Name == Tag2)` may return `null` (e.g., if the server returns only a subset of items or tag names change), leading to a `NullReferenceException` when accessing `.Value`. Please add a null check on the `Find` result before reading `.Value` so the code remains robust if server responses or subscription configuration change.
</issue_to_address>

### Comment 3
<location path="src/BootstrapBlazor.Server/Components/Samples/OpcDa.razor.cs" line_range="33" />
<code_context>
     private IOpcSubscription? _subscription;

     private bool _subscribed;
+    private CultureInfo? _culture;
+    private CultureInfo? _uiCulture;

</code_context>
<issue_to_address>
**issue (complexity):** Consider simplifying the new culture handling by using non-null captured cultures for formatting instead of mutating global culture and checking nullable fields inside the callback.

The new culture handling adds avoidable complexity via nullable fields and global culture mutation. You can keep the culture-sensitive behavior while simplifying the code and avoiding side effects.

**Key simplifications:**
1. Treat culture as non-null once a subscription exists.
2. Use the stored culture as an `IFormatProvider` instead of mutating `CultureInfo.CurrentCulture` / `CurrentUICulture`.
3. Keep `InvokeAsync` for correct Blazor threading, but only for UI updates and formatting.

### Suggested changes

**1. Make culture non-nullable and capture once**

```csharp
private CultureInfo _culture = CultureInfo.CurrentCulture;
// If you truly need UI culture separately:
private CultureInfo _uiCulture = CultureInfo.CurrentUICulture;
```

Update in `OnCreateSubscription` (no nullable fields, no extra checks later):

```csharp
private void OnCreateSubscription()
{
    _subscribed = true;
    _culture = CultureInfo.CurrentCulture;
    _uiCulture = CultureInfo.CurrentUICulture;

    _subscription = OpcDaServer.CreateSubscription("Subscription1", 1000, true);
    _subscription.DataChanged += UpdateValues;
    _subscription.AddItems([Tag1, Tag2]);
}
```

**2. Use the captured culture only for formatting, no global mutation**

```csharp
private void UpdateValues(List<OpcReadItem> items)
{
    // Capture once for thread-safety and clarity
    var culture = _culture;

    _ = InvokeAsync(() =>
    {
        var value1 = items.Find(i => i.Name == Tag1).Value;
        if (value1 != null)
        {
            _tagValue3 = Convert.ToString(value1, culture);
        }

        var value2 = items.Find(i => i.Name == Tag2).Value;
        if (value2 != null)
        {
            _tagValue4 = Convert.ToString(value2, culture);
        }

        StateHasChanged();
    });
}
```

If you specifically need `CurrentUICulture` semantics (e.g., for localized strings), you can use `_uiCulture` the same way:

```csharp
_tagValue3 = Convert.ToString(value1, _uiCulture);
```

**Benefits:**
- Removes global side effects on `CultureInfo.CurrentCulture` / `CurrentUICulture`.
- Eliminates nullable `_culture` / `_uiCulture` and their null checks.
- Keeps the new behavior: values are formatted using the culture captured at subscription time.
</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 +68 to 72
_culture = CultureInfo.CurrentCulture;
_uiCulture = CultureInfo.CurrentUICulture;
_subscription = OpcDaServer.CreateSubscription("Subscription1", 1000, true);
_subscription.DataChanged += UpdateValues;
_subscription.AddItems([Tag1, Tag2]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Persisting and globally setting cultures in subscription callbacks can have side effects and is not reverted.

The callback captures CurrentCulture/CurrentUICulture once and then reapplies them on every UpdateValues via InvokeAsync, without restoring the prior values. Since these are ambient thread-wide settings, this can cause subtle issues if other code changes culture or if the culture changes after the subscription is created. Prefer using the captured cultures only where needed (e.g., value1.ToString(_culture)) instead of setting CurrentCulture/CurrentUICulture, or at least capture and restore the previous culture inside UpdateValues.

Comment on lines 84 to +87

private void UpdateValues(List<OpcReadItem> items)
{
var value1 = items.Find(i => i.Name == Tag1).Value;
if (value1 != null)
{
_tagValue3 = value1.ToString();
}
var value2 = items.Find(i => i.Name == Tag2).Value;
if (value2 != null)
_ = InvokeAsync(() =>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Potential null dereference when an expected tag is missing from the subscription update list.

items.Find(i => i.Name == Tag1) and items.Find(i => i.Name == Tag2) may return null (e.g., if the server returns only a subset of items or tag names change), leading to a NullReferenceException when accessing .Value. Please add a null check on the Find result before reading .Value so the code remains robust if server responses or subscription configuration change.

Comment thread src/BootstrapBlazor.Server/Components/Samples/OpcDa.razor.cs
@ArgoZhang ArgoZhang merged commit db208d3 into main May 31, 2026
4 of 5 checks passed
@ArgoZhang ArgoZhang deleted the feat-da branch May 31, 2026 02:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (86babcf) to head (231e9f9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #8070   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          766       766           
  Lines        34155     34155           
  Branches      4697      4697           
=========================================
  Hits         34155     34155           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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): bump version 10.0.1

2 participants