Skip to content

Commit

Permalink
General updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
9swampy committed Nov 20, 2024
1 parent bd446f8 commit 63a3cf8
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 76 deletions.
33 changes: 21 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ jobs:
run: msbuild $env:Solution_Name /p:Configuration=Debug /p:Platform="Any CPU"

- name: Telnet.CiTests
uses: rusty-bender/vstest-action@main
uses: rusty-bender/vstest-action@main
with:
testAssembly: PrimS.Telnet.CiTests.dll
searchFolder: ./**/bin/Debug/**/
runInParallel: true

- name: Remove File
uses: JesseTG/rm@v1.0.3
with:
path: ../../_actions/rusty-bender/vstest-action/main/dist

# Can't apparently run both full fat and core test suites together.'
- name: Telnet.*.CiTests
uses: rusty-bender/vstest-action@main
Expand All @@ -61,22 +66,26 @@ jobs:

- name: Run GitVersion
run: |
dotnet-gitversion /showConfig
$str = dotnet-gitversion /updateprojectfiles | out-string
$json = ConvertFrom-Json $str
$json
$semVer = $json.SemVer
$fullSemVer = $json.FullSemVer
$nuGetVersionV2 = $json.NuGetVersionV2
$buildMetaDataPadded = $json.BuildMetaDataPadded
$nuGetVersionV2 = $json.MajorMinorPatch
$buildMetaDataPadded = "$($json.MajorMinorPatch)$($json.PreReleaseTagWithDash)$($json.WeightedPreReleaseNumber)"
Write-Host $json
Write-Host $semVer
Write-Host $fullSemVer
Write-Host $nuGetVersionV2
Write-Host "semVer:" $semVer
Write-Host "fullSemVer:" $fullSemVer
Write-Host "nuGetVersionV2:" $nuGetVersionV2
Write-Host "Pre buildMetaDataPadded:" $buildMetaDataPadded
if (${buildMetaDataPadded} = "0000") {
${buildMetaDataPadded} = ''
}
Write-Host ${nuGetVersionV2}${buildMetaDataPadded}
Write-Host "Post buildMetaDataPadded:" $buildMetaDataPadded
Write-Host "NuGetVersionV2ext:${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
Expand All @@ -87,22 +96,22 @@ jobs:
run: msbuild $env:Solution_Name /p:Configuration=Release /p:Platform="Any CPU"

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

# Navigate to https://github.com/settings/tokens and check to see if the old token has expired
# https://github.com/settings/tokens to create a new classic token, permission write:packages, name & copy paste to PUBLISH_TO_GITHUB_PACKAGES
# Navigate to repo->Settings->Secrets and variables->Actions and check PUBLISH_TO_GITHUB_PACKAGES
- name: Publish to GitHub
run: dotnet nuget push "Telnet.$Env:NuGetVersionV2ext.nupkg" --api-key ${{ secrets.PUBLISH_TO_GITHUB_PACKAGES }} --source "https://nuget.pkg.github.com/9swampy/index.json"
run: dotnet nuget push "Telnet.$Env:SemVer.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...
# GitHub navigate to repo->Settings->Secrets and variables->Actions and set NUGET_APIKEY
- name: Publish to Nuget
if: github.ref == 'refs/heads/master'
run: nuget push "Telnet.$Env:NuGetVersionV2ext.nupkg" ${{ secrets.NUGET_APIKEY }} -source https://api.nuget.org/v3/index.json
run: nuget push "Telnet.$Env:SemVer.nupkg" ${{ secrets.NUGET_APIKEY }} -source https://api.nuget.org/v3/index.json

- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: published-nuget-package
path: Telnet.*.nupkg
Expand Down
32 changes: 32 additions & 0 deletions PrimS.Telnet.CiTests/WithDummyByteStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public void ShouldConnect()
}
}

#if ASYNC
[Fact(Timeout = 2000)]
#else
[Fact]
#endif
public
#if ASYNC
async Task
Expand All @@ -49,7 +53,11 @@ async Task
}
}

#if ASYNC
[Fact(Timeout = 2000)]
#else
[Fact]
#endif
public
#if ASYNC
async Task
Expand All @@ -74,7 +82,11 @@ async Task
}
}

#if ASYNC
[Fact(Timeout = 2000)]
#else
[Fact]
#endif
public
#if ASYNC
async Task
Expand Down Expand Up @@ -105,7 +117,11 @@ async Task
}
}

#if ASYNC
[Fact(Timeout = 3000)]
#else
[Fact]
#endif
public
#if ASYNC
async Task
Expand Down Expand Up @@ -136,7 +152,11 @@ async Task
}
}

#if ASYNC
[Fact(Timeout = 5000)]
#else
[Fact]
#endif
public
#if ASYNC
async Task
Expand Down Expand Up @@ -165,7 +185,11 @@ async Task
}
}

#if ASYNC
[Fact(Timeout = 5000)]
#else
[Fact]
#endif
public
#if ASYNC
async Task
Expand Down Expand Up @@ -194,7 +218,11 @@ async Task
}
}

#if ASYNC
[Fact(Timeout = 5000)]
#else
[Fact]
#endif
public
#if ASYNC
async Task
Expand All @@ -217,7 +245,11 @@ async Task
}
}

#if ASYNC
[Fact(Timeout = 5000)]
#else
[Fact]
#endif
public
#if ASYNC
async Task
Expand Down
4 changes: 4 additions & 0 deletions PrimS.Telnet.NetStandard/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public async Task WriteAsync(string command)
/// <inheritdoc/>
public async Task WriteAsync(byte[] data)
{
data = data ?? throw new ArgumentNullException(nameof(data));

if (ByteStream.Connected && !InternalCancellation.Token.IsCancellationRequested)
{
await SendRateLimit.WaitAsync(InternalCancellation.Token).ConfigureAwait(false);
Expand Down Expand Up @@ -100,6 +102,8 @@ public async Task<string> TerminatedReadAsync(string terminator, TimeSpan timeou
/// <inheritdoc/>
public async Task<string> TerminatedReadAsync(Regex regex, TimeSpan timeout, int millisecondSpin)
{
regex = regex ?? throw new ArgumentNullException(nameof(regex));

bool isTerminated(string x) => Client.IsRegexLocated(regex, x);
var s = await TerminatedReadAsync(isTerminated, timeout, millisecondSpin).ConfigureAwait(false);
if (!isTerminated(s))
Expand Down
68 changes: 10 additions & 58 deletions PrimS.Telnet.Sync/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@

public partial class Client : BaseClient, IClient
{
/// <summary>
/// Tries to login.
/// </summary>
/// <param name="userName">The user name.</param>
/// <param name="password">The password.</param>
/// <param name="loginTimeOutMs">The login time out ms.</param>
/// <param name="terminator">The prompt terminator to anticipate.</param>
/// <param name="lineFeed">The line feed to use. Issue 38: According to RFC 854, CR+LF should be the default a client sends. For backward compatibility \n maintained.</param>
/// <returns>True if successful.</returns>
/// <inheritdoc/>
public bool TryLogin(string userName, string password, int loginTimeOutMs, string terminator = ">", string lineFeed = LegacyLineFeed)
{
try
Expand Down Expand Up @@ -60,20 +52,13 @@ public void WriteLineRfc854(string command)
Write(string.Format("{0}{1}", command, Rfc854LineFeed));
}

/// <summary>
/// Writes the line to the server.
/// </summary>
/// <param name="command">The command.</param>
/// <param name="lineFeed">The line feed to use. Issue 38: According to RFC 854, CR+LF should be the default a client sends. For backward compatibility \n maintained.</param>
/// <inheritdoc/>
public void WriteLine(string command, string lineFeed = LegacyLineFeed)
{
Write(string.Format("{0}{1}", command, lineFeed));
}

/// <summary>
/// Writes the specified command to the server.
/// </summary>
/// <param name="command">The command.</param>
/// <inheritdoc/>
public void Write(string command)
{
if (ByteStream.Connected)
Expand All @@ -82,64 +67,37 @@ public void Write(string command)
}
}

/// <summary>
/// Reads asynchronously from the stream.
/// </summary>
/// <returns>Any text read from the stream.</returns>
/// <inheritdoc/>
public string Read()
{
return Read(TimeSpan.FromMilliseconds(Client.DefaultTimeoutMs));
}

/// <summary>
/// Reads asynchronously from the stream, terminating as soon as the <paramref name="terminator"/> is located.
/// </summary>
/// <param name="terminator">The terminator.</param>
/// <returns>Any text read from the stream.</returns>
/// <inheritdoc/>
public string TerminatedRead(string terminator)
{
return TerminatedRead(terminator, TimeSpan.FromMilliseconds(Client.DefaultTimeoutMs));
}

/// <summary>
/// Reads asynchronously from the stream, terminating as soon as the <paramref name="regex"/> is matched.
/// </summary>
/// <param name="regex">The regex to match.</param>
/// <returns>Any text read from the stream.</returns>
/// <inheritdoc/>
public string TerminatedRead(Regex regex)
{
return TerminatedRead(regex, TimeSpan.FromMilliseconds(Client.DefaultTimeoutMs));
}

/// <summary>
/// Reads synchronously from the stream, terminating as soon as the <paramref name="terminator"/> is located.
/// </summary>
/// <param name="terminator">The terminator.</param>
/// <param name="timeout">The timeout.</param>
/// <returns>Any text read from the stream.</returns>
/// <inheritdoc/>
public string TerminatedRead(string terminator, TimeSpan timeout)
{
return TerminatedRead(terminator, timeout, 1);
}

/// <summary>
/// Reads synchronously from the stream, terminating as soon as the <paramref name="regex"/> is located.
/// </summary>
/// <param name="regex">The terminator.</param>
/// <param name="timeout">The timeout.</param>
/// <returns>Any text read from the stream.</returns>
/// <inheritdoc/>
public string TerminatedRead(Regex regex, TimeSpan timeout)
{
return TerminatedRead(regex, timeout, 1);
}

/// <summary>
/// Reads synchronously from the stream, terminating as soon as the <paramref name="terminator"/> is located.
/// </summary>
/// <param name="terminator">The terminator.</param>
/// <param name="timeout">The maximum time to wait.</param>
/// <param name="millisecondSpin">The millisecond spin between each read from the stream.</param>
/// <returns>Any text read from the stream.</returns>
/// <inheritdoc/>
public string TerminatedRead(string terminator, TimeSpan timeout, int millisecondSpin)
{
var endTimeout = DateTime.Now.Add(timeout);
Expand All @@ -157,13 +115,7 @@ public string TerminatedRead(string terminator, TimeSpan timeout, int millisecon
return s;
}

/// <summary>
/// Reads synchronously from the stream, terminating as soon as the <paramref name="regex"/> is matched.
/// </summary>
/// <param name="regex">The regex to match.</param>
/// <param name="timeout">The maximum time to wait.</param>
/// <param name="millisecondSpin">The millisecond spin between each read from the stream.</param>
/// <returns>Any text read from the stream.</returns>
/// <inheritdoc/>
public string TerminatedRead(Regex regex, TimeSpan timeout, int millisecondSpin)
{
var endTimeout = DateTime.Now.Add(timeout);
Expand Down
6 changes: 1 addition & 5 deletions PrimS.Telnet.Sync/ClientCancellable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
/// </summary>
public partial class Client
{
/// <summary>
/// Reads from the stream.
/// </summary>
/// <param name="timeout">The timeout.</param>
/// <returns>Any text read from the stream.</returns>
/// <inheritdoc/>
public string Read(TimeSpan timeout)
{
var handler = new ByteStreamHandler(ByteStream, InternalCancellation, MillisecondReadDelay);
Expand Down
Loading

0 comments on commit 63a3cf8

Please sign in to comment.