private void OnCadmTimer() { if (_CadmTaskID <= 0) { return; } String result = ""; StringBuilder taskStatus = new StringBuilder(4096); int progress = 0; Boolean finished = false; if (this.checkBoxAPI.Checked) { //local finished = TaskController.IsTaskFinished(_CadmTaskID); progress = TaskController.GetTaskProgress(_CadmTaskID, taskStatus); } else { progress = CadmAPI.TaskProgress(_reqSession, _CadmTaskID.ToString(), taskStatus); finished = (progress >= 1000); } this.textBoxStatus.Text += taskStatus.ToString().Replace("\t", "\r\n"); this.textBoxStatus.SelectionStart = this.textBoxStatus.Text.Length; this.textBoxStatus.ScrollToCaret(); if (progress >= 0) { this.progressBar.Value = (progress % 1000); Debug.WriteLine(String.Format("Progress: {0} %", (progress % 1000))); } if (finished) { try { taskStatus.Clear(); int errorCode = 0; if (this.checkBoxAPI.Checked) { //local progress = TaskController.GetTaskProgress(_CadmTaskID, taskStatus); this.textBoxStatus.Text += taskStatus.ToString().Replace("\t", "\r\n"); this.textBoxStatus.SelectionStart = this.textBoxStatus.Text.Length; this.textBoxStatus.ScrollToCaret(); if (progress >= 0) { this.progressBar.Value = (progress % 1000); } result = TaskController.GetTaskResult(_CadmTaskID); this.textBoxStatus.Text += result; } else { errorCode = CadmAPI.TaskResult(_reqSession, _CadmTaskID.ToString(), taskStatus); } if (errorCode > 0) { this.textBoxStatus.Text += taskStatus.ToString().Replace("\t", "\r\n"); } } catch (Exception e) { } _CadmTaskID = -1; this.buttonSubmit.Text = "提交任务"; if (_SubmitCountdown > 1) { buttonSubmit_Click(null, null); } } }
private void buttonSubmit_Click(object sender, EventArgs e) { if (!this.checkBoxAPI.Checked) { if (!_reqSession.IsSigned()) { MessageBox.Show("客户端尚未登录", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } } if (sender != null) { _SubmitCountdown = Convert.ToInt32(this.textBoxLoops.Text); } else { _SubmitCountdown--; } if (_CadmTaskID < 0) { String taskType = CadmAPI.TASK_BINPACKING; if (this.radioButtonPathImport.Checked) { taskType = CadmAPI.TASK_PATHIMPORT; } Dictionary <String, String> taskFiles = new Dictionary <string, string>(); String[] pathFiles = this.textBoxFile.Text.Split(';'); for (int i = 0; i < pathFiles.Length; i++) { taskFiles["File" + (i + 1)] = pathFiles[i]; } //this.textBoxStatus.Text = ""; if (this.checkBoxAPI.Checked) { //local String sParam = ""; sParam += String.Format("task_type={0}", taskType); sParam += String.Format("::task_name={0}", taskType); sParam += String.Format("::Length={0}", this.textBoxLength.Text); sParam += String.Format("::Width={0}", this.textBoxWidth.Text); sParam += String.Format("::Height={0}", this.textBoxHeight.Text); sParam += String.Format("::trim={0}", this.textBoxTrim.Text); sParam += String.Format("::gap={0}", this.textBoxSawThickness.Text); sParam += String.Format("::saw_x={0}", this.comboBoxDx.Text + "," + this.comboBoxTx.Text + ",R30"); sParam += String.Format("::saw_y={0}", this.comboBoxDy.Text + "," + this.comboBoxTy.Text + ",R30"); foreach (String path in pathFiles) { sParam += String.Format("::{0}=^_^", path); } _CadmTaskID = TaskController.SubmitTask((IntPtr)0, sParam); } else { //remote _CadmTaskID = CadmAPI.TaskSubmit(_reqSession, taskType, "BinPacking", taskFiles); } if (_CadmTaskID < 0) { MessageBox.Show("启动任务失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } this.buttonSubmit.Text = "终止任务"; } else { if (this.checkBoxAPI.Checked) { //local TaskController.CancelTask(_CadmTaskID); } else { StringBuilder resultMessage = new StringBuilder(8192); CadmAPI.TaskCancel(_reqSession, _CadmTaskID.ToString(), resultMessage); } } }