//激活任务 private void taskActiveToolStripMenuItem_Click(object sender, EventArgs e) { MySqlConnection conn = null; string taskId = this.taskInfoDataGridView.CurrentRow.Cells["taskId"].Value.ToString(); try { conn = DatabaseOpt.getDBConnection(); List <string> taskIdList = DatabaseOpt.queryTaskTag(conn); if (taskIdList.Count > 0) { //显示弹窗 ActiveConfirmForm activeConfirmForm = new ActiveConfirmForm(taskIdList); activeConfirmForm.ShowDialog(); } if (!taskIdList.Contains("cancel")) { //激活任务代码 //通知web端本条任务激活 string phoneNumber = this.taskInfoDataGridView.CurrentRow.Cells["phoneNumber"].Value.ToString(); string IMSI = this.taskInfoDataGridView.CurrentRow.Cells["IMSI"].Value.ToString(); string nationCode = this.taskInfoDataGridView.CurrentRow.Cells["nationCode"].Value.ToString(); string url = "http://192.168.17.232:8989/ghost/getVerificationCode?imsi=" + IMSI + "&phone=" + phoneNumber + "&phone_nation_code=" + nationCode; string responseContent = WebServerCommunicate.httpGet(url); if (!"ok".Equals(responseContent)) { MessageBox.Show("激活失败"); return; } //修改任务标志 DatabaseOpt.updateOne(conn, taskId, "taskTag", "激活"); } }catch (Exception) { MessageBox.Show("发生错误,激活失败"); } finally { DatabaseOpt.close(conn); TaskInfoDataGridViewOpt.updateTaskInfoDataGridView(this.taskInfoDataGridView); } }
//重新吸附任务的实现方法 public void reabsorption(Object id) { MySqlConnection conn = null; string taskId = (string)id; try { conn = DatabaseOpt.getDBConnection(); //查询已激活的任务 string activeTaskId = DatabaseOpt.queryTaskTag(conn)[0]; if (!"".Equals(activeTaskId)) { //已有任务被激活 if (!taskId.Equals(activeTaskId)) { //说明当前激活的任务与重新吸附的任务不同,需要停止其模拟器 string activeTaskEmulatorId = DatabaseOpt.queryOne(conn, activeTaskId, "emulatorId")[0]; //停止模拟器 EmulatiorOpt.shutdownEmu(activeTaskId); } //关闭当前激活任务的appium string activeTaskAppiumPort = DatabaseOpt.queryOne(conn, activeTaskId, "appiumPort")[0]; if (!"".Equals(activeTaskAppiumPort)) { //关闭appium AppiumOpt.endAppium(int.Parse(activeTaskAppiumPort)); //将appium端口置空 DatabaseOpt.updateOne(conn, activeTaskId, "appiumPort", ""); } //关闭socket string activeTaskSocketPort = DatabaseOpt.queryOne(conn, activeTaskId, "socketPort")[0]; if (!"".Equals(activeTaskSocketPort)) { //关闭socket AppiumOpt.endAppium(int.Parse(activeTaskSocketPort)); //将socket端口置空 DatabaseOpt.updateOne(conn, activeTaskId, "socketPort", ""); } //置之前激活的任务标志为普通 DatabaseOpt.updateOne(conn, activeTaskId, "taskTag", "普通"); TaskInfoDataGridViewOpt.updateTaskInfoDataGridView(this.taskInfoDataGridView); } //获取重新吸附任务的appium端口 string appiumPort = DatabaseOpt.queryOne(conn, taskId, "appiumPort")[0]; if (!"".Equals(appiumPort)) { //关闭之前的appium AppiumOpt.endAppium(int.Parse(appiumPort)); //将appium端口置空 DatabaseOpt.updateOne(conn, taskId, "appiumPort", ""); } string socketPort = DatabaseOpt.queryOne(conn, taskId, "socketPort")[0]; if (!"".Equals(socketPort)) { //关闭之前的socket AppiumOpt.endAppium(int.Parse(socketPort)); //将socket端口置空 DatabaseOpt.updateOne(conn, taskId, "socketPort", ""); } //激活任务代码 //通知web端本条任务激活 string phoneNumber = DatabaseOpt.queryOne(conn, taskId, "phoneNumber")[0]; string IMSI = DatabaseOpt.queryOne(conn, taskId, "IMSI")[0]; string nationCode = DatabaseOpt.queryOne(conn, taskId, "nationCode")[0]; string url = "http://192.168.17.232:8989/ghost/getVerificationCode?imsi=" + IMSI + "&phone=" + phoneNumber + "&phone_nation_code=" + nationCode; string responseContent = WebServerCommunicate.httpGet(url); if (!"ok".Equals(responseContent)) { MessageBox.Show("激活失败"); return; } //修改任务标记为激活 DatabaseOpt.updateOne(conn, taskId, "taskTag", "激活"); TaskInfoDataGridViewOpt.updateTaskInfoDataGridView(this.taskInfoDataGridView); //启动任务函数 taskStart(taskId); } finally { DatabaseOpt.close(conn); } }