root/mpich2/trunk/src/pm/smpd/wmpiexec/wmpiexec.cs @ 100

Revision 100, 61.4 KB (checked in by balaji, 2 years ago)

Added all components in the right places.

Line 
1using System;
2using System.Drawing;
3using System.Collections;
4using System.ComponentModel;
5using System.Windows.Forms;
6using System.Data;
7using Microsoft.Win32;
8using System.IO;
9using System.Threading;
10using System.Diagnostics;
11
12namespace wmpiexec
13{
14        /// <summary>
15        /// Summary description for Form1.
16        /// </summary>
17        public class wmpiexec : System.Windows.Forms.Form
18        {
19                private System.Windows.Forms.Label application_label;
20                private System.Windows.Forms.Button application_browse_button;
21                private System.Windows.Forms.Label nproc_label;
22                private System.Windows.Forms.NumericUpDown nproc_numericUpDown;
23                private System.Windows.Forms.Label wdir_label;
24                private System.Windows.Forms.TextBox wdir_textBox;
25                private System.Windows.Forms.Button wdir_browse_button;
26                private System.Windows.Forms.Label hosts_label;
27                private System.Windows.Forms.TextBox hosts_textBox;
28                private System.Windows.Forms.Button hosts_reset_button;
29                private System.Windows.Forms.Label configfile_label;
30                private System.Windows.Forms.TextBox configfile_textBox;
31                private System.Windows.Forms.Button configfile_browse_button;
32                private System.Windows.Forms.Label mpich1_label;
33                private System.Windows.Forms.TextBox mpich1_textBox;
34                private System.Windows.Forms.Button mpich1_browse_button;
35                private System.Windows.Forms.Label env_label;
36                private System.Windows.Forms.TextBox env_textBox;
37                private System.Windows.Forms.Label drive_map_label;
38                private System.Windows.Forms.TextBox drive_map_textBox;
39                private System.Windows.Forms.Label channel_label;
40                private System.Windows.Forms.ComboBox channel_comboBox;
41                private System.Windows.Forms.Button save_job_button;
42                private System.Windows.Forms.Button load_job_button;
43                private System.Windows.Forms.Button execute_button;
44                private System.Windows.Forms.Button break_button;
45                private System.Windows.Forms.RichTextBox output_richTextBox;
46                private System.Windows.Forms.ComboBox application_comboBox;
47                private System.Windows.Forms.Button show_command_button;
48                private System.Windows.Forms.TextBox command_line_textBox;
49                private System.Windows.Forms.RadioButton application_radioButton;
50                private System.Windows.Forms.RadioButton configfile_radioButton;
51                private System.Windows.Forms.RadioButton mpich1_radioButton;
52                private System.Windows.Forms.CheckBox show_bottom_checkBox;
53                private System.Windows.Forms.TextBox extra_options_textBox;
54                private System.Windows.Forms.Label extra_options_label;
55                private System.Windows.Forms.CheckBox popup_checkBox;
56                private System.Windows.Forms.Button jumpshot_button;
57                private System.Windows.Forms.CheckBox log_checkBox;
58                /// <summary>
59                /// Required designer variable.
60                /// </summary>
61                private System.ComponentModel.Container components = null;
62
63                private RunCommandDelegate run_command;
64                private IAsyncResult last_execute_result;
65                private Process process;
66                private string thread_command;
67                private string thread_mpiexec_command;
68                private string thread_mpiexec_command_args;
69                private bool thread_popup;
70                private TextReader thread_output_stream;
71                private TextReader thread_error_stream;
72                private TextWriter thread_input_stream;
73                delegate void RunCommandDelegate(string command, string mpiexec_command, string mpiexec_command_args, bool popup);
74                delegate void ReadOutputDelegate(TextReader stream);
75                delegate void ReadErrorDelegate(TextReader stream);
76                delegate void WriteInputDelegate(TextWriter stream);
77                delegate void AppendTextDelegate(string str);
78                delegate void SetProcessDelegate(Process p);
79                delegate void ResetExecuteButtonsDelegate();
80
81                private string mpiexec_command, mpiexec_command_args;
82                private int expanded_dialog_difference;
83
84                public wmpiexec()
85                {
86                        //
87                        // Required for Windows Form Designer support
88                        //
89                        InitializeComponent();
90
91                        expanded_dialog_difference = mpich1_browse_button.Bottom - show_bottom_checkBox.Bottom + 8;
92                        //MessageBox.Show(string.Format("difference = {0}", mpich1_browse_button.Bottom - show_bottom_checkBox.Bottom));
93
94                        run_command = null;
95                        last_execute_result = null;
96                        UpdateExtraControls(show_bottom_checkBox.Checked);
97                        EnableApplicationControls();
98                        DisableConfigfileControls();
99                        DisableMPICH1Controls();
100                }
101
102                /// <summary>
103                /// Clean up any resources being used.
104                /// </summary>
105                protected override void Dispose( bool disposing )
106                {
107                        if( disposing )
108                        {
109                                if (components != null) 
110                                {
111                                        components.Dispose();
112                                }
113                        }
114                        base.Dispose( disposing );
115                }
116
117                #region Windows Form Designer generated code
118                /// <summary>
119                /// Required method for Designer support - do not modify
120                /// the contents of this method with the code editor.
121                /// </summary>
122                private void InitializeComponent()
123                {
124                        System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(wmpiexec));
125                        this.application_label = new System.Windows.Forms.Label();
126                        this.application_browse_button = new System.Windows.Forms.Button();
127                        this.nproc_label = new System.Windows.Forms.Label();
128                        this.nproc_numericUpDown = new System.Windows.Forms.NumericUpDown();
129                        this.wdir_label = new System.Windows.Forms.Label();
130                        this.wdir_textBox = new System.Windows.Forms.TextBox();
131                        this.wdir_browse_button = new System.Windows.Forms.Button();
132                        this.hosts_label = new System.Windows.Forms.Label();
133                        this.hosts_textBox = new System.Windows.Forms.TextBox();
134                        this.hosts_reset_button = new System.Windows.Forms.Button();
135                        this.configfile_label = new System.Windows.Forms.Label();
136                        this.configfile_textBox = new System.Windows.Forms.TextBox();
137                        this.configfile_browse_button = new System.Windows.Forms.Button();
138                        this.mpich1_label = new System.Windows.Forms.Label();
139                        this.mpich1_textBox = new System.Windows.Forms.TextBox();
140                        this.mpich1_browse_button = new System.Windows.Forms.Button();
141                        this.env_label = new System.Windows.Forms.Label();
142                        this.env_textBox = new System.Windows.Forms.TextBox();
143                        this.drive_map_label = new System.Windows.Forms.Label();
144                        this.drive_map_textBox = new System.Windows.Forms.TextBox();
145                        this.channel_label = new System.Windows.Forms.Label();
146                        this.channel_comboBox = new System.Windows.Forms.ComboBox();
147                        this.save_job_button = new System.Windows.Forms.Button();
148                        this.load_job_button = new System.Windows.Forms.Button();
149                        this.execute_button = new System.Windows.Forms.Button();
150                        this.break_button = new System.Windows.Forms.Button();
151                        this.output_richTextBox = new System.Windows.Forms.RichTextBox();
152                        this.application_comboBox = new System.Windows.Forms.ComboBox();
153                        this.show_command_button = new System.Windows.Forms.Button();
154                        this.command_line_textBox = new System.Windows.Forms.TextBox();
155                        this.application_radioButton = new System.Windows.Forms.RadioButton();
156                        this.configfile_radioButton = new System.Windows.Forms.RadioButton();
157                        this.mpich1_radioButton = new System.Windows.Forms.RadioButton();
158                        this.show_bottom_checkBox = new System.Windows.Forms.CheckBox();
159                        this.extra_options_textBox = new System.Windows.Forms.TextBox();
160                        this.extra_options_label = new System.Windows.Forms.Label();
161                        this.popup_checkBox = new System.Windows.Forms.CheckBox();
162                        this.jumpshot_button = new System.Windows.Forms.Button();
163                        this.log_checkBox = new System.Windows.Forms.CheckBox();
164                        ((System.ComponentModel.ISupportInitialize)(this.nproc_numericUpDown)).BeginInit();
165                        this.SuspendLayout();
166                        //
167                        // application_label
168                        //
169                        this.application_label.Location = new System.Drawing.Point(24, 8);
170                        this.application_label.Name = "application_label";
171                        this.application_label.Size = new System.Drawing.Size(64, 23);
172                        this.application_label.TabIndex = 1;
173                        this.application_label.Text = "Application";
174                        //
175                        // application_browse_button
176                        //
177                        this.application_browse_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
178                        this.application_browse_button.Location = new System.Drawing.Point(480, 8);
179                        this.application_browse_button.Name = "application_browse_button";
180                        this.application_browse_button.Size = new System.Drawing.Size(24, 21);
181                        this.application_browse_button.TabIndex = 3;
182                        this.application_browse_button.Text = "...";
183                        this.application_browse_button.Click += new System.EventHandler(this.application_browse_button_Click);
184                        //
185                        // nproc_label
186                        //
187                        this.nproc_label.Location = new System.Drawing.Point(24, 32);
188                        this.nproc_label.Name = "nproc_label";
189                        this.nproc_label.Size = new System.Drawing.Size(112, 23);
190                        this.nproc_label.TabIndex = 3;
191                        this.nproc_label.Text = "Number of processes";
192                        //
193                        // nproc_numericUpDown
194                        //
195                        this.nproc_numericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
196                        this.nproc_numericUpDown.Location = new System.Drawing.Point(456, 32);
197                        this.nproc_numericUpDown.Maximum = new System.Decimal(new int[] {
198                                                                                                                                                                10000,
199                                                                                                                                                                0,
200                                                                                                                                                                0,
201                                                                                                                                                                0});
202                        this.nproc_numericUpDown.Minimum = new System.Decimal(new int[] {
203                                                                                                                                                                1,
204                                                                                                                                                                0,
205                                                                                                                                                                0,
206                                                                                                                                                                0});
207                        this.nproc_numericUpDown.Name = "nproc_numericUpDown";
208                        this.nproc_numericUpDown.Size = new System.Drawing.Size(48, 20);
209                        this.nproc_numericUpDown.TabIndex = 4;
210                        this.nproc_numericUpDown.Value = new System.Decimal(new int[] {
211                                                                                                                                                          1,
212                                                                                                                                                          0,
213                                                                                                                                                          0,
214                                                                                                                                                          0});
215                        //
216                        // wdir_label
217                        //
218                        this.wdir_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
219                        this.wdir_label.Location = new System.Drawing.Point(24, 368);
220                        this.wdir_label.Name = "wdir_label";
221                        this.wdir_label.Size = new System.Drawing.Size(96, 24);
222                        this.wdir_label.TabIndex = 5;
223                        this.wdir_label.Text = "working directory";
224                        //
225                        // wdir_textBox
226                        //
227                        this.wdir_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
228                                | System.Windows.Forms.AnchorStyles.Right)));
229                        this.wdir_textBox.Location = new System.Drawing.Point(152, 368);
230                        this.wdir_textBox.Name = "wdir_textBox";
231                        this.wdir_textBox.Size = new System.Drawing.Size(328, 20);
232                        this.wdir_textBox.TabIndex = 13;
233                        this.wdir_textBox.Text = "";
234                        //
235                        // wdir_browse_button
236                        //
237                        this.wdir_browse_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
238                        this.wdir_browse_button.Location = new System.Drawing.Point(480, 368);
239                        this.wdir_browse_button.Name = "wdir_browse_button";
240                        this.wdir_browse_button.Size = new System.Drawing.Size(24, 20);
241                        this.wdir_browse_button.TabIndex = 14;
242                        this.wdir_browse_button.Text = "...";
243                        this.wdir_browse_button.Click += new System.EventHandler(this.wdir_browse_button_Click);
244                        //
245                        // hosts_label
246                        //
247                        this.hosts_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
248                        this.hosts_label.Location = new System.Drawing.Point(24, 392);
249                        this.hosts_label.Name = "hosts_label";
250                        this.hosts_label.Size = new System.Drawing.Size(32, 23);
251                        this.hosts_label.TabIndex = 8;
252                        this.hosts_label.Text = "hosts";
253                        //
254                        // hosts_textBox
255                        //
256                        this.hosts_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
257                                | System.Windows.Forms.AnchorStyles.Right)));
258                        this.hosts_textBox.Location = new System.Drawing.Point(152, 392);
259                        this.hosts_textBox.Name = "hosts_textBox";
260                        this.hosts_textBox.Size = new System.Drawing.Size(312, 20);
261                        this.hosts_textBox.TabIndex = 15;
262                        this.hosts_textBox.Text = "";
263                        //
264                        // hosts_reset_button
265                        //
266                        this.hosts_reset_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
267                        this.hosts_reset_button.Location = new System.Drawing.Point(464, 392);
268                        this.hosts_reset_button.Name = "hosts_reset_button";
269                        this.hosts_reset_button.Size = new System.Drawing.Size(40, 20);
270                        this.hosts_reset_button.TabIndex = 16;
271                        this.hosts_reset_button.Text = "reset";
272                        this.hosts_reset_button.Click += new System.EventHandler(this.hosts_reset_button_Click);
273                        //
274                        // configfile_label
275                        //
276                        this.configfile_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
277                        this.configfile_label.Location = new System.Drawing.Point(24, 524);
278                        this.configfile_label.Name = "configfile_label";
279                        this.configfile_label.Size = new System.Drawing.Size(88, 16);
280                        this.configfile_label.TabIndex = 11;
281                        this.configfile_label.Text = "configuration file";
282                        //
283                        // configfile_textBox
284                        //
285                        this.configfile_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
286                                | System.Windows.Forms.AnchorStyles.Right)));
287                        this.configfile_textBox.Location = new System.Drawing.Point(152, 522);
288                        this.configfile_textBox.Name = "configfile_textBox";
289                        this.configfile_textBox.Size = new System.Drawing.Size(320, 20);
290                        this.configfile_textBox.TabIndex = 22;
291                        this.configfile_textBox.Text = "";
292                        //
293                        // configfile_browse_button
294                        //
295                        this.configfile_browse_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
296                        this.configfile_browse_button.Location = new System.Drawing.Point(480, 522);
297                        this.configfile_browse_button.Name = "configfile_browse_button";
298                        this.configfile_browse_button.Size = new System.Drawing.Size(24, 20);
299                        this.configfile_browse_button.TabIndex = 23;
300                        this.configfile_browse_button.Text = "...";
301                        this.configfile_browse_button.Click += new System.EventHandler(this.configfile_browse_button_Click);
302                        //
303                        // mpich1_label
304                        //
305                        this.mpich1_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
306                        this.mpich1_label.Location = new System.Drawing.Point(24, 548);
307                        this.mpich1_label.Name = "mpich1_label";
308                        this.mpich1_label.Size = new System.Drawing.Size(128, 16);
309                        this.mpich1_label.TabIndex = 14;
310                        this.mpich1_label.Text = "mpich1 configuration file";
311                        //
312                        // mpich1_textBox
313                        //
314                        this.mpich1_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
315                                | System.Windows.Forms.AnchorStyles.Right)));
316                        this.mpich1_textBox.Location = new System.Drawing.Point(152, 546);
317                        this.mpich1_textBox.Name = "mpich1_textBox";
318                        this.mpich1_textBox.Size = new System.Drawing.Size(320, 20);
319                        this.mpich1_textBox.TabIndex = 25;
320                        this.mpich1_textBox.Text = "";
321                        //
322                        // mpich1_browse_button
323                        //
324                        this.mpich1_browse_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
325                        this.mpich1_browse_button.Location = new System.Drawing.Point(480, 546);
326                        this.mpich1_browse_button.Name = "mpich1_browse_button";
327                        this.mpich1_browse_button.Size = new System.Drawing.Size(24, 20);
328                        this.mpich1_browse_button.TabIndex = 26;
329                        this.mpich1_browse_button.Text = "...";
330                        this.mpich1_browse_button.Click += new System.EventHandler(this.mpich1_browse_button_Click);
331                        //
332                        // env_label
333                        //
334                        this.env_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
335                        this.env_label.Location = new System.Drawing.Point(24, 416);
336                        this.env_label.Name = "env_label";
337                        this.env_label.Size = new System.Drawing.Size(120, 23);
338                        this.env_label.TabIndex = 17;
339                        this.env_label.Text = "environment variables";
340                        //
341                        // env_textBox
342                        //
343                        this.env_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
344                                | System.Windows.Forms.AnchorStyles.Right)));
345                        this.env_textBox.Location = new System.Drawing.Point(152, 416);
346                        this.env_textBox.Name = "env_textBox";
347                        this.env_textBox.Size = new System.Drawing.Size(352, 20);
348                        this.env_textBox.TabIndex = 17;
349                        this.env_textBox.Text = "";
350                        //
351                        // drive_map_label
352                        //
353                        this.drive_map_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
354                        this.drive_map_label.Location = new System.Drawing.Point(24, 440);
355                        this.drive_map_label.Name = "drive_map_label";
356                        this.drive_map_label.Size = new System.Drawing.Size(88, 23);
357                        this.drive_map_label.TabIndex = 19;
358                        this.drive_map_label.Text = "drive mappings";
359                        //
360                        // drive_map_textBox
361                        //
362                        this.drive_map_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
363                                | System.Windows.Forms.AnchorStyles.Right)));
364                        this.drive_map_textBox.Location = new System.Drawing.Point(152, 440);
365                        this.drive_map_textBox.Name = "drive_map_textBox";
366                        this.drive_map_textBox.Size = new System.Drawing.Size(352, 20);
367                        this.drive_map_textBox.TabIndex = 18;
368                        this.drive_map_textBox.Text = "";
369                        //
370                        // channel_label
371                        //
372                        this.channel_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
373                        this.channel_label.Location = new System.Drawing.Point(24, 464);
374                        this.channel_label.Name = "channel_label";
375                        this.channel_label.Size = new System.Drawing.Size(48, 23);
376                        this.channel_label.TabIndex = 21;
377                        this.channel_label.Text = "channel";
378                        //
379                        // channel_comboBox
380                        //
381                        this.channel_comboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
382                        this.channel_comboBox.Items.AddRange(new object[] {
383                                                                                                                                  "sock",
384                                                                                                                                  "shm",
385                                                                                                                                  "sshm",
386                                                                                                                                  "ssm",
387                                                                                                                                  "essm",
388                                                                                                                                  "ib",
389                                                                                                                                  "mt",
390                                                                                                                                  "default",
391                                                                                                                                  "auto"});
392                        this.channel_comboBox.Location = new System.Drawing.Point(424, 464);
393                        this.channel_comboBox.Name = "channel_comboBox";
394                        this.channel_comboBox.Size = new System.Drawing.Size(80, 21);
395                        this.channel_comboBox.TabIndex = 19;
396                        this.channel_comboBox.Text = "default";
397                        //
398                        // save_job_button
399                        //
400                        this.save_job_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
401                        this.save_job_button.Location = new System.Drawing.Point(429, 56);
402                        this.save_job_button.Name = "save_job_button";
403                        this.save_job_button.TabIndex = 8;
404                        this.save_job_button.Text = "Save Job";
405                        this.save_job_button.Click += new System.EventHandler(this.save_job_button_Click);
406                        //
407                        // load_job_button
408                        //
409                        this.load_job_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
410                        this.load_job_button.Location = new System.Drawing.Point(352, 56);
411                        this.load_job_button.Name = "load_job_button";
412                        this.load_job_button.TabIndex = 7;
413                        this.load_job_button.Text = "Load Job";
414                        this.load_job_button.Click += new System.EventHandler(this.load_job_button_Click);
415                        //
416                        // execute_button
417                        //
418                        this.execute_button.Location = new System.Drawing.Point(8, 56);
419                        this.execute_button.Name = "execute_button";
420                        this.execute_button.TabIndex = 5;
421                        this.execute_button.Text = "Execute";
422                        this.execute_button.Click += new System.EventHandler(this.execute_button_Click);
423                        //
424                        // break_button
425                        //
426                        this.break_button.Enabled = false;
427                        this.break_button.Location = new System.Drawing.Point(88, 56);
428                        this.break_button.Name = "break_button";
429                        this.break_button.TabIndex = 6;
430                        this.break_button.Text = "Break";
431                        this.break_button.Click += new System.EventHandler(this.break_button_Click);
432                        //
433                        // output_richTextBox
434                        //
435                        this.output_richTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
436                                | System.Windows.Forms.AnchorStyles.Left) 
437                                | System.Windows.Forms.AnchorStyles.Right)));
438                        this.output_richTextBox.Font = new System.Drawing.Font("Lucida Console", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
439                        this.output_richTextBox.Location = new System.Drawing.Point(8, 104);
440                        this.output_richTextBox.Name = "output_richTextBox";
441                        this.output_richTextBox.Size = new System.Drawing.Size(496, 224);
442                        this.output_richTextBox.TabIndex = 11;
443                        this.output_richTextBox.Text = "";
444                        this.output_richTextBox.WordWrap = false;
445                        this.output_richTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.output_richTextBox_KeyPress);
446                        //
447                        // application_comboBox
448                        //
449                        this.application_comboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
450                                | System.Windows.Forms.AnchorStyles.Right)));
451                        this.application_comboBox.Location = new System.Drawing.Point(88, 8);
452                        this.application_comboBox.Name = "application_comboBox";
453                        this.application_comboBox.Size = new System.Drawing.Size(392, 21);
454                        this.application_comboBox.TabIndex = 2;
455                        //
456                        // show_command_button
457                        //
458                        this.show_command_button.Location = new System.Drawing.Point(8, 80);
459                        this.show_command_button.Name = "show_command_button";
460                        this.show_command_button.Size = new System.Drawing.Size(96, 23);
461                        this.show_command_button.TabIndex = 9;
462                        this.show_command_button.Text = "Show Command";
463                        this.show_command_button.Click += new System.EventHandler(this.show_command_button_Click);
464                        //
465                        // command_line_textBox
466                        //
467                        this.command_line_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
468                                | System.Windows.Forms.AnchorStyles.Right)));
469                        this.command_line_textBox.Location = new System.Drawing.Point(104, 80);
470                        this.command_line_textBox.Name = "command_line_textBox";
471                        this.command_line_textBox.ReadOnly = true;
472                        this.command_line_textBox.Size = new System.Drawing.Size(400, 20);
473                        this.command_line_textBox.TabIndex = 10;
474                        this.command_line_textBox.Text = "";
475                        //
476                        // application_radioButton
477                        //
478                        this.application_radioButton.Checked = true;
479                        this.application_radioButton.Location = new System.Drawing.Point(8, 8);
480                        this.application_radioButton.Name = "application_radioButton";
481                        this.application_radioButton.Size = new System.Drawing.Size(16, 24);
482                        this.application_radioButton.TabIndex = 1;
483                        this.application_radioButton.TabStop = true;
484                        this.application_radioButton.CheckedChanged += new System.EventHandler(this.application_radioButton_CheckedChanged);
485                        //
486                        // configfile_radioButton
487                        //
488                        this.configfile_radioButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
489                        this.configfile_radioButton.Location = new System.Drawing.Point(8, 520);
490                        this.configfile_radioButton.Name = "configfile_radioButton";
491                        this.configfile_radioButton.Size = new System.Drawing.Size(16, 24);
492                        this.configfile_radioButton.TabIndex = 21;
493                        this.configfile_radioButton.CheckedChanged += new System.EventHandler(this.configfile_radioButton_CheckedChanged);
494                        //
495                        // mpich1_radioButton
496                        //
497                        this.mpich1_radioButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
498                        this.mpich1_radioButton.Location = new System.Drawing.Point(8, 544);
499                        this.mpich1_radioButton.Name = "mpich1_radioButton";
500                        this.mpich1_radioButton.Size = new System.Drawing.Size(16, 24);
501                        this.mpich1_radioButton.TabIndex = 24;
502                        this.mpich1_radioButton.CheckedChanged += new System.EventHandler(this.mpich1_radioButton_CheckedChanged);
503                        //
504                        // show_bottom_checkBox
505                        //
506                        this.show_bottom_checkBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
507                        this.show_bottom_checkBox.Location = new System.Drawing.Point(8, 328);
508                        this.show_bottom_checkBox.Name = "show_bottom_checkBox";
509                        this.show_bottom_checkBox.Size = new System.Drawing.Size(96, 16);
510                        this.show_bottom_checkBox.TabIndex = 12;
511                        this.show_bottom_checkBox.Text = "more options";
512                        this.show_bottom_checkBox.CheckedChanged += new System.EventHandler(this.show_bottom_checkBox_CheckedChanged);
513                        //
514                        // extra_options_textBox
515                        //
516                        this.extra_options_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
517                                | System.Windows.Forms.AnchorStyles.Right)));
518                        this.extra_options_textBox.Location = new System.Drawing.Point(152, 496);
519                        this.extra_options_textBox.Name = "extra_options_textBox";
520                        this.extra_options_textBox.Size = new System.Drawing.Size(352, 20);
521                        this.extra_options_textBox.TabIndex = 27;
522                        this.extra_options_textBox.Text = "";
523                        //
524                        // extra_options_label
525                        //
526                        this.extra_options_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
527                        this.extra_options_label.Location = new System.Drawing.Point(24, 496);
528                        this.extra_options_label.Name = "extra_options_label";
529                        this.extra_options_label.Size = new System.Drawing.Size(120, 23);
530                        this.extra_options_label.TabIndex = 28;
531                        this.extra_options_label.Text = "extra mpiexec options";
532                        //
533                        // popup_checkBox
534                        //
535                        this.popup_checkBox.Location = new System.Drawing.Point(168, 56);
536                        this.popup_checkBox.Name = "popup_checkBox";
537                        this.popup_checkBox.Size = new System.Drawing.Size(168, 24);
538                        this.popup_checkBox.TabIndex = 29;
539                        this.popup_checkBox.Text = "run in an separate window";
540                        //
541                        // jumpshot_button
542                        //
543                        this.jumpshot_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
544                        this.jumpshot_button.Location = new System.Drawing.Point(432, 336);
545                        this.jumpshot_button.Name = "jumpshot_button";
546                        this.jumpshot_button.Size = new System.Drawing.Size(75, 24);
547                        this.jumpshot_button.TabIndex = 30;
548                        this.jumpshot_button.Text = "Jumpshot";
549                        this.jumpshot_button.Click += new System.EventHandler(this.jumpshot_button_Click);
550                        //
551                        // log_checkBox
552                        //
553                        this.log_checkBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
554                        this.log_checkBox.Location = new System.Drawing.Point(312, 336);
555                        this.log_checkBox.Name = "log_checkBox";
556                        this.log_checkBox.Size = new System.Drawing.Size(112, 24);
557                        this.log_checkBox.TabIndex = 31;
558                        this.log_checkBox.Text = "produce clog2 file";
559                        //
560                        // wmpiexec
561                        //
562                        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
563                        this.ClientSize = new System.Drawing.Size(512, 579);
564                        this.Controls.Add(this.log_checkBox);
565                        this.Controls.Add(this.jumpshot_button);
566                        this.Controls.Add(this.popup_checkBox);
567                        this.Controls.Add(this.extra_options_label);
568                        this.Controls.Add(this.extra_options_textBox);
569                        this.Controls.Add(this.application_radioButton);
570                        this.Controls.Add(this.command_line_textBox);
571                        this.Controls.Add(this.drive_map_textBox);
572                        this.Controls.Add(this.env_textBox);
573                        this.Controls.Add(this.mpich1_textBox);
574                        this.Controls.Add(this.configfile_textBox);
575                        this.Controls.Add(this.hosts_textBox);
576                        this.Controls.Add(this.wdir_textBox);
577                        this.Controls.Add(this.show_bottom_checkBox);
578                        this.Controls.Add(this.mpich1_radioButton);
579                        this.Controls.Add(this.configfile_radioButton);
580                        this.Controls.Add(this.show_command_button);
581                        this.Controls.Add(this.application_comboBox);
582                        this.Controls.Add(this.output_richTextBox);
583                        this.Controls.Add(this.break_button);
584                        this.Controls.Add(this.execute_button);
585                        this.Controls.Add(this.load_job_button);
586                        this.Controls.Add(this.save_job_button);
587                        this.Controls.Add(this.channel_comboBox);
588                        this.Controls.Add(this.channel_label);
589                        this.Controls.Add(this.drive_map_label);
590                        this.Controls.Add(this.env_label);
591                        this.Controls.Add(this.mpich1_browse_button);
592                        this.Controls.Add(this.mpich1_label);
593                        this.Controls.Add(this.configfile_browse_button);
594                        this.Controls.Add(this.configfile_label);
595                        this.Controls.Add(this.hosts_reset_button);
596                        this.Controls.Add(this.hosts_label);
597                        this.Controls.Add(this.wdir_browse_button);
598                        this.Controls.Add(this.wdir_label);
599                        this.Controls.Add(this.nproc_numericUpDown);
600                        this.Controls.Add(this.nproc_label);
601                        this.Controls.Add(this.application_browse_button);
602                        this.Controls.Add(this.application_label);
603                        this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
604                        this.Name = "wmpiexec";
605                        this.Text = "MPIEXEC wrapper";
606                        this.Closing += new System.ComponentModel.CancelEventHandler(this.wmpiexec_Closing);
607                        ((System.ComponentModel.ISupportInitialize)(this.nproc_numericUpDown)).EndInit();
608                        this.ResumeLayout(false);
609
610                }
611                #endregion
612
613                /// <summary>
614                /// The main entry point for the application.
615                /// </summary>
616                [STAThread]
617                static void Main() 
618                {
619                        Application.Run(new wmpiexec());
620                }
621
622                private void AppendText(string str)
623                {
624                        output_richTextBox.AppendText(str);
625                }
626
627                private void SetProcess(Process p)
628                {
629                        process = p;
630                }
631
632                private void ResetExecuteButtons()
633                {
634                        execute_button.Enabled = true;
635                        break_button.Enabled = false;
636                }
637
638                private void application_browse_button_Click(object sender, System.EventArgs e)
639                {
640                        OpenFileDialog dlg = new OpenFileDialog();
641                        dlg.Filter = "Executable files (*.exe)|*.exe|All files (*.*)|*.*";
642                        if (dlg.ShowDialog() == DialogResult.OK)
643                        {
644                                if (dlg.FileName.IndexOf(' ') != -1)
645                                {
646                                        application_comboBox.Text = "\"" + dlg.FileName + "\"";
647                                }
648                                else
649                                {
650                                        application_comboBox.Text = dlg.FileName;
651                                }
652                        }
653                }
654
655                private void wdir_browse_button_Click(object sender, System.EventArgs e)
656                {
657                        FolderBrowserDialog dlg = new FolderBrowserDialog();
658                        if (wdir_textBox.Text.Length > 0)
659                        {
660                                dlg.SelectedPath = wdir_textBox.Text;
661                        }
662                        else
663                        {
664                                dlg.SelectedPath = Environment.CurrentDirectory;
665                        }
666                        if (dlg.ShowDialog() == DialogResult.OK)
667                        {
668                                wdir_textBox.Text = dlg.SelectedPath;
669                        }
670                }
671
672                private void hosts_reset_button_Click(object sender, System.EventArgs e)
673                {
674                        object obj;
675                        RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH\SMPD");
676                        obj = key.GetValue("hosts");
677                        if (obj != null)
678                        {
679                                hosts_textBox.Text = obj.ToString();
680                        }
681                        else
682                        {
683                                hosts_textBox.Text = "";
684                        }
685                }
686
687                private void configfile_browse_button_Click(object sender, System.EventArgs e)
688                {
689                        OpenFileDialog dlg = new OpenFileDialog();
690                        dlg.Filter = "All files (*.*)|*.*";
691                        if (dlg.ShowDialog() == DialogResult.OK)
692                        {
693                                configfile_textBox.Text = dlg.FileName;
694                        }
695                }
696
697                private void mpich1_browse_button_Click(object sender, System.EventArgs e)
698                {
699                        OpenFileDialog dlg = new OpenFileDialog();
700                        dlg.Filter = "Configuration file (*.cfg)|*.cfg|All files (*.*)|*.*";
701                        if (dlg.ShowDialog() == DialogResult.OK)
702                        {
703                                mpich1_textBox.Text = dlg.FileName;
704                        }
705                }
706
707                private void save_job_button_Click(object sender, System.EventArgs e)
708                {
709                        SaveFileDialog dlg = new SaveFileDialog();
710                        dlg.Filter = "Job files (*.txt *.mpi)|*.txt;*.mpi|All files (*.*)|*.*";
711                        if (dlg.ShowDialog() == DialogResult.OK)
712                        {
713                                StreamWriter stream;
714                                using (stream = new StreamWriter(dlg.FileName))
715                                {
716                                        stream.WriteLine("exe {0}", application_comboBox.Text.Trim());
717                                        stream.WriteLine("n {0}", nproc_numericUpDown.Value);
718                                        stream.WriteLine("wdir {0}", wdir_textBox.Text.Trim());
719                                        stream.WriteLine("hosts {0}", hosts_textBox.Text.Trim());
720                                        stream.WriteLine("cfg {0}", configfile_textBox.Text.Trim());
721                                        stream.WriteLine("mpich1 {0}", mpich1_textBox.Text.Trim());
722                                        stream.WriteLine("env {0}", env_textBox.Text.Trim());
723                                        stream.WriteLine("map {0}", drive_map_textBox.Text.Trim());
724                                        stream.WriteLine("channel {0}", channel_comboBox.Text.Trim());
725                                        stream.WriteLine("extra {0}", extra_options_textBox.Text.Trim());
726                                        stream.WriteLine(popup_checkBox.Checked ? "window yes" : "window no");
727                                        stream.WriteLine(log_checkBox.Checked ? "log yes" : "log no");
728                                        stream.Close();
729                                }
730                        }
731                }
732
733                private void load_job_button_Click(object sender, System.EventArgs e)
734                {
735                        OpenFileDialog dlg = new OpenFileDialog();
736                        dlg.Filter = "Job files (*.txt *.mpi)|*.txt;*.mpi|All files (*.*)|*.*";
737                        if (dlg.ShowDialog() == DialogResult.OK)
738                        {
739                                StreamReader stream;
740                                using (stream = new StreamReader(dlg.FileName))
741                                {
742                                        string line;
743                                        int index;
744
745                                        // reset all the values before loading new ones
746                                        application_comboBox.Text = "";
747                                        nproc_numericUpDown.Value = 1;
748                                        wdir_textBox.Text = "";
749                                        hosts_textBox.Text = "";
750                                        configfile_textBox.Text = "";
751                                        mpich1_textBox.Text = "";
752                                        env_textBox.Text = "";
753                                        drive_map_textBox.Text = "";
754                                        channel_comboBox.Text = "";
755                                        extra_options_textBox.Text = "";
756                                        popup_checkBox.Checked = false;
757                                        log_checkBox.Checked = false;
758
759                                        line = stream.ReadLine();
760                                        while (line != null)
761                                        {
762                                                index = line.IndexOf(" ");
763                                                if (index > 0)
764                                                {
765                                                        string key, val;
766                                                        key = line.Substring(0, index);
767                                                        val = line.Substring(index+1);
768                                                        switch (key)
769                                                        {
770                                                                case "exe":
771                                                                        application_comboBox.Text = val;
772                                                                        break;
773                                                                case "n":
774                                                                        nproc_numericUpDown.Value = Convert.ToInt32(val);
775                                                                        break;
776                                                                case "wdir":
777                                                                        wdir_textBox.Text = val;
778                                                                        break;
779                                                                case "hosts":
780                                                                        hosts_textBox.Text = val;
781                                                                        break;
782                                                                case "cfg":
783                                                                        configfile_textBox.Text = val;
784                                                                        break;
785                                                                case "mpich1":
786                                                                        mpich1_textBox.Text = val;
787                                                                        break;
788                                                                case "env":
789                                                                        env_textBox.Text = val;
790                                                                        break;
791                                                                case "map":
792                                                                        drive_map_textBox.Text = val;
793                                                                        break;
794                                                                case "channel":
795                                                                        channel_comboBox.Text = val;
796                                                                        break;
797                                                                case "extra":
798                                                                        extra_options_textBox.Text = val;
799                                                                        break;
800                                                                case "window":
801                                                                        if (val == "yes")
802                                                                                popup_checkBox.Checked = true;
803                                                                        else
804                                                                                popup_checkBox.Checked = false;
805                                                                        break;
806                                                                case "log":
807                                                                        if (val == "yes")
808                                                                                log_checkBox.Checked = true;
809                                                                        else
810                                                                                log_checkBox.Checked = false;
811                                                                        break;
812                                                        }
813                                                }
814                                                line = stream.ReadLine();
815                                        }
816                                        stream.Close();
817                                }
818                        }
819                }
820
821                #region Process thread functions
822                /// <summary>
823                /// These functions read and write input and output of the spawned mpiexec process.
824                /// They are run in separate threads since they can execute for a long period of time
825                /// and therefore shouldn't come from the thread pool (delegates).
826                /// Is this a correct design decision?
827                /// </summary>
828                private void ReadOutput(TextReader stream)
829                {
830                        thread_output_stream = stream;
831                        Thread thread = new Thread(new ThreadStart(ReadOutputThread));
832                        thread.Start();
833                }
834
835                private void ReadError(TextReader stream)
836                {
837                        thread_error_stream = stream;
838                        Thread thread = new Thread(new ThreadStart(ReadErrorThread));
839                        thread.Start();
840                }
841
842                private void ReadErrorThread()
843                {
844                        int num_read;
845                        char [] buffer = new char[4096];
846                        TextReader stream = thread_error_stream;
847                        num_read = stream.Read(buffer, 0, 4096);
848                        while (num_read > 0)
849                        {
850                                string str;
851                                char [] text = new char[num_read];
852                                Array.Copy(buffer, 0, text, 0, num_read);
853                                str = new string(text);
854                                object[] pList = { str };
855                                // put the string in the edit box in a thread safe way
856                                AppendTextDelegate ap = new AppendTextDelegate(AppendText);
857                                output_richTextBox.Invoke(ap, pList);
858                                num_read = stream.Read(buffer, 0, 1024);
859                        }
860                }
861
862                private void ReadOutputThread()
863                {
864                        int num_read;
865                        char [] buffer = new char[4096];
866                        TextReader stream = thread_output_stream;
867                        num_read = stream.Read(buffer, 0, 4096);
868                        while (num_read > 0)
869                        {
870                                string str;
871                                char [] text = new char[num_read];
872                                Array.Copy(buffer, 0, text, 0, num_read);
873                                str = new string(text);
874                                object[] pList = { str };
875                                // put the string in the edit box in a thread safe way
876                                AppendTextDelegate ap = new AppendTextDelegate(AppendText);
877                                output_richTextBox.Invoke(ap, pList);
878                                num_read = stream.Read(buffer, 0, 1024);
879                        }
880                }
881
882                ManualResetEvent char_available = new ManualResetEvent(false);
883                ManualResetEvent char_written = new ManualResetEvent(true);
884                bool quit_input = false;
885                char ch;
886                private void WriteInput(TextWriter stream)
887                {
888                        thread_input_stream = stream;
889                        Thread thread = new Thread(new ThreadStart(WriteInputThread));
890                        thread.Start();
891                }
892
893                private void WriteInputThread()
894                {
895                        WriteInputEx(thread_input_stream);
896                }
897
898                private void WriteInputEx(TextWriter stream)
899                {
900                        while (char_available.WaitOne())
901                        {
902                                if (quit_input)
903                                {
904                                        return;
905                                }
906                                stream.Write(ch);
907                                stream.Flush();
908                                char_available.Reset();
909                                char_written.Set();
910
911                                /*
912                                object[] pList = { "ch(" + ch + ")" };
913                                // put the string in the edit box in a thread safe way
914                                AppendTextDelegate ap = new AppendTextDelegate(AppendText);
915                                output_richTextBox.Invoke(ap, pList);
916                                */
917                        }
918                }
919
920                private void RunCommand(string command, string mpiexec_command, string mpiexec_command_args, bool popup)
921                {
922                        thread_command = command;
923                        thread_mpiexec_command = mpiexec_command;
924                        thread_mpiexec_command_args = mpiexec_command_args;
925                        thread_popup = popup;
926                        Thread thread = new Thread(new ThreadStart(RunCommandThread));
927                        thread.Start();
928                }
929
930                void RunCommandThread()
931                {
932                        RunCommandEx(thread_command, thread_mpiexec_command, thread_mpiexec_command_args, thread_popup);
933                }
934
935                private void RunCommandEx(string command, string mpiexec_command, string mpiexec_command_args, bool popup)
936                {
937                        if (popup)
938                        {
939                                // start a process to run the mpiexec command
940                                Process p = new Process();
941                                p.StartInfo.UseShellExecute = true;
942                                p.StartInfo.CreateNoWindow = false;
943                                p.StartInfo.RedirectStandardError = false;
944                                p.StartInfo.RedirectStandardInput = false;
945                                p.StartInfo.RedirectStandardOutput = false;
946                                p.StartInfo.FileName = "cmd.exe";
947                                if (command.IndexOf('"') != -1)
948                                {
949                                        p.StartInfo.Arguments = "/C \"" + command + "\" && pause";
950                                }
951                                else
952                                {
953                                        p.StartInfo.Arguments = "/C " + command + " && pause";
954                                }
955                                p.Start();
956                                p.WaitForExit();
957                        }
958                        else
959                        {
960                                quit_input = false;
961                                // start a process to run the mpiexec command
962                                Process p = new Process();
963                                p.StartInfo.UseShellExecute = false;
964                                p.StartInfo.CreateNoWindow = true;
965                                p.StartInfo.RedirectStandardError = true;
966                                p.StartInfo.RedirectStandardInput = true;
967                                p.StartInfo.RedirectStandardOutput = true;
968                                p.StartInfo.FileName = mpiexec_command;
969                                p.StartInfo.Arguments = mpiexec_command_args;
970                                p.Start();
971                                // start a delagate to read stdout
972                                ReadOutputDelegate r1 = new ReadOutputDelegate(ReadOutput);
973                                //IAsyncResult ar1 = r1.BeginInvoke(TextReader.Synchronized(p.StandardOutput), null, null);
974                                object [] list1 = { TextReader.Synchronized(p.StandardOutput) };
975                                Invoke(r1, list1);
976                                // start a delagate to read stderr
977                                ReadErrorDelegate r2 = new ReadErrorDelegate(ReadError);
978                                //IAsyncResult ar2 = r2.BeginInvoke(TextReader.Synchronized(p.StandardError), null, null);
979                                object [] list2 = { TextReader.Synchronized(p.StandardError) };
980                                Invoke(r2, list2);
981                                // Send stdin to the process
982                                WriteInputDelegate w = new WriteInputDelegate(WriteInput);
983                                //IAsyncResult ar3 = w.BeginInvoke(TextWriter.Synchronized(p.StandardInput), null, null);
984                                object [] list3 = { TextWriter.Synchronized(p.StandardInput) };
985                                Invoke(w, list3);
986
987                                //process = p;
988                                SetProcessDelegate sp = new SetProcessDelegate(SetProcess);
989                                object [] list = { p };
990                                Invoke(sp, list);
991                                // wait for the process to exit
992                                p.WaitForExit();
993                                // wait for the output and error delegates to finish
994                                //r1.EndInvoke(ar1);
995                                //r2.EndInvoke(ar2);
996                                // set the process variable to null
997                                list[0] = null;
998                                Invoke(sp, list);
999                                // signal the input delegate to exit after setting the process variable to null to avoid conflicts with the keypressed handler
1000                                quit_input = true;
1001                                char_available.Set();
1002                                //w.EndInvoke(ar3);
1003                        }
1004                        ResetExecuteButtonsDelegate d = new ResetExecuteButtonsDelegate(ResetExecuteButtons);
1005                        Invoke(d);
1006                }
1007                #endregion
1008
1009                private void execute_button_Click(object sender, System.EventArgs e)
1010                {
1011                        VerifyEncryptedPasswordExists();
1012                        execute_button.Enabled = false;
1013                        break_button.Enabled = true;
1014                        output_richTextBox.Clear();
1015                        if (last_execute_result != null)
1016                        {
1017                                run_command.EndInvoke(last_execute_result);
1018                        }
1019                        // Create the command line
1020                        command_line_textBox.Text = get_command_line();
1021                        // Add the command to the application drop down if it has not already been added
1022                        bool found = false;
1023                        foreach (string str in application_comboBox.Items)
1024                        {
1025                                if (str == application_comboBox.Text)
1026                                        found = true;
1027                        }
1028                        if (!found)
1029                        {
1030                                application_comboBox.Items.Add(application_comboBox.Text);
1031                        }
1032                        run_command = new RunCommandDelegate(RunCommand);
1033                        last_execute_result = run_command.BeginInvoke(command_line_textBox.Text, mpiexec_command, mpiexec_command_args, popup_checkBox.Checked, null, null);
1034                        // after starting a command move to the output box so the user can interact with the running process.
1035                        output_richTextBox.Focus();
1036                }
1037
1038                private void VerifyEncryptedPasswordExists()
1039                {
1040                        try
1041                        {
1042                                bool popup = true;
1043                                string mpiexec = get_mpiexec();
1044
1045                                // Check the registry for the encrypted password
1046                                // This code will have to be kept synchronized with the smpd code
1047                                // The advantage of this approach is that the credentials don't have to be valid on the local host
1048                                RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\MPICH");
1049                                if (key != null)
1050                                {
1051                                        // check to see that an encrypted password for the current user exists
1052                                        object obj = key.GetValue("smpdPassword");
1053                                        key.Close();
1054                                        if (obj != null)
1055                                        {
1056                                                popup = false;
1057                                        }
1058                                }
1059
1060                                // Or run "mpiexec -validate" and check the output for SUCCESS
1061                                // This code will last longer because it doesn't rely on known information about the smpd implementation
1062                                // The disadvantage of this code is that the user credentials have to be valid on the local host.
1063                                /*
1064                                Process p1 = new Process();
1065                                p1.StartInfo.RedirectStandardOutput = true;
1066                                p1.StartInfo.RedirectStandardError = true;
1067                                p1.StartInfo.UseShellExecute = false;
1068                                p1.StartInfo.CreateNoWindow = true;
1069                                p1.StartInfo.FileName = mpiexec;
1070                                p1.StartInfo.Arguments = "-validate";
1071                                p1.Start();
1072                                string output = p1.StandardOutput.ReadToEnd() + p1.StandardError.ReadToEnd();
1073                                p1.WaitForExit();
1074                                p1.Close();
1075                                if (output.IndexOf("SUCCESS") != -1)
1076                                {
1077                                        popup = false;
1078                                }
1079                                */
1080
1081                                if (popup)
1082                                {
1083                                        string wmpiregister;
1084                                        wmpiregister = mpiexec.Replace("mpiexec.exe", "wmpiregister.exe");
1085                                        Process p = new Process();
1086                                        p.StartInfo.FileName = wmpiregister;
1087                                        p.Start();
1088                                        p.WaitForExit();
1089                                }
1090                        }
1091                        catch (Exception)
1092                        {
1093                        }
1094                }
1095
1096                private void break_button_Click(object sender, System.EventArgs e)
1097                {
1098                        if (process != null)
1099                        {
1100                                process.Kill();
1101                        }
1102                }
1103
1104                #region Get known files: mpiexec, jumpshot, and clog2 files
1105                private string get_jumpshot()
1106                {
1107                        string jumpshot = "";
1108                        object obj;
1109                        try
1110                        {
1111                                RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH2");
1112                                if (key != null)
1113                                {
1114                                        obj = key.GetValue("Path");
1115                                        key.Close();
1116                                        if (obj != null)
1117                                        {
1118                                                jumpshot = obj.ToString();
1119                                                if (jumpshot.EndsWith(@"\"))
1120                                                {
1121                                                        jumpshot = jumpshot + @"bin\jumpshot.jar";
1122                                                }
1123                                                else
1124                                                {
1125                                                        jumpshot = jumpshot + @"\bin\jumpshot.jar";
1126                                                }
1127                                                if (!File.Exists(jumpshot))
1128                                                {
1129                                                        jumpshot = "";
1130                                                }
1131                                        }
1132                                }
1133                                if (jumpshot == "")
1134                                {
1135                                        key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH\SMPD");
1136                                        if (key != null)
1137                                        {
1138                                                obj = key.GetValue("binary");
1139                                                key.Close();
1140                                                if (obj != null)
1141                                                {
1142                                                        jumpshot = obj.ToString().Replace("smpd.exe", "jumpshot.jar");
1143                                                        if (!File.Exists(jumpshot))
1144                                                        {
1145                                                                jumpshot = "";
1146                                                        }
1147                                                }
1148                                        }
1149                                }
1150                                if (jumpshot == "")
1151                                {
1152                                        jumpshot = "jumpshot.jar";
1153                                }
1154                                jumpshot = jumpshot.Trim();
1155                                if (jumpshot.IndexOf(' ') != -1)
1156                                {
1157                                        jumpshot = "\"" + jumpshot + "\"";
1158                                }
1159                        }
1160                        catch (Exception)
1161                        {
1162                                jumpshot = "jumpshot.jar";
1163                        }
1164                        return jumpshot;
1165                }
1166
1167                private string get_clog2()
1168                {
1169                        int index, last;
1170                        string app = application_comboBox.Text;
1171                        try
1172                        {
1173                                if (app[0] == '\"')
1174                                {
1175                                        // remove the quotes to be restored at the end
1176                                        app = app.Replace("\"", "");
1177                                }
1178                                index = app.LastIndexOf('\\');
1179                                if (index == -1)
1180                                {
1181                                        index = 0;
1182                                }
1183                                last = index;
1184                                // find the index of .exe starting from the last \
1185                                index = app.IndexOf(".exe", last);
1186                                if (index == -1)
1187                                {
1188                                        // no .exe so find the first space after the last \
1189                                        // This assumes the executable does not have spaces in its name
1190                                        index = app.IndexOf(' ', last);
1191                                        if (index == -1)
1192                                        {
1193                                                // no .exe and no spaces found so take the entire string
1194                                                index = app.Length;
1195                                        }
1196                                }
1197                                app = app.Substring(0, index) + ".exe.clog2";
1198                                app = app.Trim();
1199                                if (!File.Exists(app) && wdir_textBox.Text.Length > 0)
1200                                {
1201                                        // file not found from the application combo box so try finding it in the working directory
1202                                        string app2 = application_comboBox.Text;
1203                                        if (app2[0] == '\"')
1204                                        {
1205                                                // remove the quotes to be restored at the end
1206                                                app2 = app2.Replace("\"", "");
1207                                        }
1208                                        index = app2.LastIndexOf('\\');
1209                                        if (index != -1)
1210                                        {
1211                                                // remove the path
1212                                                app2 = app2.Remove(0, index);
1213                                        }
1214                                        // find the index of .exe
1215                                        index = app2.IndexOf(".exe");
1216                                        if (index != -1)
1217                                        {
1218                                                // remove any arguments after the executable name
1219                                                app2 = app2.Substring(0, index + 4);
1220                                        }
1221                                        else
1222                                        {
1223                                                // no .exe so find the first space
1224                                                // This assumes the executable does not have spaces in its name
1225                                                index = app.IndexOf(' ');
1226                                                if (index != -1)
1227                                                {
1228                                                        app2 = app2.Substring(0, index) + ".exe";
1229                                                }
1230                                                else
1231                                                {
1232                                                        // no .exe and no arguments so append .exe
1233                                                        app2 += ".exe";
1234                                                }
1235                                        }
1236                                        // app2 should now contain only the executable name
1237                                        // Add the wdir path and clog2 extension
1238                                        if (wdir_textBox.Text.EndsWith("\\"))
1239                                                app2 = wdir_textBox.Text + app2 + ".clog2";
1240                                        else
1241                                                app2 = wdir_textBox.Text + "\\" + app2 + ".clog2";
1242                                        if (File.Exists(app2))
1243                                        {
1244                                                app = app2;
1245                                                FileStream f = File.OpenRead(app2);
1246                                                app = f.Name;
1247                                                f.Close();
1248                                        }
1249                                }
1250                                if (app.IndexOf(' ') != -1)
1251                                {
1252                                        app = "\"" + app + "\"";
1253                                }
1254                        }
1255                        catch (Exception)
1256                        {
1257                                app = "";
1258                        }
1259                        return app;
1260                }
1261
1262                private string get_mpiexec()
1263                {
1264                        string mpiexec = "";
1265                        object obj;
1266                        try
1267                        {
1268                                RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH2");
1269                                if (key != null)
1270                                {
1271                                        obj = key.GetValue("Path");
1272                                        key.Close();
1273                                        if (obj != null)
1274                                        {
1275                                                mpiexec = obj.ToString();
1276                                                if (mpiexec.EndsWith(@"\"))
1277                                                {
1278                                                        mpiexec = mpiexec + @"bin\mpiexec.exe";
1279                                                }
1280                                                else
1281                                                {
1282                                                        mpiexec = mpiexec + @"\bin\mpiexec.exe";
1283                                                }
1284                                                if (!File.Exists(mpiexec))
1285                                                {
1286                                                        mpiexec = "";
1287                                                }
1288                                        }
1289                                }
1290                                if (mpiexec == "")
1291                                {
1292                                        key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH\SMPD");
1293                                        if (key != null)
1294                                        {
1295                                                obj = key.GetValue("binary");
1296                                                key.Close();
1297                                                if (obj != null)
1298                                                {
1299                                                        mpiexec = obj.ToString().Replace("smpd.exe", "mpiexec.exe");
1300                                                        if (!File.Exists(mpiexec))
1301                                                        {
1302                                                                mpiexec = "";
1303                                                        }
1304                                                }
1305                                        }
1306                                }
1307                                if (mpiexec == "")
1308                                {
1309                                        mpiexec = "mpiexec.exe";
1310                                }
1311                                mpiexec = mpiexec.Trim();
1312                                mpiexec_command = mpiexec; // save the path to mpiexec.exe without quotes
1313                                if (mpiexec.IndexOf(' ') != -1)
1314                                {
1315                                        mpiexec = "\"" + mpiexec + "\"";
1316                                }
1317                        }
1318                        catch (Exception)
1319                        {
1320                                mpiexec = "mpiexec.exe";
1321                        }
1322                        return mpiexec;
1323                }
1324                #endregion
1325
1326                private string get_command_line()
1327                {
1328                        string cmd, mpiexec;
1329                        cmd = mpiexec = get_mpiexec();
1330                        if (application_radioButton.Checked)
1331                        {
1332                                wdir_textBox.Text = wdir_textBox.Text.Trim();
1333                                if (wdir_textBox.Text.Length > 0)
1334                                {
1335                                        if (wdir_textBox.Text.IndexOf(' ') != -1)
1336                                        {
1337                                                cmd = cmd + " -wdir \"" + wdir_textBox.Text + "\"";
1338                                        }
1339                                        else
1340                                        {
1341                                                cmd = cmd + " -wdir " + wdir_textBox.Text;
1342                                        }
1343                                }
1344                                drive_map_textBox.Text = drive_map_textBox.Text.Trim();
1345                                if (drive_map_textBox.Text.Length > 0)
1346                                {
1347                                        if (drive_map_textBox.Text.IndexOf(' ') != -1)
1348                                        {
1349                                                cmd = cmd + " -map \"" + drive_map_textBox.Text + "\"";
1350                                        }
1351                                        else
1352                                        {
1353                                                cmd = cmd + " -map " + drive_map_textBox.Text;
1354                                        }
1355                                }
1356                                if (log_checkBox.Checked)
1357                                {
1358                                        cmd = cmd + " -log";
1359                                }
1360                                channel_comboBox.Text = channel_comboBox.Text.Trim();
1361                                if (channel_comboBox.Text != "default" && channel_comboBox.Text != "auto" && channel_comboBox.Text != "")
1362                                {
1363                                        cmd = cmd + " -env MPICH2_CHANNEL " + channel_comboBox.Text;
1364                                }
1365                                env_textBox.Text = env_textBox.Text.Trim();
1366                                if (env_textBox.Text.Length > 0)
1367                                {
1368                                        foreach (string keyval in env_textBox.Text.Split(' '))
1369                                        {
1370                                                string [] kv;
1371                                                kv = keyval.Split('=');
1372                                                if (kv.Length > 1)
1373                                                {
1374                                                        cmd = cmd + " -env " + kv[0] + " " + kv[1];
1375                                                }
1376                                        }
1377                                }
1378                                hosts_textBox.Text = hosts_textBox.Text.Trim();
1379                                if (hosts_textBox.Text.Length > 0)
1380                                {
1381                                        string [] hosts;
1382                                        int n;
1383                                        hosts = hosts_textBox.Text.Split(' ');
1384                                        n = (int)nproc_numericUpDown.Value;
1385                                        if (n > hosts.Length)
1386                                        {
1387                                                int max = n % hosts.Length;
1388                                                cmd = cmd + " -hosts " + hosts.Length + " ";
1389                                                for (int i=0; i<hosts.Length; i++)
1390                                                {
1391                                                        if (i<max)
1392                                                        {
1393                                                                cmd = cmd + hosts[i] + " " + ((n / hosts.Length) + 1) + " ";
1394                                                        }
1395                                                        else
1396                                                        {
1397                                                                cmd = cmd + hosts[i] + " " + (n / hosts.Length) + " ";
1398                                                        }
1399                                                }
1400                                        }
1401                                        else
1402                                        {
1403                                                cmd = cmd + " -hosts " + n + " ";
1404                                                for (int i=0; i<n; i++)
1405                                                {
1406                                                        cmd = cmd + hosts[i] + " ";
1407                                                }
1408                                        }
1409                                }
1410                                else
1411                                {
1412                                        cmd = cmd + " -n " + nproc_numericUpDown.Value + " ";
1413                                }
1414                                extra_options_textBox.Text = extra_options_textBox.Text.Trim();
1415                                if (extra_options_textBox.Text.Length > 0)
1416                                {
1417                                        cmd = cmd + " " + extra_options_textBox.Text;
1418                                }
1419                                application_comboBox.Text = application_comboBox.Text.Trim();
1420                                // Don't add quotes because they would enclose any arguments to the application
1421                                // The user must provide the quotes as necessary in the combo box.
1422                                /*
1423                                if (application_comboBox.Text.IndexOf(' ') != -1)
1424                                {
1425                                        cmd = cmd + " \"" + application_comboBox.Text + "\"";
1426                                }
1427                                else
1428                                {
1429                                        cmd = cmd + " " + application_comboBox.Text;
1430                                }
1431                                */
1432                                cmd = cmd + " -noprompt " + application_comboBox.Text; // add -noprompt since we can't send input to stdin
1433                                mpiexec_command_args = cmd.Replace(mpiexec, ""); // save the command line minus the mpiexec path
1434                        }
1435                        else if (configfile_radioButton.Checked)
1436                        {
1437                                configfile_textBox.Text = configfile_textBox.Text.Trim();
1438                                if (configfile_textBox.Text.IndexOf(' ') != -1)
1439                                {
1440                                        cmd = cmd + " -configfile \"" + configfile_textBox.Text + "\"";
1441                                }
1442                                else
1443                                {
1444                                        cmd = cmd + " -configfile " + configfile_textBox.Text;
1445                                }
1446                        }
1447                        else if (mpich1_radioButton.Checked)
1448                        {
1449                                mpich1_textBox.Text = mpich1_textBox.Text.Trim();
1450                                if (mpich1_textBox.Text.IndexOf(' ') != -1)
1451                                {
1452                                        cmd = cmd + " -file \"" + mpich1_textBox.Text + "\"";
1453                                }
1454                                else
1455                                {
1456                                        cmd = cmd + " -file " + mpich1_textBox.Text;
1457                                }
1458                        }
1459                        else
1460                        {
1461                                cmd = "";
1462                        }
1463                        return cmd;
1464                }
1465
1466                private void show_command_button_Click(object sender, System.EventArgs e)
1467                {
1468                        command_line_textBox.Text = get_command_line();
1469                }
1470
1471                private void output_richTextBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
1472                {
1473                        if (process != null)
1474                        {
1475                                char_written.WaitOne();
1476                                ch = e.KeyChar;
1477                                char_written.Reset();
1478                                char_available.Set();
1479                        }
1480                }
1481
1482                #region Radio buttons enabling and disabling functions
1483                /// <summary>
1484                /// Enable and disable controls based on which radio button is selected
1485                /// </summary>
1486                private void DisableApplicationControls()
1487                {
1488                        application_label.Enabled = false;
1489                        application_comboBox.Enabled = false;
1490                        application_browse_button.Enabled = false;
1491                        nproc_label.Enabled = false;
1492                        nproc_numericUpDown.Enabled = false;
1493                        wdir_label.Enabled = false;
1494                        wdir_textBox.Enabled = false;
1495                        wdir_browse_button.Enabled = false;
1496                        hosts_label.Enabled = false;
1497                        hosts_textBox.Enabled = false;
1498                        hosts_reset_button.Enabled = false;
1499                        env_label.Enabled = false;
1500                        env_textBox.Enabled = false;
1501                        drive_map_label.Enabled = false;
1502                        drive_map_textBox.Enabled = false;
1503                        channel_label.Enabled = false;
1504                        channel_comboBox.Enabled = false;
1505                        extra_options_label.Enabled = false;
1506                        extra_options_textBox.Enabled = false;
1507                        log_checkBox.Enabled = false;
1508                }
1509
1510                private void EnableApplicationControls()
1511                {
1512                        application_label.Enabled = true;
1513                        application_comboBox.Enabled = true;
1514                        application_browse_button.Enabled = true;
1515                        nproc_label.Enabled = true;
1516                        nproc_numericUpDown.Enabled = true;
1517                        wdir_label.Enabled = true;
1518                        wdir_textBox.Enabled = true;
1519                        wdir_browse_button.Enabled = true;
1520                        hosts_label.Enabled = true;
1521                        hosts_textBox.Enabled = true;
1522                        hosts_reset_button.Enabled = true;
1523                        env_label.Enabled = true;
1524                        env_textBox.Enabled = true;
1525                        drive_map_label.Enabled = true;
1526                        drive_map_textBox.Enabled = true;
1527                        channel_label.Enabled = true;
1528                        channel_comboBox.Enabled = true;
1529                        extra_options_textBox.Enabled = true;
1530                        extra_options_label.Enabled = true;
1531                        log_checkBox.Enabled = true;
1532                }
1533
1534                private void DisableConfigfileControls()
1535                {
1536                        configfile_label.Enabled = false;
1537                        configfile_textBox.Enabled = false;
1538                        configfile_browse_button.Enabled = false;
1539                }
1540
1541                private void EnableConfigfileControls()
1542                {
1543                        configfile_label.Enabled = true;
1544                        configfile_textBox.Enabled = true;
1545                        configfile_browse_button.Enabled = true;
1546                }
1547
1548                private void DisableMPICH1Controls()
1549                {
1550                        mpich1_label.Enabled = false;
1551                        mpich1_textBox.Enabled = false;
1552                        mpich1_browse_button.Enabled = false;
1553                }
1554
1555                private void EnableMPICH1Controls()
1556                {
1557                        mpich1_label.Enabled = true;
1558                        mpich1_textBox.Enabled = true;
1559                        mpich1_browse_button.Enabled = true;
1560                }
1561
1562                private void application_radioButton_CheckedChanged(object sender, System.EventArgs e)
1563                {
1564                        if (application_radioButton.Checked)
1565                        {
1566                                EnableApplicationControls();
1567                                DisableConfigfileControls();
1568                                DisableMPICH1Controls();
1569                        }
1570                }
1571
1572                private void configfile_radioButton_CheckedChanged(object sender, System.EventArgs e)
1573                {
1574                        if (configfile_radioButton.Checked)
1575                        {
1576                                DisableApplicationControls();
1577                                EnableConfigfileControls();
1578                                DisableMPICH1Controls();
1579                        }
1580                }
1581
1582                private void mpich1_radioButton_CheckedChanged(object sender, System.EventArgs e)
1583                {
1584                        if (mpich1_radioButton.Checked)
1585                        {
1586                                DisableApplicationControls();
1587                                DisableConfigfileControls();
1588                                EnableMPICH1Controls();
1589                        }
1590                }
1591                #endregion
1592
1593                #region Dialog expansion and contraction
1594                /// <summary>
1595                /// Manage expansion and contraction of the extra dialog controls
1596                /// </summary>
1597                private void DisableAnchors()
1598                {
1599                        show_bottom_checkBox.Anchor = AnchorStyles.Top;
1600                        wdir_label.Anchor = AnchorStyles.Top;
1601                        wdir_textBox.Anchor = AnchorStyles.Top;
1602                        wdir_browse_button.Anchor = AnchorStyles.Top;
1603                        hosts_label.Anchor = AnchorStyles.Top;
1604                        hosts_textBox.Anchor = AnchorStyles.Top;
1605                        hosts_reset_button.Anchor = AnchorStyles.Top;
1606                        configfile_label.Anchor = AnchorStyles.Top;
1607                        configfile_textBox.Anchor = AnchorStyles.Top;
1608                        configfile_browse_button.Anchor = AnchorStyles.Top;
1609                        mpich1_label.Anchor = AnchorStyles.Top;
1610                        mpich1_textBox.Anchor = AnchorStyles.Top;
1611                        mpich1_browse_button.Anchor = AnchorStyles.Top;
1612                        env_label.Anchor = AnchorStyles.Top;
1613                        env_textBox.Anchor = AnchorStyles.Top;
1614                        drive_map_label.Anchor = AnchorStyles.Top;
1615                        drive_map_textBox.Anchor = AnchorStyles.Top;
1616                        channel_label.Anchor = AnchorStyles.Top;
1617                        channel_comboBox.Anchor = AnchorStyles.Top;
1618                        output_richTextBox.Anchor = AnchorStyles.Top;
1619                        configfile_radioButton.Anchor = AnchorStyles.Top;
1620                        mpich1_radioButton.Anchor = AnchorStyles.Top;
1621                        extra_options_label.Anchor = AnchorStyles.Top;
1622                        extra_options_textBox.Anchor = AnchorStyles.Top;
1623                        log_checkBox.Anchor = AnchorStyles.Top;
1624                        jumpshot_button.Anchor = AnchorStyles.Top;
1625                }
1626
1627                private void EnableAnchors()
1628                {
1629                        show_bottom_checkBox.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
1630                        wdir_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1631                        wdir_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1632                        wdir_browse_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1633                        hosts_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1634                        hosts_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1635                        hosts_reset_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1636                        configfile_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1637                        configfile_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1638                        configfile_browse_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1639                        mpich1_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1640                        mpich1_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1641                        mpich1_browse_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1642                        env_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1643                        env_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1644                        drive_map_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1645                        drive_map_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1646                        channel_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1647                        channel_comboBox.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1648                        output_richTextBox.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right)));
1649                        configfile_radioButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1650                        mpich1_radioButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1651                        extra_options_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1652                        extra_options_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1653                        log_checkBox.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1654                        jumpshot_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1655                }
1656
1657                private void HideExtraOptions()
1658                {
1659                        wdir_label.Hide();
1660                        wdir_textBox.Hide();
1661                        wdir_browse_button.Hide();
1662                        hosts_label.Hide();
1663                        hosts_textBox.Hide();
1664                        hosts_reset_button.Hide();
1665                        configfile_label.Hide();
1666                        configfile_textBox.Hide();
1667                        configfile_browse_button.Hide();
1668                        mpich1_label.Hide();
1669                        mpich1_textBox.Hide();
1670                        mpich1_browse_button.Hide();
1671                        env_label.Hide();
1672                        env_textBox.Hide();
1673                        drive_map_label.Hide();
1674                        drive_map_textBox.Hide();
1675                        channel_label.Hide();
1676                        channel_comboBox.Hide();
1677                        configfile_radioButton.Hide();
1678                        mpich1_radioButton.Hide();
1679                        extra_options_textBox.Hide();
1680                        extra_options_label.Hide();
1681                        log_checkBox.Hide();
1682                        jumpshot_button.Hide();
1683                }
1684
1685                private void ShowExtraOptions()
1686                {
1687                        wdir_label.Show();
1688                        wdir_textBox.Show();
1689                        wdir_browse_button.Show();
1690                        hosts_label.Show();
1691                        hosts_textBox.Show();
1692                        hosts_reset_button.Show();
1693                        configfile_label.Show();
1694                        configfile_textBox.Show();
1695                        configfile_browse_button.Show();
1696                        mpich1_label.Show();
1697                        mpich1_textBox.Show();
1698                        mpich1_browse_button.Show();
1699                        env_label.Show();
1700                        env_textBox.Show();
1701                        drive_map_label.Show();
1702                        drive_map_textBox.Show();
1703                        channel_label.Show();
1704                        channel_comboBox.Show();
1705                        configfile_radioButton.Show();
1706                        mpich1_radioButton.Show();
1707                        extra_options_label.Show();
1708                        extra_options_textBox.Show();
1709                        log_checkBox.Show();
1710                        jumpshot_button.Show();
1711                }
1712
1713                private void UpdateExtraControls(bool bShow)
1714                {
1715                        DisableAnchors();
1716                        if (bShow)
1717                        {
1718                                ShowExtraOptions();
1719                                Height = Height + expanded_dialog_difference;//230;
1720                        }
1721                        else
1722                        {
1723                                HideExtraOptions();
1724                                Height = Height - expanded_dialog_difference;//230;
1725                        }
1726                        EnableAnchors();
1727                }
1728
1729                private void show_bottom_checkBox_CheckedChanged(object sender, System.EventArgs e)
1730                {
1731                        UpdateExtraControls(show_bottom_checkBox.Checked);
1732                }
1733                #endregion
1734
1735                private void wmpiexec_Closing(object sender, System.ComponentModel.CancelEventArgs e)
1736                {
1737                        if (process != null)
1738                        {
1739                                process.Kill();
1740                        }
1741                        if (last_execute_result != null)
1742                        {
1743                                run_command.EndInvoke(last_execute_result);
1744                                last_execute_result = null;
1745                        }
1746                }
1747
1748                private void jumpshot_button_Click(object sender, System.EventArgs e)
1749                {
1750                        Process p;
1751                        string args = "-Xms32m -Xmx256m -jar " + get_jumpshot() + " " + get_clog2();
1752                        //MessageBox.Show("javaw.exe " + args);
1753                        //output_richTextBox.AppendText("javaw.exe " + args + "\r\n");
1754                        try
1755                        {
1756                                p = Process.Start("javaw.exe", args);
1757                        }
1758                        catch (Exception x)
1759                        {
1760                                MessageBox.Show("Unable to start: javaw.exe " + args + "\r\n" + x.Message, "Error");
1761                        }
1762                }
1763        }
1764}
Note: See TracBrowser for help on using the browser.