diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c6b38ac..143af4a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: ../../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 @@ -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 @@ -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 diff --git a/PrimS.Telnet.CiTests/WithDummyByteStream.cs b/PrimS.Telnet.CiTests/WithDummyByteStream.cs index 8d5a9ac..d28d16a 100644 --- a/PrimS.Telnet.CiTests/WithDummyByteStream.cs +++ b/PrimS.Telnet.CiTests/WithDummyByteStream.cs @@ -25,7 +25,11 @@ public void ShouldConnect() } } +#if ASYNC [Fact(Timeout = 2000)] +#else + [Fact] +#endif public #if ASYNC async Task @@ -49,7 +53,11 @@ async Task } } +#if ASYNC [Fact(Timeout = 2000)] +#else + [Fact] +#endif public #if ASYNC async Task @@ -74,7 +82,11 @@ async Task } } +#if ASYNC [Fact(Timeout = 2000)] +#else + [Fact] +#endif public #if ASYNC async Task @@ -105,7 +117,11 @@ async Task } } +#if ASYNC [Fact(Timeout = 3000)] +#else + [Fact] +#endif public #if ASYNC async Task @@ -136,7 +152,11 @@ async Task } } +#if ASYNC [Fact(Timeout = 5000)] +#else + [Fact] +#endif public #if ASYNC async Task @@ -165,7 +185,11 @@ async Task } } +#if ASYNC [Fact(Timeout = 5000)] +#else + [Fact] +#endif public #if ASYNC async Task @@ -194,7 +218,11 @@ async Task } } +#if ASYNC [Fact(Timeout = 5000)] +#else + [Fact] +#endif public #if ASYNC async Task @@ -217,7 +245,11 @@ async Task } } +#if ASYNC [Fact(Timeout = 5000)] +#else + [Fact] +#endif public #if ASYNC async Task diff --git a/PrimS.Telnet.NetStandard/Client.cs b/PrimS.Telnet.NetStandard/Client.cs index 5b8e273..7289d75 100644 --- a/PrimS.Telnet.NetStandard/Client.cs +++ b/PrimS.Telnet.NetStandard/Client.cs @@ -58,6 +58,8 @@ public async Task WriteAsync(string command) /// 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); @@ -100,6 +102,8 @@ public async Task TerminatedReadAsync(string terminator, TimeSpan timeou /// public async Task 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)) diff --git a/PrimS.Telnet.Sync/Client.cs b/PrimS.Telnet.Sync/Client.cs index 2abaaca..9afab08 100644 --- a/PrimS.Telnet.Sync/Client.cs +++ b/PrimS.Telnet.Sync/Client.cs @@ -9,15 +9,7 @@ public partial class Client : BaseClient, IClient { - /// - /// Tries to login. - /// - /// The user name. - /// The password. - /// The login time out ms. - /// The prompt terminator to anticipate. - /// 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. - /// True if successful. + /// public bool TryLogin(string userName, string password, int loginTimeOutMs, string terminator = ">", string lineFeed = LegacyLineFeed) { try @@ -60,20 +52,13 @@ public void WriteLineRfc854(string command) Write(string.Format("{0}{1}", command, Rfc854LineFeed)); } - /// - /// Writes the line to the server. - /// - /// The command. - /// 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. + /// public void WriteLine(string command, string lineFeed = LegacyLineFeed) { Write(string.Format("{0}{1}", command, lineFeed)); } - /// - /// Writes the specified command to the server. - /// - /// The command. + /// public void Write(string command) { if (ByteStream.Connected) @@ -82,64 +67,37 @@ public void Write(string command) } } - /// - /// Reads asynchronously from the stream. - /// - /// Any text read from the stream. + /// public string Read() { return Read(TimeSpan.FromMilliseconds(Client.DefaultTimeoutMs)); } - /// - /// Reads asynchronously from the stream, terminating as soon as the is located. - /// - /// The terminator. - /// Any text read from the stream. + /// public string TerminatedRead(string terminator) { return TerminatedRead(terminator, TimeSpan.FromMilliseconds(Client.DefaultTimeoutMs)); } - /// - /// Reads asynchronously from the stream, terminating as soon as the is matched. - /// - /// The regex to match. - /// Any text read from the stream. + /// public string TerminatedRead(Regex regex) { return TerminatedRead(regex, TimeSpan.FromMilliseconds(Client.DefaultTimeoutMs)); } - /// - /// Reads synchronously from the stream, terminating as soon as the is located. - /// - /// The terminator. - /// The timeout. - /// Any text read from the stream. + /// public string TerminatedRead(string terminator, TimeSpan timeout) { return TerminatedRead(terminator, timeout, 1); } - /// - /// Reads synchronously from the stream, terminating as soon as the is located. - /// - /// The terminator. - /// The timeout. - /// Any text read from the stream. + /// public string TerminatedRead(Regex regex, TimeSpan timeout) { return TerminatedRead(regex, timeout, 1); } - /// - /// Reads synchronously from the stream, terminating as soon as the is located. - /// - /// The terminator. - /// The maximum time to wait. - /// The millisecond spin between each read from the stream. - /// Any text read from the stream. + /// public string TerminatedRead(string terminator, TimeSpan timeout, int millisecondSpin) { var endTimeout = DateTime.Now.Add(timeout); @@ -157,13 +115,7 @@ public string TerminatedRead(string terminator, TimeSpan timeout, int millisecon return s; } - /// - /// Reads synchronously from the stream, terminating as soon as the is matched. - /// - /// The regex to match. - /// The maximum time to wait. - /// The millisecond spin between each read from the stream. - /// Any text read from the stream. + /// public string TerminatedRead(Regex regex, TimeSpan timeout, int millisecondSpin) { var endTimeout = DateTime.Now.Add(timeout); diff --git a/PrimS.Telnet.Sync/ClientCancellable.cs b/PrimS.Telnet.Sync/ClientCancellable.cs index fce5108..c8425d5 100644 --- a/PrimS.Telnet.Sync/ClientCancellable.cs +++ b/PrimS.Telnet.Sync/ClientCancellable.cs @@ -9,11 +9,7 @@ /// public partial class Client { - /// - /// Reads from the stream. - /// - /// The timeout. - /// Any text read from the stream. + /// public string Read(TimeSpan timeout) { var handler = new ByteStreamHandler(ByteStream, InternalCancellation, MillisecondReadDelay); diff --git a/PrimS.Telnet.Sync/IClient.cs b/PrimS.Telnet.Sync/IClient.cs index 9d1feec..9736850 100644 --- a/PrimS.Telnet.Sync/IClient.cs +++ b/PrimS.Telnet.Sync/IClient.cs @@ -3,28 +3,94 @@ using System; using System.Text.RegularExpressions; + /// + /// Basic Telnet client. + /// public interface IClient : IBaseClient { + /// + /// Reads asynchronously from the stream. + /// + /// Any text read from the stream. string Read(); + /// + /// Reads from the stream. + /// + /// The timeout. + /// Any text read from the stream. string Read(TimeSpan timeout); + /// + /// Reads asynchronously from the stream, terminating as soon as the is matched. + /// + /// The regex to match. + /// Any text read from the stream. string TerminatedRead(Regex regex); + /// + /// Reads synchronously from the stream, terminating as soon as the is located. + /// + /// The terminator. + /// The timeout. + /// Any text read from the stream. string TerminatedRead(Regex regex, TimeSpan timeout); + /// + /// Reads synchronously from the stream, terminating as soon as the is matched. + /// + /// The regex to match. + /// The maximum time to wait. + /// The millisecond spin between each read from the stream. + /// Any text read from the stream. string TerminatedRead(Regex regex, TimeSpan timeout, int millisecondSpin); + /// + /// Reads asynchronously from the stream, terminating as soon as the is located. + /// + /// The terminator. + /// Any text read from the stream. string TerminatedRead(string terminator); + /// + /// Reads synchronously from the stream, terminating as soon as the is located. + /// + /// The terminator. + /// The timeout. + /// Any text read from the stream. string TerminatedRead(string terminator, TimeSpan timeout); + /// + /// Reads synchronously from the stream, terminating as soon as the is located. + /// + /// The terminator. + /// The maximum time to wait. + /// The millisecond spin between each read from the stream. + /// Any text read from the stream. string TerminatedRead(string terminator, TimeSpan timeout, int millisecondSpin); + /// + /// Tries to login. + /// + /// The user name. + /// The password. + /// The login time out ms. + /// The prompt terminator to anticipate. + /// 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. + /// True if successful. bool TryLogin(string userName, string password, int loginTimeOutMs, string terminator = ">", string lineFeed = Client.LegacyLineFeed); + /// + /// Writes the specified command to the server. + /// + /// The command. void Write(string command); + /// + /// Writes the line to the server. + /// + /// The command. + /// 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. void WriteLine(string command, string lineFeed = Client.LegacyLineFeed); } }