Skip to content

Lab 4: extract duplicated send and stop helpers#21

Open
nik-bykoff wants to merge 4 commits intolenagrin:masterfrom
nik-bykoff:lab-04-duplications
Open

Lab 4: extract duplicated send and stop helpers#21
nik-bykoff wants to merge 4 commits intolenagrin:masterfrom
nik-bykoff:lab-04-duplications

Conversation

@nik-bykoff
Copy link
Copy Markdown

Summary

Eliminate the three duplicate blocks Sonar would flag in NetSdrClientApp.Networking:

  • TcpClientWrapper.SendMessageAsync(byte[]) and SendMessageAsync(string) shared a 6-line check/log/write block. Refactored into private async Task SendCoreAsync(byte[]); the two public overloads are now one-liners.
  • UdpClientWrapper.StopListening and UdpClientWrapper.Exit had identical bodies. Both now delegate to a private StopCore().
  • The b => Convert.ToString(b, toBase: 16) hex-format snippet was copy-pasted in three log statements. Extracted into a new internal static HexFormatter.ToSpaceSeparatedHex(byte[]) and reused in TCP send, TCP receive and UDP samples logs.

No public API changes; IUdpClient and ITcpClient contracts are untouched. All existing 18 tests continue to pass.

Test plan

  • dotnet build NetSdrClient.sln -c Release --no-restore succeeds.
  • dotnet test NetSdrClient.sln -c Release --no-build reports 18/18 passing.
  • After merging, SonarCloud Duplications on New Code is 0% (Quality Gate green for this metric).

Discipline / Author

  • Subject: Реінжиніринг програмного забезпечення
  • Student: Биков Нікіта Вячеславович, group ПЗС-1

nik-bykoff added 4 commits May 4, 2026 21:31
- Move SONAR_PROJECT_KEY/SONAR_ORGANIZATION into workflow env block with explicit setup instructions for fork-based usage.

- Update README with student header, fork/upstream links and a table of all eight lab reports.

- Replace SonarCloud badges with placeholders for nik-bykoff fork.

- Add docs/labs/lab-01.md report describing manual SonarCloud steps, CI workflow layout and verification checklist.

- Ignore local .env files to prevent accidental token leaks.
- Rename NetSdrClient.Disconect to Disconnect (typo) and update callers/tests.

- Remove stray semicolon in StartIQAsync and unused JSType using-statics.

- Make responseTaskSource thread-safe via Interlocked.Exchange + TrySetResult.

- Replace Aggregate-on-empty-may-throw log formatting with string.Join in three places.

- Rewrite GetSamples from O(n^2) IEnumerable.Count loop to O(n) for-loop with reusable byte[4] buffer.

- Replace MD5-based UdpClientWrapper.GetHashCode with HashCode.Combine and add Equals override.

- Make TcpClientWrapper._cts nullable, mark _host/_port readonly, drop unused exception variable names.

- All eight existing unit tests still pass; compiler warnings dropped from 18 to 15 (rest are EchoTcpServer or NuGet).
- Add coverlet.msbuild to NetSdrClientAppTests with PrivateAssets=all.

- Add four NetSdrClient tests (ChangeFrequency, idempotent IQ flag, listener startup, no-op when disconnected).

- Add six NetSdrMessageHelper tests covering control-item/data-item roundtrip and GetSamples edge cases (8/16 bit, empty body, oversized width).

- Fix latent bug in TranslateMessage where Enum.IsDefined was called with ushort while ControlItemCodes underlying type is int.

- Re-enable Tests with coverage step in CI workflow with opencover output and Program exclusion.

- 18/18 tests passing locally; coverage of NetSdrClientApp module: line 45.86%, branch 26.92%, method 48.48%.
- Add internal HexFormatter.ToSpaceSeparatedHex used by TCP send log, TCP receive log and UDP samples log.

- Replace TcpClientWrapper.SendMessageAsync(byte[]) and SendMessageAsync(string) overloads with thin wrappers around private SendCoreAsync(byte[]).

- Collapse identical UdpClientWrapper.StopListening and Exit into StopCore via thin delegating wrappers.

- 18/18 tests still pass; behavior unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant