mirror of
https://github.com/proxysu/ProxySU.git
synced 2024-11-22 05:06:08 +03:00
学习完善异常处理
This commit is contained in:
parent
dceea20538
commit
b8fd635357
@ -28,17 +28,35 @@ namespace ProxySU
|
||||
RadioButtonNoProxy.IsChecked = true;
|
||||
RadioButtonProxyNoLogin.IsChecked = true;
|
||||
}
|
||||
|
||||
//System.Diagnostics.Process exitProgram = System.Diagnostics.Process.GetProcessById(System.Diagnostics.Process.GetCurrentProcess().Id);
|
||||
private void Button_Login_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//byte[] expectedFingerPrint = new byte[] {
|
||||
// 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31,
|
||||
// 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b
|
||||
// };
|
||||
if (string.IsNullOrEmpty(TextBoxHost.Text) == true || string.IsNullOrEmpty(TextBoxPort.Text) == true || string.IsNullOrEmpty(TextBoxUserName.Text) == true)
|
||||
{
|
||||
MessageBox.Show("主机地址、主机端口、用户名为必填项,不能为空");
|
||||
//exitProgram.Kill();
|
||||
return;
|
||||
}
|
||||
string sshHostName = TextBoxHost.Text.ToString();
|
||||
int sshPort = int.Parse(TextBoxPort.Text);
|
||||
string sshUser = TextBoxUserName.Text.ToString();
|
||||
if (RadioButtonPasswordLogin.IsChecked == true && string.IsNullOrEmpty(PasswordBoxHostPassword.Password) == true)
|
||||
{
|
||||
MessageBox.Show("登录密码为必填项,不能为空");
|
||||
//exitProgram.Kill();
|
||||
return;
|
||||
}
|
||||
string sshPassword = PasswordBoxHostPassword.Password.ToString();
|
||||
if (RadioButtonCertLogin.IsChecked == true && string.IsNullOrEmpty(TextBoxCertFilePath.Text) == true)
|
||||
{
|
||||
MessageBox.Show("密钥文件为必填项,不能为空");
|
||||
//exitProgram.Kill();
|
||||
return;
|
||||
}
|
||||
string sshPrivateKey = TextBoxCertFilePath.Text.ToString();
|
||||
ProxyTypes proxyTypes = new ProxyTypes();//默认为None
|
||||
//MessageBox.Show(proxyTypes.ToString());
|
||||
@ -61,15 +79,29 @@ namespace ProxySU
|
||||
}
|
||||
|
||||
//MessageBox.Show(proxyTypes.ToString());
|
||||
if (RadioButtonNoProxy.IsChecked==false&&(string.IsNullOrEmpty(TextBoxProxyHost.Text)==true||string.IsNullOrEmpty(TextBoxProxyPort.Text)==true))
|
||||
{
|
||||
MessageBox.Show("如果选择了代理,则代理地址与端口不能为空");
|
||||
//exitProgram.Kill();
|
||||
return;
|
||||
}
|
||||
string sshProxyHost = TextBoxProxyHost.Text.ToString();
|
||||
int sshProxyPort = int.Parse(TextBoxProxyPort.Text.ToString());
|
||||
if (RadiobuttonProxyYesLogin.IsChecked == true && (string.IsNullOrEmpty(TextBoxProxyUserName.Text) == true || string.IsNullOrEmpty(PasswordBoxProxyPassword.Password) == true))
|
||||
{
|
||||
MessageBox.Show("如果代理需要登录,则代理登录的用户名与密码不能为空");
|
||||
//exitProgram.Kill();
|
||||
return;
|
||||
}
|
||||
string sshProxyUser = TextBoxProxyUserName.Text.ToString();
|
||||
string sshProxyPassword = PasswordBoxProxyPassword.Password.ToString();
|
||||
|
||||
//判断相关值是否为空
|
||||
|
||||
|
||||
//var connectionInfo = new PasswordConnectionInfo(sshHostName, sshPort, sshUser, sshPassword);
|
||||
|
||||
var connectionInfo = new ConnectionInfo(
|
||||
var connectionInfo = new ConnectionInfo(
|
||||
sshHostName,
|
||||
sshPort,
|
||||
sshUser,
|
||||
@ -78,11 +110,29 @@ namespace ProxySU
|
||||
sshProxyPort,
|
||||
sshProxyUser,
|
||||
sshProxyPassword,
|
||||
new PasswordAuthenticationMethod(sshUser, sshPassword),
|
||||
new PasswordAuthenticationMethod(sshUser, sshPassword)
|
||||
//new PrivateKeyAuthenticationMethod(sshUser, new PrivateKeyFile(sshPrivateKey))
|
||||
);
|
||||
|
||||
if (RadioButtonCertLogin.IsChecked == true)
|
||||
{
|
||||
connectionInfo = new ConnectionInfo(
|
||||
sshHostName,
|
||||
sshPort,
|
||||
sshUser,
|
||||
proxyTypes,
|
||||
sshProxyHost,
|
||||
sshProxyPort,
|
||||
sshProxyUser,
|
||||
sshProxyPassword,
|
||||
//new PasswordAuthenticationMethod(sshUser, sshPassword)
|
||||
new PrivateKeyAuthenticationMethod(sshUser, new PrivateKeyFile(sshPrivateKey))
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
#region
|
||||
//using (var client = new SshClient(sshHostName, sshPort, sshUser, sshPassword))
|
||||
{
|
||||
// client.HostKeyReceived += (sender, e) =>
|
||||
@ -103,10 +153,20 @@ namespace ProxySU
|
||||
// e.CanTrust = false;
|
||||
// }
|
||||
// };
|
||||
client.Connect();
|
||||
client.RunCommand("echo 1111 >> test.json");
|
||||
MessageBox.Show(client.ConnectionInfo.ServerVersion.ToString());
|
||||
client.Disconnect();
|
||||
#endregion
|
||||
try
|
||||
{
|
||||
client.Connect();
|
||||
client.RunCommand("echo 1111 >> test.json");
|
||||
MessageBox.Show(client.ConnectionInfo.ServerVersion.ToString());
|
||||
//MessageBox.Show(client);
|
||||
client.Disconnect();
|
||||
}
|
||||
catch (Exception ex1 )
|
||||
{
|
||||
MessageBox.Show(ex1.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,12 +189,6 @@ namespace ProxySU
|
||||
}
|
||||
}
|
||||
|
||||
//private void RadioButtonHttp_Checked(object sender, RoutedEventArgs e)
|
||||
//{
|
||||
// MessageBox.Show("PrxoyHttp");
|
||||
//}
|
||||
|
||||
|
||||
private void ButtonOpenFileDialog_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var openFileDialog = new Microsoft.Win32.OpenFileDialog()
|
||||
@ -147,7 +201,7 @@ namespace ProxySU
|
||||
TextBoxCertFilePath.Text = openFileDialog.FileName;
|
||||
}
|
||||
}
|
||||
|
||||
#region
|
||||
private void RadioButtonNoProxy_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TextBlockProxyHost.IsEnabled = false;
|
||||
@ -215,5 +269,6 @@ namespace ProxySU
|
||||
TextBoxProxyUserName.IsEnabled = true;
|
||||
PasswordBoxProxyPassword.IsEnabled = true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -117,9 +117,6 @@
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="ProxySU2.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="ProxySU.ico" />
|
||||
</ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user