Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 18 additions & 36 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Build

on:
push:
Expand All @@ -17,67 +17,49 @@ on:
workflow_dispatch:

jobs:
build-on-windows:
runs-on: windows-latest
build:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: "6.0.x"
dotnet-version: |
6.0.x
7.0.x
include-prerelease: false

- name: Build
run: |
cd Common.BasicHelper
dotnet build -c Release

build-on-ubuntu:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: "6.0.x"
include-prerelease: false
dotnet build -c Release

- name: Build
- name: Test
run: |
cd Common.BasicHelper
dotnet build -c Release
cd Common.BasicHelper.Test

dotnet test -c Release

- name: Add to GitHub Repo
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
nuget sources add -name github -Source https://nuget.pkg.github.com/Crequency/index.json -Username Crequency -Password ${{ secrets.GitHubToken }}

- name: Install NuGet
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: nuget/setup-nuget@v1
with:
nuget-version: "6.x"

- name: Publish Package to GitHub and NuGet
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
nuget push ./Common.BasicHelper/bin/Release/*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NugetKey }} -NoSymbol
nuget push ./Common.BasicHelper/bin/Release/*.nupkg -Source github -SkipDuplicate

build-on-macos:
runs-on: macos-latest

steps:
- uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: "6.0.x"
include-prerelease: false

- name: Build
run: |
cd Common.BasicHelper
dotnet build -c Release
25 changes: 0 additions & 25 deletions .github/workflows/codecov.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/pr-merged.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "Pull Request Labeler"
on:
pull_request:
types:
- closed

jobs:
pr-merged:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["merged"]
})
18 changes: 16 additions & 2 deletions Common.BasicHelper.Test/Core/Shell/CommandsExecutor_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@ public class CommandsExecutor_Tests
[TestMethod]
public void Test_ExecuteAsCommand()
{
Console.WriteLine("help".ExecuteAsCommand());
if (OperatingSystem.IsWindows())
Console.WriteLine("help".ExecuteAsCommand());

if (OperatingSystem.IsLinux())
Console.WriteLine("apt".ExecuteAsCommand("-v"));

if (OperatingSystem.IsMacOS())
Console.WriteLine("sw_vers".ExecuteAsCommand());
}

[TestMethod]
public async Task Test_ExecuteAsCommandAsync()
{
Console.WriteLine(await "help".ExecuteAsCommandAsync());
if (OperatingSystem.IsWindows())
Console.WriteLine(await "help".ExecuteAsCommandAsync());

if (OperatingSystem.IsLinux())
Console.WriteLine(await "apt".ExecuteAsCommandAsync("-v"));

if (OperatingSystem.IsMacOS())
Console.WriteLine(await "sw_vers".ExecuteAsCommandAsync());
}
}
25 changes: 17 additions & 8 deletions Common.BasicHelper.Test/Network/NetUtils_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,36 @@ public class NetUtils_Tests
[TestMethod]
public void Test_IsWebConected()
{
Assert.IsTrue(NetUtils.IsWebConected("localhost", 3));
Assert.IsFalse(NetUtils.IsWebConected("192.168.255.255", 3));
if (OperatingSystem.IsWindows())
{
Assert.IsTrue(NetUtils.IsWebConected("localhost", 3));
Assert.IsFalse(NetUtils.IsWebConected("192.168.255.255", 3));
}
}

[TestMethod]
public void Test_DownloadFile()
{
var path = Path.GetFullPath($"{Path.GetTempPath()}/test_downloadFile.txt");
if (OperatingSystem.IsWindows())
{
var path = Path.GetFullPath($"{Path.GetTempPath()}/test_downloadFile.txt");

NetUtils.DownloadFile(testDownloadFilePath, path);
NetUtils.DownloadFile(testDownloadFilePath, path);

File.Delete(path);
File.Delete(path);
}
}

[TestMethod]
public void Test_WebDownloadFile()
{
var path = Path.GetFullPath($"{Path.GetTempPath()}/test_webDownloadFile.txt");
if (OperatingSystem.IsWindows())
{
var path = Path.GetFullPath($"{Path.GetTempPath()}/test_webDownloadFile.txt");

NetUtils.WebDownloadFile(testDownloadFilePath, path);
NetUtils.WebDownloadFile(testDownloadFilePath, path);

File.Delete(path);
File.Delete(path);
}
}
}
18 changes: 12 additions & 6 deletions Common.BasicHelper.Test/Utils/Extensions/Dumpper_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ public void Test_Dump()
.Dump()
;

var interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (var iface in interfaces)
iface.Dump();
if (OperatingSystem.IsWindows())
{
var interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (var iface in interfaces)
iface.Dump();
}
}

[TestMethod()]
Expand All @@ -28,9 +31,12 @@ public void Test_Dump2Lines()
.Dump2Lines()
;

var interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (var iface in interfaces)
iface.Dump2Lines();
if (OperatingSystem.IsWindows())
{
var interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (var iface in interfaces)
iface.Dump2Lines();
}
}

[TestMethod()]
Expand Down
2 changes: 1 addition & 1 deletion Common.BasicHelper.Test/Utils/Password_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Password_Tests
[TestMethod]
public void Test_GeneratePassword()
{
foreach (var item in Enumerable.Range(0, 10))
foreach (var _ in Enumerable.Range(0, 10))
Console.WriteLine(Password.GeneratePassword(length: 12));
}
}
25 changes: 15 additions & 10 deletions Common.BasicHelper/Core/Shell/CommandsExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static async Task<string> GetExecutionResultAsync
string args,
bool findInPath = false,
Action<ProcessStartInfo>? action = null,
CancellationToken? token = default
CancellationToken? token = null
)
{
if (findInPath)
Expand All @@ -90,19 +90,24 @@ public static async Task<string> GetExecutionResultAsync
StartInfo = psi,
};

//var sb = new StringBuilder();

//void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
// => sb.AppendLine(outLine.Data);

//process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
//process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);

process.Start();

var output = process.StandardOutput.ReadToEnd();

await Task.Run(process.WaitForExit);
await Task.Run(() =>
{
if (token is null) process.WaitForExit();

while (!process.HasExited)
{
if (token is not null && token.Value.IsCancellationRequested)
{
process.Kill();

break;
}
}
});

return output;
}
Expand Down
63 changes: 63 additions & 0 deletions Common.BasicHelper/Core/TaskSystem/SignalTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Common.BasicHelper.Utils.Extensions;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Common.BasicHelper.Core.TaskSystem;

public class SignalTask
{
public Queue<Action> Actions { get; } = new();

public bool SignalReusable { get; set; } = false;

public bool ActionsReusable { get; set; } = false;

public SignalTask AddAction(Action action)
{
Actions.Enqueue(action);

return this;
}

public SignalTask ReuseSignal(bool reusable = true)
{
SignalReusable = reusable;

return this;
}

public SignalTask ReuseActions(bool reusable = true)
{
ActionsReusable = reusable;

return this;
}

public SignalTask ExecuteAll(bool? reuseall = null)
{
Actions.ForEach(action => action(), reuseall ?? ActionsReusable);

return this;
}

public async Task<SignalTask> ExecuteAllAsync(bool? reuseall = null, CancellationToken? token = null)
{
await Actions.ForEachAsync(
action => action(),
reuseall ?? ActionsReusable,
token ?? default
);

return this;
}
}

public static class SignalTaskExtensions
{
public static SignalTask AddTo(this Action action, SignalTask task) => task.AddAction(action);

public static SignalTask ExecuteAll(this SignalTask task, bool reuseAll = false)
=> task.ExecuteAll(reuseAll);
}
Loading