Skip to content

Commit 3bc5684

Browse files
Add SshCommand.ExecuteAsync (#1426)
* Add SshCommand.ExecuteAsync After the previous change (#1423), this basically entails swapping out the IAsyncResult for a TaskCompletionSource and hooking up the cancellation/timeout logic. As with the prior Begin/End implementation, the initiation of the command (SendExecRequest) happens synchronously, so there's a bit of room for improvement there, but otherwise it is the Task-based async that we know and like. I chose to make it void (Task)- returning instead of string like in the existing overloads, so that OutputStream is not automatically consumed (and encoded as a string) when that may not be desired. As in #650, I was initially considering changing the other overloads to be void-returning as well, but decided that it was not worth the break since most people will probably want to change over to ExecuteAsync anyway. * Update examples --------- Co-authored-by: Wojciech Nagórski <[email protected]>
1 parent 919af75 commit 3bc5684

File tree

9 files changed

+259
-274
lines changed

9 files changed

+259
-274
lines changed

docfx/examples.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,17 @@ using (var client = new SshClient("sftp.foo.com", "guest", "pwd"))
113113
// Make the server echo back the input file with "cat"
114114
using (SshCommand command = client.CreateCommand("cat"))
115115
{
116-
IAsyncResult asyncResult = command.BeginExecute();
116+
Task executeTask = command.ExecuteAsync(CancellationToken.None);
117117

118118
using (Stream inputStream = command.CreateInputStream())
119119
{
120120
inputStream.Write("Hello World!"u8);
121121
}
122122

123-
string result = command.EndExecute(asyncResult);
123+
await executeTask;
124124

125-
Console.WriteLine(result); // "Hello World!"
125+
Console.WriteLine(command.ExitStatus); // 0
126+
Console.WriteLine(command.Result); // "Hello World!"
126127
}
127128
}
128129
```

src/Renci.SshNet/.editorconfig

+8
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,11 @@ dotnet_diagnostic.CA5350.severity = none
180180
# CA5351: Do Not Use Broken Cryptographic Algorithms
181181
# https://learn.microsoft.com/en-ca/dotnet/fundamentals/code-analysis/quality-rules/ca5351
182182
dotnet_diagnostic.CA5351.severity = none
183+
184+
# MA0040: Forward the CancellationToken parameter to methods that take one
185+
# Partial/noisy duplicate of CA2016
186+
dotnet_diagnostic.MA0040.severity = none
187+
188+
# MA0042: Do not use blocking calls in an async method
189+
# duplicate of CA1849
190+
dotnet_diagnostic.MA0042.severity = none

src/Renci.SshNet/CommandAsyncResult.cs

-60
This file was deleted.

0 commit comments

Comments
 (0)