Skip to content
Open
73 changes: 25 additions & 48 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow helps you trigger a SonarCloud analysis of your code and populates
# GitHub Code Scanning alerts with the vulnerabilities found.
# Free for open source project.

# 1. Login to SonarCloud.io using your GitHub account

# 2. Import your project on SonarCloud
# * Add your GitHub organization first, then add your repository as a new project.
# * Please note that many languages are eligible for automatic analysis,
# which means that the analysis will start automatically without the need to set up GitHub Actions.
# * This behavior can be changed in Administration > Analysis Method.
#
# 3. Follow the SonarCloud in-product tutorial
# * a. Copy/paste the Project Key and the Organization Key into the args parameter below
# (You'll find this information in SonarCloud. Click on "Information" at the bottom left)
#
# * b. Generate a new token and add it to your Github repository's secrets using the name SONAR_TOKEN
# (On SonarCloud, click on your avatar on top-right > My account > Security
# or go directly to https://sonarcloud.io/account/security/)

# Feel free to take a look at our documentation (https://docs.sonarcloud.io/getting-started/github/)
# or reach out to our community forum if you need some help (https://community.sonarsource.com/c/help/sc/9)

name: SonarCloud analysis

on:
Expand All @@ -36,15 +8,16 @@ on:
workflow_dispatch:

permissions:
pull-requests: read # allows SonarCloud to decorate PRs with analysis results
pull-requests: read

jobs:
sonar-check:
name: Sonar Check
runs-on: windows-latest # безпечно для будь-яких .NET проектів
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
with:
fetch-depth: 0

- uses: actions/setup-dotnet@v4
with:
Expand All @@ -54,29 +27,33 @@ jobs:
- name: SonarScanner Begin
run: |
dotnet tool install --global dotnet-sonarscanner
echo "$env:USERPROFILE\.dotnet\tools" >> $env:GITHUB_PATH
dotnet sonarscanner begin `
/k:"ppanchen_NetSdrClient" `
/o:"ppanchen" `
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" `
/d:sonar.cs.opencover.reportsPaths="**/coverage.xml" `
/d:sonar.cpd.cs.minimumTokens=40 `
/d:sonar.cpd.cs.minimumLines=5 `
/d:sonar.exclusions=**/bin/**,**/obj/**,**/sonarcloud.yml `
/d:sonar.qualitygate.wait=true
/k:"NatashaTymchenko_NetSdrClient" `
/o:"natashatymchenko" `
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" `
/d:sonar.cs.opencover.reportsPaths="**/coverage.xml" `
/d:sonar.cpd.cs.minimumTokens=40 `
/d:sonar.cpd.cs.minimumLines=5 `
/d:sonar.exclusions=**/bin/**,**/obj/**,**/sonarcloud.yml `
/d:sonar.qualitygate.wait=true
shell: pwsh
# 2) BUILD & TEST

# 2) BUILD
- name: Restore
run: dotnet restore NetSdrClient.sln

- name: Build
run: dotnet build NetSdrClient.sln -c Release --no-restore
#- name: Tests with coverage (OpenCover)
# run: |
# dotnet test NetSdrClientAppTests/NetSdrClientAppTests.csproj -c Release --no-build `
# /p:CollectCoverage=true `
# /p:CoverletOutput=TestResults/coverage.xml `
# /p:CoverletOutputFormat=opencover
# shell: pwsh

# ДОДАНО БЛОК ТЕСТІВ
- name: Tests with coverage (OpenCover)
run: |
dotnet test NetSdrClientAppTests/NetSdrClientAppTests.csproj -c Release --no-build `
/p:CollectCoverage=true `
/p:CoverletOutput=TestResults/coverage.xml `
/p:CoverletOutputFormat=opencover
shell: pwsh

# 3) END: SonarScanner
- name: SonarScanner End
run: dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
Expand Down
2 changes: 1 addition & 1 deletion NetSdrClientApp/NetSdrClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task ConnectAsync()
}
}

public void Disconect()
public void Disconnect()
{
_tcpClient.Disconnect();
}
Expand Down
4 changes: 0 additions & 4 deletions NetSdrClientApp/Networking/TcpClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace NetSdrClientApp.Networking
{
public class TcpClientWrapper : ITcpClient
{
private string _host;
private int _port;
private TcpClient? _tcpClient;
private NetworkStream? _stream;
private CancellationTokenSource _cts;
Expand All @@ -24,8 +22,6 @@ public class TcpClientWrapper : ITcpClient

public TcpClientWrapper(string host, int port)
{
_host = host;
_port = port;
}

public void Connect()
Expand Down
15 changes: 3 additions & 12 deletions NetSdrClientApp/Networking/UdpClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task StartListeningAsync()
Console.WriteLine($"Received from {result.RemoteEndPoint}");
}
}
catch (OperationCanceledException ex)
catch (OperationCanceledException)
{
//empty
}
Expand All @@ -61,16 +61,7 @@ public void StopListening()

public void Exit()
{
try
{
_cts?.Cancel();
_udpClient?.Close();
Console.WriteLine("Stopped listening for UDP messages.");
}
catch (Exception ex)
{
Console.WriteLine($"Error while stopping: {ex.Message}");
}
StopListening();
}

public override int GetHashCode()
Expand All @@ -82,4 +73,4 @@ public override int GetHashCode()

return BitConverter.ToInt32(hash, 0);
}
}
}
85 changes: 48 additions & 37 deletions NetSdrClientApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,57 @@
using NetSdrClientApp;
using System;
using System.Threading.Tasks;
using NetSdrClientApp;
using NetSdrClientApp.Networking;

Console.WriteLine(@"Usage:
C - connect
D - disconnet
F - set frequency
S - Start/Stop IQ listener
Q - quit");

var tcpClient = new TcpClientWrapper("127.0.0.1", 5000);
var udpClient = new UdpClientWrapper(60000);

var netSdr = new NetSdrClient(tcpClient, udpClient);

while (true)
namespace NetSdrClientApp
{
var key = Console.ReadKey(intercept: true).Key;
if (key == ConsoleKey.C)
{
await netSdr.ConnectAsync();
}
else if (key == ConsoleKey.D)
{
netSdr.Disconect();
}
else if (key == ConsoleKey.F)
public static class Program
{
await netSdr.ChangeFrequencyAsync(20000000, 1);
}
else if (key == ConsoleKey.S)
{
if (netSdr.IQStarted)
public static async Task Main()
{
await netSdr.StopIQAsync();
}
else
Console.WriteLine(@"Usage:
C - connect
D - disconnet
F - set frequency
S - Start/Stop IQ listener
Q - quit");

var tcpClient = new TcpClientWrapper("127.0.0.1", 5000);
var udpClient = new UdpClientWrapper(60000);

var netSdr = new NetSdrClient(tcpClient, udpClient);

while (true)
{
await netSdr.StartIQAsync();
var key = Console.ReadKey(intercept: true).Key;
if (key == ConsoleKey.C)
{
await netSdr.ConnectAsync();
}
else if (key == ConsoleKey.D)
{
netSdr.Disconnect();
}
else if (key == ConsoleKey.F)
{
await netSdr.ChangeFrequencyAsync(20000000, 1);
}
else if (key == ConsoleKey.S)
{
if (netSdr.IQStarted)
{
await netSdr.StopIQAsync();
}
else
{
await netSdr.StartIQAsync();
}
}
else if (key == ConsoleKey.Q)
{
break;
}
}
}
}
else if (key == ConsoleKey.Q)
{
break;
}
}
1 change: 1 addition & 0 deletions NetSdrClientAppTests/NetSdrClientAppTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="coverlet.msbuild" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="NUnit" Version="3.14.0" />
Expand Down
Loading