Please allow us to customize `OutputStream` and `ExtendedOutputStream` before executing an SSH command.
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 30/100
- issue の種類
- 機能追加
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- csharp
- 領域
- networking
調査の方向性
まず、SshCommand.OutputStream と ExtendedOutputStream、拡張可能な PipeStream 型、および ExecuteAsync エントリポイントを確認します。reflection を使わずに標準出力とエラーをリアルタイムで処理でき、コマンド実行中も両方のストリームを使用可能なままにする、公開カスタマイズメカニズムを定義して検証します。
索引モデルが issue の本文から書いたものです。
説明
I have a use case where I want real time output from the console command to be printed to the console. Unfortunately, the streams that are written to cannot be customized with the existing public interface, even though the PipeStream class is extensible. The best solution I found to do what I need to do unfortunately requires reflection.
A public interface (such as a callback) for this feature would be greatly appreciated.
public static class SshClientExtensions
{
public static async Task<SshCommand> ConnectAndExecuteCommandAsync(this SshClient client, string command, CancellationToken cancellationToken = default)
{
SshCommand sshCommand;
try
{
await client.ConnectAsync(cancellationToken);
sshCommand = client.CreateCommand(command);
using CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance;
PropertyInfo stdOutProp = typeof(SshCommand).GetProperty(nameof(SshCommand.OutputStream), bindingFlags)!;
PropertyInfo stdErrProp = typeof(SshCommand).GetProperty(nameof(SshCommand.ExtendedOutputStream), bindingFlags)!;
PipeStream stdOutStream = (PipeStream)stdOutProp.GetValue(sshCommand)!;
PipeStream stdErrStream = (PipeStream)stdErrProp.GetValue(sshCommand)!;
await stdOutStream.DisposeAsync();
await stdErrStream.DisposeAsync();
TextWriterPipeStream stdOut = new(Console.Out);
TextWriterPipeStream stdErr = new(Console.Error);
stdOutProp.SetValue(sshCommand, stdOut);
stdErrProp.SetValue(sshCommand, stdErr);
await sshCommand.ExecuteAsync(cancellationToken);
}
catch (Exception e)
{
return await Task.FromException<SshCommand>(e);
}
finally
{
client.Disconnect();
}
return sshCommand;
}
private sealed class TextWriterPipeStream : PipeStream
{
private readonly TextWriter textWriter;
public TextWriterPipeStream(TextWriter textWriter) : base()
{
this.textWriter = textWriter;
}
public override void Write(byte[] buffer, int offset, int count)
{
base.Write(buffer, offset, count);
string output = Encoding.UTF8.GetString(buffer, offset, count);
textWriter.Write(output);
}
}
}
- 主要言語
- C#
- スター
- 4.4k
- フォーク
- 993
- 平均マージ
- 9日 21時間
- マージ済み PR(30日)
- 1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
sshnet/SSH.NET のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 67/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
似ている issue
-
effort:S P3 refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
nightscout/nocturne#1532 ·
-
core dependencies
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
C#/.NET Roslyn LSP オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
DotNetNext/SqlSugar#1458 ·