Esempio n. 1
0
        //停止任务的实现方法
        public void taskStop(Object id)
        {
            MySqlConnection conn   = null;
            string          taskId = (string)id;

            try
            {
                conn = DatabaseOpt.getDBConnection();

                //获取本模拟器的编号通过命令行停止,关闭appium和socket连接
                string emulatorId = DatabaseOpt.queryOne(conn, taskId, "emulatorId")[0];
                if (!"".Equals(emulatorId))
                {
                    //说明模拟器编号不为空,执行关闭模拟器操作
                    EmulatiorOpt.shutdownEmu(emulatorId);
                }
                string appiumPort = DatabaseOpt.queryOne(conn, taskId, "appiumPort")[0];
                if (!"".Equals(appiumPort))
                {
                    //说明appium端口不为空
                    AppiumOpt.endAppium(int.Parse(appiumPort));
                }
                string socketPort = DatabaseOpt.queryOne(conn, taskId, "socketPort")[0];
                if (!"".Equals(socketPort))
                {
                    //说明socket端口不为空
                    AppiumOpt.endAppium(int.Parse(socketPort));
                }

                //修改任务状态和任务标志
                DatabaseOpt.updateOne(conn, taskId, "taskStatus", "停止");
                DatabaseOpt.updateOne(conn, taskId, "taskTag", "普通");
            }
            catch (Exception)
            {
                MessageBox.Show("任务停止出错");
            }
            finally
            {
                DatabaseOpt.close(conn);
                TaskInfoDataGridViewOpt.updateTaskInfoDataGridView(this.taskInfoDataGridView);
            }
        }
Esempio n. 2
0
        //是按钮
        private void confirmBtn_Click(object sender, EventArgs e)
        {
            MySqlConnection conn = null;

            try
            {
                conn = DatabaseOpt.getDBConnection();
                //将已激活任务置为普通
                for (int i = 0; i < taskIdList.Count; i++)
                {
                    string taskId = taskIdList[i];
                    //停止任务的代码
                    //查询并停止模拟器
                    string emualtorId = DatabaseOpt.queryOne(conn, taskId, "emulatorId")[0];
                    if (!"".Equals(emualtorId))
                    {
                        //说明模拟器已创建,通过命令行停止
                        EmulatiorOpt.shutdownEmu(emualtorId);
                    }
                    string appiumPort = DatabaseOpt.queryOne(conn, taskId, "appiumPort")[0];
                    if (!"".Equals(appiumPort))
                    {
                        //说明appium已经启动,通过命令行杀死
                        AppiumOpt.endAppium(int.Parse(appiumPort));
                    }
                    string socketPort = DatabaseOpt.queryOne(conn, taskId, "socketPort")[0];
                    if (!"".Equals(socketPort))
                    {
                        //说明socket已经开启,通过命令行杀死
                        AppiumOpt.endAppium(int.Parse(socketPort));
                    }

                    DatabaseOpt.updateOne(conn, taskId, "taskTag", "普通");
                    DatabaseOpt.updateOne(conn, taskId, "taskStatus", "停止");
                }
            }
            finally
            {
                DatabaseOpt.close(conn);
                this.Dispose();
            }
        }
Esempio n. 3
0
        //重新吸附任务的实现方法
        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);
            }
        }