Skip to content

Commit

Permalink
Merge branch 'features/AddNet8' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
9swampy committed Apr 17, 2024
2 parents 7ad0369 + 406120e commit 4963fd6
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 37 deletions.
55 changes: 35 additions & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build, Publish, Tag

on:
push:
branches: [ "master", "release/**" ]
branches: [ "master", "release/**", "features/**" ]
pull_request:
branches: [ "master", "develop" ]
workflow_dispatch:
Expand All @@ -18,17 +18,19 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install .NET Core
uses: actions/setup-dotnet@v2
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: |
6.0.x
8.0.x
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.0.2
uses: microsoft/setup-msbuild@v2

- name: Install nuget
run: Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile Nuget.exe
Expand All @@ -39,20 +41,20 @@ jobs:
- name: Build Debug
run: msbuild $env:Solution_Name /p:Configuration=Debug /p:Platform="Any CPU"

- name: Setup VSTest.console.exe
uses: darenm/Setup-VSTest@v1

- name: Telnet.CiTests
run: vstest.console.exe **\bin\Debug\**\PrimS.Telnet.CiTests.dll

- name: Telnet.48.CiTests
run: vstest.console.exe **\bin\Debug\**\PrimS.Telnet.48.CiTests.dll

- name: Telnet.Sync.CiTests
run: vstest.console.exe **\bin\Debug\**\PrimS.Telnet.Sync.CiTests.dll
uses: microsoft/[email protected]
with:
testAssembly: PrimS.Telnet.CiTests.dll
searchFolder: ./**/bin/Debug/**/
runInParallel: true

- name: Telnet.NetStandard.CiTests
run: vstest.console.exe **\bin\Debug\**\PrimS.Telnet.NetStandard.CiTests.dll
# Can't apparently run both full fat and core test suites together.'
- name: Telnet.*.CiTests
uses: microsoft/[email protected]
with:
testAssembly: PrimS.Telnet.*.CiTests.dll
searchFolder: ./**/bin/Debug/**/
runInParallel: true

- name: GitVersion
run: dotnet tool install --global GitVersion.Tool
Expand All @@ -64,27 +66,40 @@ jobs:
$semVer = $json.SemVer
$fullSemVer = $json.FullSemVer
$nuGetVersionV2 = $json.NuGetVersionV2
$buildMetaDataPadded = $json.BuildMetaDataPadded
Write-Host $json
Write-Host $semVer
Write-Host $fullSemVer
Write-Host $nuGetVersionV2
Write-Host ${nuGetVersionV2}${buildMetaDataPadded}
echo "FullSemVer=$fullSemVer" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
echo "SemVer=$semVer" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
echo "NuGetVersionV2=$nuGetVersionV2" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
echo "NuGetVersionV2ext=${nuGetVersionV2}${buildMetaDataPadded}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Build Release
run: msbuild $env:Solution_Name /p:Configuration=Release /p:Platform="Any CPU"

- name: Nuget pack
run: nuget pack Telnet.nuspec -Version $Env:NuGetVersionV2
run: nuget pack Telnet.nuspec -Version $Env:NuGetVersionV2ext

# Navigate to repo->Settings->Actions and check PUBLISH_TO_GITHUB_PACKAGES
# https://github.com/settings/tokens to create a new classic token, permission write:packages, name & copy paste to PUBLISH_TO_GITHUB_PACKAGES
- name: Publish to GitHub
run: dotnet nuget push "Telnet.$Env:NuGetVersionV2.nupkg" --api-key ${{ secrets.PUBLISH_TO_GITHUB_PACKAGES }} --source "https://nuget.pkg.github.com/9swampy/index.json"
run: dotnet nuget push "Telnet.$Env:NuGetVersionV2ext.nupkg" --api-key ${{ secrets.PUBLISH_TO_GITHUB_PACKAGES }} --source "https://nuget.pkg.github.com/9swampy/index.json"

# Login to Nuget 9swampy->Api Keys and regenerate, copy to NUGET_APIKEY
- name: Publish to Nuget
if: github.ref == 'refs/heads/master'
run: nuget push "Telnet.$Env:NuGetVersionV2.nupkg" ${{ secrets.NUGET_APIKEY }} -source https://api.nuget.org/v3/index.json
run: nuget push "Telnet.$Env:NuGetVersionV2ext.nupkg" ${{ secrets.NUGET_APIKEY }} -source https://api.nuget.org/v3/index.json

- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: published-nuget-package
path: Telnet.*.nupkg

- name: Setup Git User
uses: fregante/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion PrimS.Telnet.CiTests/PrimS.Telnet.CiTests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
59 changes: 49 additions & 10 deletions PrimS.Telnet.NetStandard/Client_Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public partial class Client
/// <param name="hostname">The hostname.</param>
/// <param name="port">The port.</param>
/// <param name="token">The cancellation token.</param>
[Obsolete("Prefer overload that accepts new TcpByteStream(hostname, port) and dispose it properly.")]
public Client(string hostname, int port, CancellationToken token)
: this(new TcpByteStream(hostname, port), token)
{
Expand All @@ -48,9 +49,20 @@ public Client(IByteStream byteStream, CancellationToken token)
/// Initialises a new instance of the <see cref="Client"/> class.
/// </summary>
/// <param name="byteStream">The stream served by the host connected to.</param>
/// <param name="timeout">The timeout to wait for initial successful connection to <cref>byteStream</cref>.</param>
/// <param name="timeout">The timeout to wait for initial successful connection to <cref>byteStream</cref>. Other overloads default to new TimeSpan(0, 0, 30).</param>
/// <param name="token">The cancellation token.</param>
public Client(IByteStream byteStream, TimeSpan timeout, CancellationToken token)
: this(byteStream, timeout, token, Array.Empty<(Commands Command, Options Option)>())
{ }

/// <summary>
/// Initialises a new instance of the <see cref="Client"/> class.
/// </summary>
/// <param name="byteStream">The stream served by the host connected to.</param>
/// <param name="timeout">The timeout to wait for initial successful connection to <cref>byteStream</cref>.</param>
/// <param name="token">The cancellation token.</param>
/// <param name="options">Additional options to send during negotiation.</param>
public Client(IByteStream byteStream, TimeSpan timeout, CancellationToken token, (Commands Command, Options Option)[] options)
: base(byteStream, token)
{
Guard.AgainstNullArgument(nameof(byteStream), byteStream);
Expand All @@ -73,9 +85,17 @@ public Client(IByteStream byteStream, TimeSpan timeout, CancellationToken token)
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
// https://stackoverflow.com/questions/70964917/optimising-an-asynchronous-call-in-a-constructor-using-joinabletaskfactory-run
Task.Run(async () => await ProactiveOptionNegotiation().ConfigureAwait(false)).Wait();
foreach (var option in options)
{
Task.Run(async () => await NegotiateOption(option.Command, option.Option).ConfigureAwait(false)).Wait();
}
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
#else
ProactiveOptionNegotiation();
foreach (var option in options)
{
NegotiateOption(option.Command, option.Option);
}
#endif
}
}
Expand All @@ -95,6 +115,18 @@ public Client(IByteStream byteStream, TimeSpan timeout, CancellationToken token)
/// </summary>
public static string TerminalSpeed { get; set; } = "19200,19200";

internal static byte[] SuppressGoAheadBuffer
{
get
{
var supressGoAhead = new byte[3];
supressGoAhead[0] = (byte)Commands.InterpretAsCommand;
supressGoAhead[1] = (byte)Commands.Do;
supressGoAhead[2] = (byte)Options.SuppressGoAhead;
return supressGoAhead;
}
}

/// <summary>
/// Sending <see cref="Commands.Do"/> <see cref="Options.SuppressGoAhead"/> up front will get us to the logon prompt faster.
/// </summary>
Expand All @@ -114,16 +146,23 @@ public Client(IByteStream byteStream, TimeSpan timeout, CancellationToken token)
#endif
}

internal static byte[] SuppressGoAheadBuffer
/// <summary>
/// Negotiate Option specified.
/// </summary>
private
#if ASYNC
Task
#else
void
#endif
NegotiateOption(Commands command, Options option)
{
get
{
var supressGoAhead = new byte[3];
supressGoAhead[0] = (byte)Commands.InterpretAsCommand;
supressGoAhead[1] = (byte)Commands.Do;
supressGoAhead[2] = (byte)Options.SuppressGoAhead;
return supressGoAhead;
}
var buffer = new byte[] { (byte)Commands.InterpretAsCommand, (byte)command, (byte)option };
#if ASYNC
return ByteStream.WriteAsync(buffer, 0, buffer.Length, InternalCancellation.Token);
#else
ByteStream.Write(buffer, 0, buffer.Length);
#endif
}
}
}
2 changes: 1 addition & 1 deletion PrimS.Telnet.NetStandard/Commands.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PrimS.Telnet
{
internal enum Commands
public enum Commands

Check warning on line 3 in PrimS.Telnet.NetStandard/Commands.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Commands'

Check warning on line 3 in PrimS.Telnet.NetStandard/Commands.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Commands'
{
SubnegotiationEnd = 240,

Check warning on line 5 in PrimS.Telnet.NetStandard/Commands.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Commands.SubnegotiationEnd'

Check warning on line 5 in PrimS.Telnet.NetStandard/Commands.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Commands.SubnegotiationEnd'
NoOperation = 241,

Check warning on line 6 in PrimS.Telnet.NetStandard/Commands.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Commands.NoOperation'

Check warning on line 6 in PrimS.Telnet.NetStandard/Commands.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Commands.NoOperation'
Expand Down
2 changes: 1 addition & 1 deletion PrimS.Telnet.NetStandard/Options.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PrimS.Telnet
{
internal enum Options
public enum Options
{
TransmitBinary = 0,
Echo = 1,
Expand Down
2 changes: 1 addition & 1 deletion PrimS.Telnet/PrimS.Telnet.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down
10 changes: 7 additions & 3 deletions Telnet.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
<icon>images\Ptelnet128x600.png</icon>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>
A minimal open-source C# 4.6.2/4.7.2/4.8/NetStandard2.0/NetStandard2.1/Net6.0 Telnet client
A minimal open-source C# 4.6.2/4.7.2/4.8/NetStandard2.0/NetStandard2.1/Net6.0/Net8.0 Telnet client
library implementation; just enough to send simple text commands and retrieve the response.
</description>
<readme>docs\README.md</readme>
<releaseNotes>
0.11.3 exposes the TcpByteStream(ISocket) and TcpClient(System.Net.Sockets.TcpClient) ctors
allowing more open access to creating a viable client than (string hostName, int port).
0.12 adds a Net8.0 target.
</releaseNotes>
<copyright>Copyright (c) 9swampy, Telnet contributors</copyright>
<tags>Telnet</tags>
Expand All @@ -35,6 +34,8 @@
</group>
<group targetFramework="net6.0">
</group>
<group targetFramework="net8.0">
</group>
</dependencies>
</metadata>
<files>
Expand All @@ -55,6 +56,9 @@
<file src="PrimS.Telnet\Bin\Release\net6.0\PrimS.Telnet.dll" target="lib\net6.0" />
<file src="PrimS.Telnet\Bin\Release\net6.0\PrimS.Telnet.xml" target="lib\net6.0" />
<file src="PrimS.Telnet\Bin\Release\net6.0\PrimS.Telnet.deps.json" target="lib\net6.0" />
<file src="PrimS.Telnet\Bin\Release\net8.0\PrimS.Telnet.dll" target="lib\net8.0" />
<file src="PrimS.Telnet\Bin\Release\net8.0\PrimS.Telnet.xml" target="lib\net8.0" />
<file src="PrimS.Telnet\Bin\Release\net8.0\PrimS.Telnet.deps.json" target="lib\net8.0" />
<file src="readme.md" target="docs\" />
</files>
</package>

0 comments on commit 4963fd6

Please sign in to comment.