/// <summary>
        /// 传到指定模拟器编号启动登录
        /// </summary>
        private void AutomaticLogin(object login)
        {
            LoginInfo li = (LoginInfo)login;

            Task.Run(() =>
            {
                //获取所有设备连接信息
                List <string> devicesList = ProcessUtils.AdbDevices();
                gridLListSimulators.Clear();
                string txt = "";
                if (this.dgAccountManagement.Items[li.index] != null)
                {
                    if (((Xzy.EmbeddedApp.Model.admins) this.dgAccountManagement.Items[li.index]).login_pwd != null && ((Xzy.EmbeddedApp.Model.admins) this.dgAccountManagement.Items[li.index]).login_user != null)
                    {
                        if (((Xzy.EmbeddedApp.Model.admins) this.dgAccountManagement.Items[li.index]).login_pwd.Trim() != "" && ((Xzy.EmbeddedApp.Model.admins) this.dgAccountManagement.Items[li.index]).login_user.Trim() != "")
                        {
                            gridLListSimulators.Add(this.dgAccountManagement.Items[li.index] as Xzy.EmbeddedApp.Model.admins);
                        }
                        txt += ((Xzy.EmbeddedApp.Model.admins) this.dgAccountManagement.Items[li.index]).login_user.Trim() + "\r\n" +
                               ((Xzy.EmbeddedApp.Model.admins) this.dgAccountManagement.Items[li.index]).login_pwd + "\r\n";
                    }
                }

                if (((Xzy.EmbeddedApp.Model.admins) this.dgAccountManagement.Items[0]).login_user != null)
                {
                    string connectDeviceCmd = string.Format("{0}/adb -s {1} shell", ProcessUtils.LDPath, devicesList[li.index].ToString());
                    if (devicesList[li.index].IndexOf(li.port) > 0)
                    {
                        string cmdInputText = string.Format("input text {0}", gridLListSimulators[0].login_user);
                        string cmdInputTap  = string.Format("input tap {0} {1}", 100, 200);
                        string cmdTab       = "input keyevent 61";
                        string cmdPwd       = string.Format("input text {0}", gridLListSimulators[0].login_pwd);
                        string cmdLogin     = string.Format("input tap {0} {1}", 100, 300);
                        string cmdConfirm   = string.Format("input tap {0} {1}", 245, 465);

                        StreamWriter sw = new StreamWriter(@"D:\" + li.index.ToString() + ".txt");
                        sw.WriteLine(cmdInputTap);
                        sw.WriteLine(cmdInputText);
                        sw.WriteLine(cmdInputTap);
                        sw.WriteLine(cmdTab);
                        sw.WriteLine(cmdPwd);
                        sw.WriteLine(cmdLogin);
                        sw.WriteLine(cmdConfirm);
                        sw.Close();

                        DeviceOperation deviceOperation = new DeviceOperation();
                        deviceOperation.RunText(connectDeviceCmd, @"D:\" + li.index.ToString() + ".txt");
                    }
                }
            });
        }
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            int    id     = dgAccountManagement.SelectedIndex;
            int    number = -1;
            int    num    = 555 + 2 * id;
            string port2  = "5" + num;

            SystemConfigBLL bLL = new SystemConfigBLL();

            Task.Run(() =>
            {
                List <string> devicesList = ProcessUtils.AdbDevices();
                foreach (string deviceIP in devicesList)
                {
                    if (deviceIP.IndexOf(port2) > 0)
                    {
                        string port                     = deviceIP.Remove(0, deviceIP.Length - 4);
                        string connectDeviceCmd         = string.Format("{0}/adb -s {1} shell", ProcessUtils.LDPath, deviceIP);
                        string cmdPs                    = string.Format("ps");
                        string cmdExit                  = string.Format("exit");
                        DeviceOperation deviceOperation = new DeviceOperation();
                        deviceOperation
                        .SetCmd(connectDeviceCmd)
                        .SetCmd(cmdPs)
                        .SetCmd(cmdExit)
                        .Run2(id, out number);

                        switch (number)
                        {
                        case 0:
                            List <SystemConfig> model = bLL.GetSystemConfigList(id);
                            if (model.Count > 0)
                            {
                                model[0].state = 0;
                                bLL.UpdateSystemConfig(model[0]);
                            }
                            else
                            {
                                SystemConfig sc = new SystemConfig();
                                sc.uid          = id;
                                sc.state        = 0;
                                bLL.AddSystemConfig(sc);
                            }
                            break;

                        case 1:
                            model = bLL.GetSystemConfigList(id);
                            if (model.Count > 0)
                            {
                                model[0].state = 1;
                                bLL.UpdateSystemConfig(model[0]);
                            }
                            else
                            {
                                SystemConfig sc = new SystemConfig();
                                sc.uid          = id;
                                sc.state        = 0;
                                bLL.AddSystemConfig(sc);
                            }
                            break;
                        }
                        //1表示已启动了0表示为没启动com.facebook.katana;判断模拟器是否启动facebook应用,有返回没启动

                        if (number == 0)
                        {
                            #region 启动Facebook
                            if (_runningGroupIndex == -1)
                            {
                                MessageDialogManager.ShowDialogAsync(SystemLanguageManager.Instance.ResourceManager.GetString("Error_Please_Launch_A_Vm", SystemLanguageManager.Instance.CultureInfo));
                                return;
                            }
                            string packagename       = "com.facebook.katana";
                            List <Phonenum> listPhon = new PhonenumBLL().SelectPhoneNumber();

                            for (int i = 0; i < VmManager.Instance.Column; i++)
                            {
                                int vmIndex = VmManager.Instance.VmIndexArray[_runningGroupIndex, i];
                                if (vmIndex != -1)
                                {
                                    ProcessUtils.AdbOpenApps(vmIndex, packagename);
                                }
                            }
                            break;
                            #endregion
                        }
                    }

                    LoginInfo li = new LoginInfo();
                    li.index     = id;
                    li.port      = port2;
                    if (th == null || !th.IsAlive)
                    {
                        th = new Thread(new  ParameterizedThreadStart(AutomaticLogin));
                        th.IsBackground = true;
                        th.Start(li);
                    }
                }
            });
        }