Esempio n. 1
0
        private void cmdTest_Click(object sender, EventArgs e)
        {
            try
            {
                string machineName    = ApplyConfigVarsOnField(txtMachineName.Text);
                string userName       = ApplyConfigVarsOnField(txtUsername.Text);
                string password       = ApplyConfigVarsOnField(txtPassword.Text);
                string privateKeyFile = ApplyConfigVarsOnField(txtPrivateKeyFile.Text);
                string passPhrase     = ApplyConfigVarsOnField(txtPassPhrase.Text);

                using (Renci.SshNet.SshClient sshClient = SshClientTools.GetSSHConnection(
                           optPrivateKey.Checked ? SSHSecurityOption.PrivateKey : optPassword.Checked?SSHSecurityOption.Password: SSHSecurityOption.KeyboardInteractive,
                           machineName,
                           (int)sshPortNumericUpDown.Value,
                           userName,
                           password,
                           privateKeyFile,
                           passPhrase))
                {
                    if (sshClient.IsConnected)
                    {
                        MessageBox.Show(string.Format("Success\r\n{0}", sshClient.RunCommand("cat /proc/version").Result), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    sshClient.Disconnect();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Fail!\r\n{0}", ex.Message), "Test", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void lblAutoAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                SSHConnectionDetails sshConnection = sshConnectionDetails.Clone();
                sshConnection.ComputerName     = ApplyConfigVarsOnField(sshConnection.ComputerName);
                sshConnection.UserName         = ApplyConfigVarsOnField(sshConnection.UserName);
                sshConnection.Password         = ApplyConfigVarsOnField(sshConnection.Password);
                sshConnection.PrivateKeyFile   = ApplyConfigVarsOnField(sshConnection.PrivateKeyFile);
                sshConnection.PassPhrase       = ApplyConfigVarsOnField(sshConnection.PassPhrase);
                sshConnection.ConnectionName   = ApplyConfigVarsOnField(sshConnection.ConnectionName);
                sshConnection.ConnectionString = ApplyConfigVarsOnField(sshConnection.ConnectionString);

                if (lvwNICs.Items.Count > 0 && (MessageBox.Show("Clear all existing entries?", "Clear", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No))
                {
                    return;
                }
                else
                {
                    lvwNICs.Items.Clear();
                    lvwNICs.Items.Add(new ListViewItem("Querying " + sshConnection.ComputerName + "..."));
                    Application.DoEvents();
                }

                Renci.SshNet.SshClient sshClient = SshClientTools.GetSSHConnection(sshConnection);
                if (sshClient.IsConnected)
                {
                    lvwNICs.Items.Clear();
                    foreach (NicInfo di in NicInfo.GetCurrentNicStats(sshClient))
                    {
                        NIXNICSubEntry dsse = new NIXNICSubEntry()
                        {
                            NICName = di.Name, WarningValueKB = (long)warningNumericUpDown.Value, ErrorValueKB = (long)errorNumericUpDown.Value
                        };
                        ListViewItem lvi = new ListViewItem()
                        {
                            Text = dsse.NICName
                        };
                        lvi.SubItems.Add(dsse.WarningValueKB.ToString());
                        lvi.SubItems.Add(dsse.ErrorValueKB.ToString());
                        lvi.Tag = dsse;
                        lvwNICs.Items.Add(lvi);
                    }
                }
                else
                {
                    lvwNICs.Items.Clear();
                    MessageBox.Show("Could not connect to computer!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
 private void lblAutoAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     try
     {
         if (lvwDisks.Items.Count > 0 && (MessageBox.Show("Clear all existing entries?", "Clear", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No))
         {
             return;
         }
         else
         {
             lvwDisks.Items.Clear();
             lvwDisks.Items.Add(new ListViewItem("Querying " + sshConnectionDetails.ComputerName + "..."));
             Application.DoEvents();
         }
         Renci.SshNet.SshClient sshClient = SshClientTools.GetSSHConnection(sshConnectionDetails);
         if (sshClient.IsConnected)
         {
             lvwDisks.Items.Clear();
             foreach (DiskIOInfo di in DiskIOInfo.GetCurrentDiskStats(sshClient))
             {
                 NIXDiskIOSubEntry dsse = new NIXDiskIOSubEntry()
                 {
                     DiskName = di.Name, WarningValue = (double)warningNumericUpDown.Value, ErrorValue = (double)errorNumericUpDown.Value
                 };
                 ListViewItem lvi = new ListViewItem()
                 {
                     Text = dsse.DiskName
                 };
                 lvi.SubItems.Add(dsse.WarningValue.ToString());
                 lvi.SubItems.Add(dsse.ErrorValue.ToString());
                 lvi.Tag = dsse;
                 lvwDisks.Items.Add(lvi);
             }
         }
         else
         {
             lvwDisks.Items.Clear();
             MessageBox.Show("Could not connect to computer!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }