📄 wmpiconfig.cs
字号:
this.Load += new System.EventHandler(this.wmpiconfig_Load); this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new wmpiconfig()); } internal void PopulateDomainList() { ComputerBrowser ce; string domainName = ""; string currentDomain = System.Environment.UserDomainName; int index = -1; Cursor.Current = Cursors.WaitCursor; // browse for domains ce = new ComputerBrowser(ComputerBrowser.ServerType.SV_TYPE_DOMAIN_ENUM); for (int i=0; i<ce.Length; i++) { domainName = ce[i].Name; // Add the name to the dropdown list if it already doesn't exist bool found = false; foreach (string str in domain_comboBox.Items) { if (str.ToLower() == domainName.ToLower()) found = true; } if (!found) { domain_comboBox.Items.Add(domainName); } // Save the index of the current machine's domain so it will be selected by default if (domainName.ToLower() == currentDomain.ToLower()) { index = i; } } if (index == -1) { index = domain_comboBox.Items.Add(currentDomain); } domain_comboBox.SelectedIndex = index; Cursor.Current = Cursors.Default; } internal string [] GetHostNames() { ComputerBrowser ce; string [] results = null; Cursor.Current = Cursors.WaitCursor; ce = new ComputerBrowser(domain_comboBox.Text); int numServer = ce.Length; if (ce.LastError.Length == 0) { IEnumerator enumerator = ce.GetEnumerator(); // add the domain text to the dropdown list if it isn't already there bool found = false; foreach (string str in domain_comboBox.Items) { if (str == domain_comboBox.Text) { found = true; } } if (!found) { domain_comboBox.Items.Add(domain_comboBox.Text); } results = new string[numServer]; int i = 0; while (enumerator.MoveNext()) { results[i] = ce[i].Name; i++; } } else { output_textBox.Text = "Error \"" + ce.LastError + "\""; } Cursor.Current = Cursors.Default; return results; } private void UpdateHash(Hashtable h) { // update or add entries to the internal hash for each key in the input hash foreach (string str in h.Keys) { if (str != "binary") // ignore the smpd binary key because it is machine specific { if (hash.Contains(str)) { ((Setting)hash[str])._value = (string)h[str]; } else { hash[str] = new Setting(str, (string)h[str], "", ""); } } } // remove settings from the internal hash for keys not in the input hash foreach (string str in hash.Keys) { if (!h.Contains(str)) { ((Setting)hash[str])._value = ""; } } } private void UpdateListBox() { int i; Hashtable h = new Hashtable(); // make a hash of the settings already in the listbox for (i=0; i<list.Items.Count; i+=2) { // add the name to the hash h.Add(list.Items[i].Text, i+1); // clear the current setting list.Items[i+1].Text = ""; } // update or add items to the listbox foreach (string str in hash.Keys) { if (h.Contains(str)) { i = (int)h[str]; list.Items[i].Text = ((Setting)hash[str])._value; } else { Setting s = (Setting)hash[str]; ListViewItem item = list.Items.Add(str); item.BackColor = setting_color; item = list.Items.Add(s._value); item.SubItems.Add(s._default_val); item.SubItems.Add(s._available_values); } } } delegate void ScanHostDelegate(string host); private void ScanHost(string host) { bool success; string result = host + "\r\n"; Hashtable h; h = get_settings(host); success = !(h.Contains("error") || h.Count == 0); SetHostBackgroundDelegate sd = new SetHostBackgroundDelegate(set_host_background); object [] sd_list = new object[2] { host, success }; Invoke(sd, sd_list); //set_host_background(host, success); foreach (string key in h.Keys) { result = result + key + " = " + h[key] + "\r\n"; } UpdateHostScanResultDelegate rd = new UpdateHostScanResultDelegate(UpdateHostScanResult); object [] list = new object[1] { result }; Invoke(rd, list); } delegate void UpdateHostScanResultDelegate(string result); private void UpdateHostScanResult(string result) { output_textBox.AppendText(result); scan_progressBar.PerformStep(); } delegate void ScanHostVersionDelegate(string host); private void ScanHostVersion(string host) { string version; version = get_version(host); UpdateHostScanVersionResultDelegate rd = new UpdateHostScanVersionResultDelegate(UpdateHostScanVersionResult); object [] list = new object[2] { host, version }; Invoke(rd, list); } delegate void UpdateHostScanVersionResultDelegate(string host, string version); private void UpdateHostScanVersionResult(string host, string version) { add_host_version_to_list(host, version); scan_progressBar.PerformStep(); } private void scan_button_Click(object sender, System.EventArgs e) { // Get the versions versions_button_Click(sender, e); // Then get the rest of the details scan_progressBar.Value = 0; scan_progressBar.Maximum = hosts_list.Items.Count; output_textBox.Text = ""; foreach (ListViewItem item in hosts_list.Items) { item.BackColor = orig_background; ScanHostDelegate shd = new ScanHostDelegate(ScanHost); shd.BeginInvoke(item.Text, null, null); } } private void VerifyEncryptedPasswordExists() { try { bool popup = true; string mpiexec = get_mpiexec();#if VERIFY_USING_REGISTRY // Check the registry for the encrypted password // This code will have to be kept synchronized with the smpd code // The advantage of this approach is that the credentials don't have to be valid on the local host RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\MPICH"); if (key != null) { // check to see that an encrypted password for the current user exists object obj = key.GetValue("smpdPassword"); key.Close(); if (obj != null) { popup = false; } }#else // Or run "mpiexec -validate" and check the output for SUCCESS // This code will last longer because it doesn't rely on known information about the smpd implementation. // The disadvantage of this code is that the user credentials have to be valid on the local host. Process p1 = new Process(); p1.StartInfo.RedirectStandardOutput = true; p1.StartInfo.RedirectStandardError = true; p1.StartInfo.UseShellExecute = false; p1.StartInfo.CreateNoWindow = true; p1.StartInfo.FileName = mpiexec; p1.StartInfo.Arguments = "-validate"; p1.Start(); string output = p1.StandardOutput.ReadToEnd() + p1.StandardError.ReadToEnd(); p1.WaitForExit(); p1.Close(); if (output.IndexOf("SUCCESS") != -1) { popup = false; }#endif if (popup) { string wmpiregister; wmpiregister = mpiexec.Replace("mpiexec.exe", "wmpiregister.exe"); Process p = new Process(); p.StartInfo.FileName = wmpiregister; p.Start(); p.WaitForExit(); } } catch (Exception) { } } private Hashtable get_settings(string host) { string option, val; Hashtable hash = new Hashtable(); VerifyEncryptedPasswordExists(); Process p = new Process(); p.StartInfo.FileName = mpiexec; p.StartInfo.Arguments = string.Format("-timeout 20 -noprompt -path {{SMPD_PATH}} -n 1 -host {0} smpd.exe -enumerate", host); p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; //MessageBox.Show("About to launch: " + p.StartInfo.FileName + " " + p.StartInfo.Arguments); try { p.Start(); while ((option = p.StandardOutput.ReadLine()) != null) { val = p.StandardOutput.ReadLine(); if (val == null) break; hash.Add(option, val); } if (!p.WaitForExit(20000)) { p.Kill(); } if (p.ExitCode != 0) { hash.Clear(); } p.Close(); } catch (Exception) { hash.Clear(); hash.Add("error", host + ": Unable to detect the settings"); } if (hash.Count == 0) { hash.Add("error", host + ": MPICH2 not installed or unable to query the host"); } return hash; } private string get_version(string host) { string version = ""; Process p = new Process(); p.StartInfo.FileName = smpd; p.StartInfo.Arguments = string.Format("-version {0}", host); p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; //MessageBox.Show("About to launch: " + p.StartInfo.FileName + " " + p.StartInfo.Arguments); try { p.Start(); version = p.StandardOutput.ReadToEnd(); if (!p.WaitForExit(20000)) { p.Kill(); } if (p.ExitCode != 0) { version = ""; } p.Close(); } catch (Exception) { } return version.Trim(); } private void set_settings(string host, Hashtable h) { StringBuilder str; string val; if (h.Keys.Count < 1) { // nothing to set return; } VerifyEncryptedPasswordExists(); str = new StringBuilder("-timeout 20 -noprompt -path {SMPD_PATH} -n 1 -host "); str.AppendFormat("{0} smpd.exe", host); foreach (string key in h.Keys) { val = (string)h[key]; if (val.IndexOf(' ') != -1 || val.Length == 0) { str.AppendFormat(" -set {0} \"{1}\"", key, val); } else { str.AppendFormat(" -set {0} {1}", key, val); } } //output_textBox.Text = str.ToString(); Process p = new Process(); p.StartInfo.FileName = mpiexec; p.StartInfo.Arguments = str.ToString(); p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; //MessageBox.Show("About to launch: " + p.StartInfo.FileName + " " + p.StartInfo.Arguments); try
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -