public void addNewProcessHandleToQueueAndBottom(ProcessHandle ph) { if(processQueueIsLocked) { return; } processQueueIsLocked = true; processQueue.Add(ph); bottom.addNewProcessHandle(ph); processQueueIsLocked = false; }
public void addToDataView(ProcessHandle ph) { ProcessHandleDataGridViewRow processHandleDataGridViewRow = new ProcessHandleDataGridViewRow(ph); string dir = ph.getProcessCaller().getDirectory(); DirectoryDataGridViewTextBoxCell pid = new DirectoryDataGridViewTextBoxCell(ph.getPID()); DirectoryDataGridViewTextBoxCell directory = new DirectoryDataGridViewTextBoxCell(dir); DirectoryDataGridViewTextBoxCell command = new DirectoryDataGridViewTextBoxCell(ph.getProcessCaller().getCmd()); DirectoryDataGridViewTextBoxCell cpu = new DirectoryDataGridViewTextBoxCell(ph.getCPUUsage()); DirectoryDataGridViewTextBoxCell ram = new DirectoryDataGridViewTextBoxCell(ph.getRAMUsage()); DirectoryDataGridViewTextBoxCell runTime = new DirectoryDataGridViewTextBoxCell(ph.getRunningTime()); DirectoryDataGridViewTextBoxCell blocker = new DirectoryDataGridViewTextBoxCell(ph.getBlockedBy() != null ? ph.getBlockedBy().getPID() : ""); DataGridViewButtonCell kill = new DataGridViewButtonCell(); if (dir.Length > 50){ int i = dir.Length; int num = 20; while (i > 50){ i--; num++; } dir = dir.Substring(0, 5) + "....." + dir.Substring(num); } pid.Value = ph.getPID(); directory.Value = dir; command.Value = ph.getProcessCaller().getCmd(); cpu.Value = ph.getCPUUsage(); ram.Value = ph.getRAMUsage(); runTime.Value = ph.getRunningTime(); blocker.Value = ph.getBlockedBy() != null ? ph.getBlockedBy().getPID() : ""; kill.Value = "KILL"; processHandleDataGridViewRow.Cells.Add(pid); processHandleDataGridViewRow.Cells.Add(directory); processHandleDataGridViewRow.Cells.Add(command); processHandleDataGridViewRow.Cells.Add(cpu); processHandleDataGridViewRow.Cells.Add(ram); processHandleDataGridViewRow.Cells.Add(runTime); processHandleDataGridViewRow.Cells.Add(blocker); processHandleDataGridViewRow.Cells.Add(kill); this.bottomUserControlProcessHandleDataGridView.Rows.Add(processHandleDataGridViewRow); }
public void addNewProcessHandle(ProcessHandle ph) { processHandles.Add(ph); addToDataView(ph); }
public override void Handle() { this.ph = new CommandLine(ph.getProcessCaller()).run(ph); }
public ProcessThreadHandler(ProcessHandle ph) { this.ph = ph; }
public ProcessHandleDataGridViewRow(ProcessHandle ph) { this.ph = ph; }
public ProcessHandle setBlockedBy(ProcessHandle blockedBy) { this.blockedBy = blockedBy; return this; }
private void goButton_Click(object sender, EventArgs e) { if(!goButton.Enabled) return; goButton.Enabled = false; List<ProcessCaller> pcs = new List<ProcessCaller>(); foreach (DirectoryDataGridViewRow directoryDataGridViewRow in this.operationControlCommandsDataGridView.Rows){ if (directoryDataGridViewRow.Cells[2] is DataGridViewCheckBoxCell){ if (!(bool)((DataGridViewCheckBoxCell)directoryDataGridViewRow.Cells[2]).EditedFormattedValue){ continue; } } ProcessCaller pc = new ProcessCaller("cmd.exe"); if (directoryDataGridViewRow.Cells[0] is DirectoryDataGridViewTextBoxCell){ pc.setDirectory(((DirectoryDataGridViewTextBoxCell)directoryDataGridViewRow.Cells[0]).getDirectory()); } if (directoryDataGridViewRow.Cells[1] is DataGridViewComboBoxCell){ pc.setCmd(PreloadedConfigurationGetterService.getInstance().getCommand(this.configFile, ((string)((DataGridViewComboBoxCell)directoryDataGridViewRow.Cells[1]).Value).Trim() )); } if (directoryDataGridViewRow.Cells[3] is DataGridViewCheckBoxCell){ //display pc.setPrefix((bool)((DataGridViewCheckBoxCell)directoryDataGridViewRow.Cells[3]).EditedFormattedValue ? "/k" : "/c"); } if (directoryDataGridViewRow.Cells[4] is DataGridViewCheckBoxCell){ //autoexit if ((bool)((DataGridViewCheckBoxCell)directoryDataGridViewRow.Cells[4]).EditedFormattedValue){ pc.setAutoExit(); } } if (directoryDataGridViewRow.Cells[5] is DataGridViewCheckBoxCell){ //wait for exit if ((bool)((DataGridViewCheckBoxCell)directoryDataGridViewRow.Cells[5]).EditedFormattedValue || !(bool)((DataGridViewCheckBoxCell)directoryDataGridViewRow.Cells[5]).Visible){ pc.setWaitForExit(); } } pc.setSpecial(""); pcs.Add(pc); //string text3 = "/c " + directory.ToCharArray()[0] + ": && cd " + directory + " && " + directory; //Console.WriteLine(text3); } //ProcessThreadHandler Cursor.Current = Cursors.WaitCursor; try{ ProcessHandle blocker = null; foreach (ProcessCaller pc in pcs){ if (pc.echo()){ cmdTextBox.Text = pc.getCmd(); } ProcessHandle ph = new ProcessHandle(pc); ProcessThreadHandler pht = new ProcessThreadHandler(ph); Thread handleCommand = new Thread(new ThreadStart(pht.Handle)); handleCommand.Start(); if(pc.waitForExit()){ ph.setBlockedBy(blocker); } blocker = ph; ((UserControlForm)this.Parent).addNewProcessHandleToQueueAndBottom(ph); } } finally { Cursor.Current = Cursors.Default; } goButton.Enabled = true; }
public abstract ProcessHandle run(ProcessHandle ph);
public void addToProcessQueue(ProcessHandle ph) { this.processQueue.Add(ph); }
public bool removeProcessHandleIfExists(ProcessHandle ph) { if(processQueue.Contains(ph)){ processQueue.Remove(ph); return true; } return false; }