mirror of
https://github.com/proxysu/ProxySU.git
synced 2024-11-25 14:46:08 +03:00
学习添加进度显示栏
This commit is contained in:
parent
b8fd635357
commit
dbb32d72aa
@ -96,9 +96,13 @@ namespace ProxySU
|
|||||||
string sshProxyUser = TextBoxProxyUserName.Text.ToString();
|
string sshProxyUser = TextBoxProxyUserName.Text.ToString();
|
||||||
string sshProxyPassword = PasswordBoxProxyPassword.Password.ToString();
|
string sshProxyPassword = PasswordBoxProxyPassword.Password.ToString();
|
||||||
|
|
||||||
//判断相关值是否为空
|
TextBlockSetUpProcessing.Text = "登录中";
|
||||||
|
ProgressBarSetUpProcessing.IsIndeterminate = true;
|
||||||
|
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
//var connectionInfo = new PasswordConnectionInfo(sshHostName, sshPort, sshUser, sshPassword);
|
//var connectionInfo = new PasswordConnectionInfo(sshHostName, sshPort, sshUser, sshPassword);
|
||||||
|
|
||||||
var connectionInfo = new ConnectionInfo(
|
var connectionInfo = new ConnectionInfo(
|
||||||
@ -131,10 +135,11 @@ namespace ProxySU
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var client = new SshClient(connectionInfo))
|
|
||||||
#region
|
|
||||||
//using (var client = new SshClient(sshHostName, sshPort, sshUser, sshPassword))
|
//using (var client = new SshClient(sshHostName, sshPort, sshUser, sshPassword))
|
||||||
|
using (var client = new SshClient(connectionInfo))
|
||||||
|
|
||||||
{
|
{
|
||||||
|
#region
|
||||||
// client.HostKeyReceived += (sender, e) =>
|
// client.HostKeyReceived += (sender, e) =>
|
||||||
// {
|
// {
|
||||||
// if (expectedFingerPrint.Length == e.FingerPrint.Length)
|
// if (expectedFingerPrint.Length == e.FingerPrint.Length)
|
||||||
@ -154,19 +159,59 @@ namespace ProxySU
|
|||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
#endregion
|
#endregion
|
||||||
try
|
|
||||||
{
|
|
||||||
client.Connect();
|
client.Connect();
|
||||||
|
if (client.IsConnected == true)
|
||||||
|
{
|
||||||
|
TextBlockSetUpProcessing.Text = "主机已登录";
|
||||||
|
ProgressBarSetUpProcessing.IsIndeterminate = false;
|
||||||
|
ProgressBarSetUpProcessing.Value = 100;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TextBlockSetUpProcessing.Text = "主机登录失败";
|
||||||
|
ProgressBarSetUpProcessing.IsIndeterminate = false;
|
||||||
|
ProgressBarSetUpProcessing.Value = 0;
|
||||||
|
}
|
||||||
client.RunCommand("echo 1111 >> test.json");
|
client.RunCommand("echo 1111 >> test.json");
|
||||||
MessageBox.Show(client.ConnectionInfo.ServerVersion.ToString());
|
MessageBox.Show(client.ConnectionInfo.ServerVersion.ToString());
|
||||||
//MessageBox.Show(client);
|
//MessageBox.Show(client);
|
||||||
client.Disconnect();
|
client.Disconnect();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex1 )
|
}
|
||||||
|
catch (Exception ex1)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex1.Message);
|
//MessageBox.Show(ex1.Message);
|
||||||
|
if (ex1.Message.Contains("连接尝试失败") == true)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"{ex1.Message}\n请检查主机地址及端口是否正确,如果通过代理,请检查代理是否正常工作");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (ex1.Message.Contains("denied (password)") == true)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"{ex1.Message}\n密码错误或用户名错误");
|
||||||
|
}
|
||||||
|
else if (ex1.Message.Contains("Invalid private key file") == true)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"{ex1.Message}\n所选密钥文件错误或者格式不对");
|
||||||
|
}
|
||||||
|
else if (ex1.Message.Contains("denied (publickey)") == true)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"{ex1.Message}\n使用密钥登录,密钥文件错误或用户名错误");
|
||||||
|
}
|
||||||
|
else if (ex1.Message.Contains("目标计算机积极拒绝") == true)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"{ex1.Message}\n主机地址错误,如果使用了代理,也可能是连接代理的端口错误");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("未知错误");
|
||||||
|
}
|
||||||
|
TextBlockSetUpProcessing.Text = "主机登录失败";
|
||||||
|
ProgressBarSetUpProcessing.IsIndeterminate = false;
|
||||||
|
ProgressBarSetUpProcessing.Value = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user