📄 wmpiconfig.cs
字号:
{ output_textBox.AppendText(host + "\r\n"); p.Start(); while ((val = p.StandardOutput.ReadLine()) != null) { output_textBox.AppendText(val + "\r\n"); } if (!p.WaitForExit(20000)) { p.Kill(); } p.Close(); } catch (Exception) { } } private Hashtable get_setttings_hash() { int i; Hashtable h = new Hashtable(); for (i=0; i<list.Items.Count; i+=2) { if (list.Items[i].Checked) { h[list.Items[i].Text] = list.Items[i+1].Text; } } return h; } private string get_mpiexec() { string mpiexec = ""; object obj; try { RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH2"); if (key != null) { obj = key.GetValue("Path"); key.Close(); if (obj != null) { mpiexec = obj.ToString(); if (mpiexec.EndsWith(@"\")) { mpiexec = mpiexec + @"bin\mpiexec.exe"; } else { mpiexec = mpiexec + @"\bin\mpiexec.exe"; } if (!File.Exists(mpiexec)) { mpiexec = ""; } } } if (mpiexec == "") { key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH\SMPD"); if (key != null) { obj = key.GetValue("binary"); key.Close(); if (obj != null) { mpiexec = obj.ToString().Replace("smpd.exe", "mpiexec.exe"); if (!File.Exists(mpiexec)) { mpiexec = ""; } } } } if (mpiexec == "") { mpiexec = "mpiexec.exe"; } mpiexec = mpiexec.Trim(); /* if (mpiexec.IndexOf(' ') != -1) { mpiexec = "\"" + mpiexec + "\""; } */ } catch (Exception) { mpiexec = "mpiexec.exe"; } return mpiexec; } private string get_smpd() { string smpd = ""; object obj; try { RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH2"); if (key != null) { obj = key.GetValue("Path"); key.Close(); if (obj != null) { smpd = obj.ToString(); if (smpd.EndsWith(@"\")) { smpd = smpd + @"bin\smpd.exe"; } else { smpd = smpd + @"\bin\smpd.exe"; } if (!File.Exists(smpd)) { smpd = ""; } } } if (smpd == "") { key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH\SMPD"); if (key != null) { obj = key.GetValue("binary"); key.Close(); if (obj != null) { smpd = obj.ToString(); if (!File.Exists(smpd)) { smpd = ""; } } } } if (smpd == "") { smpd = "smpd.exe"; } smpd = smpd.Trim(); /* if (smpd.IndexOf(' ') != -1) { smpd = "\"" + smpd + "\""; } */ } catch (Exception) { smpd = "smpd.exe"; } return smpd; } private string get_value(string key) { object obj; try { RegistryKey regkey = Registry.LocalMachine.OpenSubKey(@"Software\MPICH\SMPD"); if (regkey != null) { obj = regkey.GetValue(key); regkey.Close(); if (obj != null) { return obj.ToString(); } } } catch (Exception) { } return ""; } private void get_settings_button_Click(object sender, System.EventArgs e) { bool success; Hashtable h; Cursor.Current = Cursors.WaitCursor; output_textBox.Text = ""; h = get_settings(host_textBox.Text); UpdateHash(h); UpdateListBox(); add_host_to_list(host_textBox.Text); success = !(h.Contains("error") || h.Count == 0); set_host_background(host_textBox.Text, success); Cursor.Current = Cursors.Default; } private void add_host_to_list(string host) { bool found = false; foreach (ListViewItem item in hosts_list.Items) { if (String.Compare(item.Text, host, true) == 0) found = true; } if (!found) { hosts_list.Items.Add(host); } } private void add_host_version_to_list(string host, string version) { foreach (ListViewItem item in hosts_list.Items) { if (String.Compare(item.Text, host, true) == 0) { if (item.SubItems.Count == 2) item.SubItems[1].Text = version; else item.SubItems.Add(version); return; } } } delegate void SetHostBackgroundDelegate(string host, bool success); private void set_host_background(string host, bool success) { foreach (ListViewItem item in hosts_list.Items) { if (String.Compare(item.Text, host, true) == 0) { if (success) item.BackColor = Color.GreenYellow; else item.BackColor = Color.LightGray; } } } private void apply_button_Click(object sender, System.EventArgs e) { Hashtable h; Cursor.Current = Cursors.WaitCursor; output_textBox.Clear(); h = get_setttings_hash(); set_settings(host_textBox.Text, h); Cursor.Current = Cursors.Default; } private void apply_all_button_Click(object sender, System.EventArgs e) { Hashtable h; Cursor.Current = Cursors.WaitCursor; output_textBox.Clear(); h = get_setttings_hash(); scan_progressBar.Value = 0; scan_progressBar.Maximum = hosts_list.Items.Count; foreach (ListViewItem item in hosts_list.Items) { set_settings(item.Text, h); scan_progressBar.PerformStep(); } Cursor.Current = Cursors.Default; } private void cancel_button_Click(object sender, System.EventArgs e) { Close(); } private void list_ItemActivate(object sender, System.EventArgs e) { int index; if (list.SelectedIndices.Count > 0) { index = list.SelectedIndices[0]; if ((index & 0x1) == 0) { index++; } // turn on and begin editing the value field list.LabelEdit = true; list.Items[index].BeginEdit(); } } private void list_AfterLabelEdit(object sender, System.Windows.Forms.LabelEditEventArgs e) { // turn off editing after a field has been modified to prevent the name from being modified list.LabelEdit = false; list.Items[e.Item].Checked = true; } private void ok_button_Click(object sender, System.EventArgs e) { Close(); } private void hosts_list_SelectedIndexChanged(object sender, System.EventArgs e) { if (hosts_list.SelectedItems.Count > 0) { host_textBox.Text = hosts_list.SelectedItems[0].Text; if (click_checkBox.Checked) { get_settings_button_Click(null, null); } if (hosts_list.SelectedItems[0].BackColor == Color.LightGray) { list.BackColor = Color.LightGray; list.Enabled = false; } else { list.BackColor = orig_background; list.Enabled = true; } } else { list.BackColor = orig_background; list.Enabled = true; } } private void domain_comboBox_DropDown(object sender, System.EventArgs e) { if (!domain_populated) { PopulateDomainList(); domain_populated = true; } } private void get_hosts_button_Click(object sender, System.EventArgs e) { string [] hosts; if (domain_comboBox.Text.ToLower() == Environment.MachineName.ToLower()) { hosts = new string[1] { Environment.MachineName }; } else { hosts = GetHostNames(); } if (hosts != null) { if (!append_checkBox.Checked) { hosts_list.Items.Clear(); } // FIXME: This is an N^2 algorithm. // It probably won't slow down until there are hundreds of hosts available. // A Hashtable should be used instead. foreach (string s in hosts) { bool found = false; foreach (ListViewItem item in hosts_list.Items) { if (item.Text.ToLower() == s.ToLower()) found = true; } if (!found) { hosts_list.Items.Add(s); } } } } private void wmpiconfig_Load(object sender, System.EventArgs e) { tool_tip = new ToolTip(); tool_tip.SetToolTip(append_checkBox, "Append hosts to the list"); tool_tip.SetToolTip(click_checkBox, "Get settings when a host name is selected"); tool_tip.SetToolTip(apply_button, "Apply the checked settings to the host in the host edit box"); tool_tip.SetToolTip(apply_all_button, "Apply the checked settings to all the hosts in the host list"); tool_tip.SetToolTip(scan_button, "Retrieve the settings from the hosts in the host list"); tool_tip.SetToolTip(get_hosts_button, "Get the host names from the specified domain"); tool_tip.SetToolTip(toggle_button, "Check or uncheck all the checked settings"); tool_tip.SetToolTip(versions_button, "Retrieve the version from the hosts in the host list"); } bool check_recursed = false; private void list_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e) { int other_index; if (!check_recursed) { check_recursed = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -