Untitled

 avataruser_9934166
plain_text
17 days ago
80 kB
9
Indexable
Never
using MailKit;
using MailKit.Net.Imap;
using MailKit.Search;
using MailKit.Security;
using MimeKit;
using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.Ocsp;
using requesttool_changeaccountbyIDPASS;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Authentication;
using System.Security.Policy;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Windows;
using System.Windows.Controls;
using TwoFactorAuthNet;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;

namespace requesttool_changeaccountbyIDPASS
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : System.Windows.Window, INotifyPropertyChanged
    {
        public MainWindow()
        {
            InitializeComponent();
            if (!Directory.Exists(Environment.CurrentDirectory + "\\data\\datamain")) Directory.CreateDirectory(Environment.CurrentDirectory + "\\data");
            MainDataGrid = new ObservableCollection<Profile>();
            FormLogin form = new FormLogin();
            if (form.ShowDialog() == false)
            {
                this.Close();
            }
            
        
        }
        public class Work
        {
            public List<string> ListNamePage { get; set; }
            public List<string> ListTargetUid { get; set; }
            public List<string> ListMail { get; set; }
            public Profile pro { get; set; }
        }
        public class Profile : INotifyPropertyChanged
        {

            public IntPtr handChrome { set; get; }

            private string _LocationSort;
            public string LocationSort { get => _LocationSort; set { _LocationSort = value; OnPropertyChanged(); } }
            private bool _IsSelected { get; set; }
            public bool IsSelected { get => _IsSelected; set { _IsSelected = value; OnPropertyChanged(); } }
            private int _ID;
            public int ID { get => _ID; set { _ID = value; OnPropertyChanged(); } }

            private string _ProxyUrl;
            public string ProxyUrl { get => _ProxyUrl; set { _ProxyUrl = value; OnPropertyChanged(); } }

            private string _Status;
            public string Status { get => _Status; set { _Status = value; OnPropertyChanged(); } }
            private string _Cookie { get; set; }
            public string Cookie { get => _Cookie; set { _Cookie = value; OnPropertyChanged(); } }

            private string _Country { get; set; }
            public string Country { get => _Country; set { _Country = value; OnPropertyChanged(); } }

            private string _createDate { get; set; }
            public string createDate { get => _createDate; set { _createDate = value; OnPropertyChanged(); } }
            private string _birthday { get; set; }
            public string birthday { get => _birthday; set { _birthday = value; OnPropertyChanged(); } }
            private string _Email;
            public string Email { get => _Email; set { _Email = value; OnPropertyChanged(); } }
            private string _PassEmail;
            public string PassEmail { get => _PassEmail; set { _PassEmail = value; OnPropertyChanged(); } }
            private string _Password;
            public string Password { get => _Password; set { _Password = value; OnPropertyChanged(); } }
            private string _SecrectKey;
            public string SecrectKey { get => _SecrectKey; set { _SecrectKey = value; OnPropertyChanged(); } }
            private string _UID;
            public string UID { get => _UID; set { _UID = value; OnPropertyChanged(); } }


            #region INotifyPropertyChanged Members

            public event PropertyChangedEventHandler PropertyChanged;

            protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
            #endregion
        }
        public class GridRow : INotifyPropertyChanged
        {
            private int _ID;
            public int ID { get => _ID; set { _ID = value; OnPropertyChanged(); } }
            private string _GroupID;
            public string GroupID { get => _GroupID; set { _GroupID = value; OnPropertyChanged(); } }
            private string _UID;
            public string UID { get => _UID; set { _UID = value; OnPropertyChanged(); } }

            private string _IP;
            public string IP { get => _IP; set { _IP = value; OnPropertyChanged(); } }
            private string _Status;
            public string Status { get => _Status; set { _Status = value; OnPropertyChanged(); } }
            private string _HCQC;
            public string HCQC { get => _HCQC; set { _HCQC = value; OnPropertyChanged(); } }
            private string _IdAds;
            public string IdAds { get => _IdAds; set { _IdAds = value; OnPropertyChanged(); } }
            private string _End;
            public string End { get => _End; set { _End = value; OnPropertyChanged(); } }
            #region INotifyPropertyChanged Members

            public event PropertyChangedEventHandler PropertyChanged;

            protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
            #endregion
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion

        private ObservableCollection<GridRow> _DataChangeAccount;
        public ObservableCollection<GridRow> DataChangeAccount
        {
            get => _DataChangeAccount; set { _DataChangeAccount = value; OnPropertyChanged(); }
        }

        private ObservableCollection<Profile> _MainDataGrid;
        public ObservableCollection<Profile> MainDataGrid
        {
            get => _MainDataGrid; set { _MainDataGrid = value; OnPropertyChanged(); }
        }

        private void Checkbox_CheckAll(object sender, RoutedEventArgs e)
        {
            bool flag = Check_ALL.IsChecked is true;
            foreach (Profile pro in MainDataGrid)
            {
                pro.IsSelected = flag;
            }
        }

        private void MenuItem_ClickImportVia(object sender, RoutedEventArgs e)
        {
            ImportVia imp = new ImportVia();
            if (imp.ShowDialog() == true)
            {
                string input = imp.input_text;
                string type = imp.type_input;
                List<String> listinput = input.GetAllLines();
                List<String> listtype = type.GetAllNodes("|");
                foreach (string info in listinput)
                {
                    List<String> listinfo = info.GetAllNodes("|");
                    Profile pro = new Profile();
                    pro.ID = MainDataGrid.Count + 1;
                    for (int i = 0; i < listtype.Count; i++)
                    {
                        if (i >= listinfo.Count) break;
                        switch (listtype[i])
                        {
                            case "UID":
                                pro.UID = listinfo[i];
                                break;
                            case "PASS":
                                pro.Password = listinfo[i];
                                break;
                            case "2FA":
                                pro.SecrectKey = listinfo[i];
                                break;
                            case "Email":
                                pro.Email = listinfo[i];
                                break;
                            case "Pass Email":
                                pro.PassEmail = listinfo[i];
                                break;
                            case "Cookie":
                                pro.Cookie = listinfo[i];
                                break;
                            case "Proxy":
                                pro.ProxyUrl = listinfo[i];
                                break;
                        }
                    }
                    MainDataGrid.Add(pro);
                }
                File.WriteAllText(Environment.CurrentDirectory + "\\DATA\\DataMain", JsonConvert.SerializeObject(MainDataGrid));
            }
        }

        private void MenuItem_ClickCopyVia(object sender, RoutedEventArgs e)
        {
            ImportVia import = new ImportVia();
            if (import.ShowDialog() == false) return;
            string[] cauhinh = import.type_input.Split('|');
            string temp = "";
            foreach (var pro in MainDataGrid.ToList())
            {
                if (!pro.IsSelected) continue;
                string info = "";

                foreach (string p in cauhinh)
                {
                    switch (p)
                    {
                        case "UID":
                            {
                                info += pro.UID + "|";
                            }
                            break;
                        case "PASS":
                            {
                                info += pro.Password + "|";
                            }
                            break;
                        case "2FA":
                            {
                                info += pro.SecrectKey + "|";
                            }
                            break;
                        case "Email":
                            {
                                info += pro.Email + "|";
                            }
                            break;
                        case "Pass Email":
                            {
                                info += pro.PassEmail + "|";
                            }
                            break;
                        case "Cookie":
                            {
                                info += pro.Cookie + "|";
                            }
                            break;
                        case "Birthday":
                            {
                                info += pro.birthday + "|";
                            }
                            break;
                        case "Create Day":
                            {
                                info += pro.createDate + "|";
                            }
                            break;
                        case "Proxy":
                            {
                                info += pro.ProxyUrl + "|";
                            }
                            break;
                    }

                }
                if (!temp.Contains(info)) temp += info.TrimEnd('|') + "\n";
            }
            if (!string.IsNullOrEmpty(temp)) System.Windows.Clipboard.SetDataObject(temp.TrimEnd('\n'));  //Clipboard.SetDataObject : copy dữ liệu temp vào clipboard
        }

        private void MenuItem_SelectedCell(object sender, RoutedEventArgs e)
        {
            foreach (var items in datagrid.SelectedCells)
            {
                Profile pro = items.Item as Profile;
                pro.IsSelected = true;
            }
        }

        private void ButtonClick_DeleteProfile(object sender, RoutedEventArgs e)
        {
            List<Profile> listprofile = MainDataGrid.Where(x => x.IsSelected).ToList();
            foreach (Profile pro in listprofile)
            {
                MainDataGrid.Remove(pro);
            }
        }

        private void Click_Filter_Profile(object sender, RoutedEventArgs e)
        {
        }

        private void MainWD_Loaded(object sender, RoutedEventArgs e)
        {
            if (File.Exists(Environment.CurrentDirectory + "\\DATA\\DataMain"))
            {
                List<Profile> listProfile = JsonConvert.DeserializeObject<List<Profile>>(File.ReadAllText(Environment.CurrentDirectory + "\\DATA\\DataMain"));
                foreach (Profile pro in listProfile)
                {
                    if (pro != null)
                        MainDataGrid.Add(pro);
                }
            }
            if (File.Exists(Environment.CurrentDirectory + "\\setting.json"))
            {
                string tmp = File.ReadAllText(Environment.CurrentDirectory + "\\setting.json");
                List<element> listjson = JsonConvert.DeserializeObject<List<element>>(tmp);
                var fields = typeof(MainWindow).GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
                foreach (FieldInfo FI in fields)
                {
                    if (FI.FieldType == typeof(TextBox))
                    {
                        TextBox value = FI.GetValue(this) as TextBox;

                        foreach (element ele in listjson)
                        {
                            if (FI.Name.Equals(ele.name)) value.Text = Encoding.UTF8.GetString(Convert.FromBase64String(ele.value));
                        }
                    }
                    if (FI.FieldType == typeof(CheckBox))
                    {
                        CheckBox value = FI.GetValue(this) as CheckBox;
                        foreach (element ele in listjson)
                        {
                            if (FI.Name.Equals(ele.name)) value.IsChecked = bool.Parse(ele.value);
                        }
                    }
                    if (FI.FieldType == typeof(ComboBox))
                    {
                        ComboBox value = FI.GetValue(this) as ComboBox;
                        foreach (element ele in listjson)
                        {
                            if (FI.Name.Equals(ele.name)) value.SelectedIndex = int.Parse(ele.value);
                        }
                    }
                }
            }

        }
        public class element
        {
            public string name { set; get; }
            public string value { set; get; }
        }
        private void MainWD_Closed(object sender, EventArgs e)
        {
            File.WriteAllText(Environment.CurrentDirectory + "\\DATA\\DataMain", JsonConvert.SerializeObject(MainDataGrid));
            var fields = typeof(MainWindow).GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
            List<element> listsetting = new List<element>();
            foreach (FieldInfo FI in fields)
            {
                if (FI.FieldType == typeof(TextBox))
                {
                    TextBox value = FI.GetValue(this) as TextBox;
                    listsetting.Add(new element { name = FI.Name, value = Convert.ToBase64String(Encoding.UTF8.GetBytes(value.Text)) });
                }
                if (FI.FieldType == typeof(System.Windows.Controls.CheckBox))
                {
                    CheckBox value = FI.GetValue(this) as CheckBox;
                    listsetting.Add(new element { name = FI.Name, value = value.IsChecked.Value.ToString() });

                }
                if (FI.FieldType == typeof(System.Windows.Controls.ComboBox))
                {
                    ComboBox value = FI.GetValue(this) as ComboBox;
                    listsetting.Add(new element { name = FI.Name, value = value.SelectedIndex.ToString() });

                }
            }
            File.WriteAllText(Environment.CurrentDirectory + "\\setting.json", JsonConvert.SerializeObject(listsetting));
        }
        private static Random random = new Random();

        public static string GenerateRandomString(int length)
        {
            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            return new string(Enumerable.Repeat(chars, length)
              .Select(s => s[random.Next(s.Length)]).ToArray());
        }

        public static string GetRanDomName(int length)
        {
            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
            return new string(Enumerable.Repeat(chars, length)
              .Select(s => s[random.Next(s.Length)]).ToArray());
        }
        public static string GetRandompass(int length)
        {
            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            return new string(Enumerable.Repeat(chars, length)
              .Select(s => s[random.Next(s.Length)]).ToArray());
        }
        // viết code

        private void selectMessage(object sender, SelectionChangedEventArgs e)
        {

        }

        string getdata(string html)
        {
            string datapost = "";
            List<string> list = new List<string>();
            var listnode = Regex.Matches(html, "name=\"([^\"]+)\" value=\"([^\"]+)\"");
            foreach (Match node in listnode)
            {
                string name = node.Groups[1].Value;
                if (name.Equals("_fb_noscript")) continue;
                string value = node.Groups[2].Value;
                if (list.Contains(name)) continue;
                list.Add(name);
                datapost += $"&{name}={value}";
            }
            return datapost;
        }

        private void Click_btnStartChangebyIdpass(object sender, RoutedEventArgs e)
        {
            MyQueue<string> listUidChangemail = new MyQueue<string>(txt_listUidChangemail.Text.GetAllLines());
            List<string> listEmail = txt_listEmailchange.Text.GetAllLines();
            List<string> listHttps = txt_listProxyChangemail.Text.GetAllLines();

            MyQueue<string> listEmailQueue = new MyQueue<string>(listEmail); // build lại để mỗi luồng không bị get mail trùng nhau
            //MyQueue<string> listHttps = new MyQueue<string>(txt_listProxyChangemail.Text.GetAllLines());
            Random random = new Random();
            string password = txt_newpassChangemail.Text;
            string typelogin = cb_loginChangeidpass.Text;
            List<string> newapiproxy = txt_listProxyChangemail.Text.GetAllLines();
            bool isDeleteOldMail = tgbtn_deleteOldmail.IsChecked is true;
            bool isAddnewmail = tgbtn_addNewmail.IsChecked is true;
            bool isDeletePhone = tgbtn_deletePhone.IsChecked is true;
            bool isRandompass = tgbtn_randomPass.IsChecked is true;
            bool isResetPassword = tgbtn_changePassword.IsChecked is true;
            string cbwebproxy = cb_webproxyChangemail.Text;
            int soluong = txt_soluongChangemail.Text.ToInt(1);
            int delay = txt_delayChangemail.Text.ToInt(7);
            if (newapiproxy.Count == 0)
            {
                for (int i = 0; i < soluong; i++)
                {
                    newapiproxy.Add("NoProxy");
                }
            }
            int soProxy = newapiproxy.Count;
            if (cbwebproxy == "HTTPS")
            {
                if (soluong < soProxy)
                {
                    soProxy = soluong;
                }
            }
            btnStartChangebyIdpass.IsEnabled = false; // khi start, nút start sẽ bị đen
            isStopChange = false;
            DataChangeAccount = new ObservableCollection<GridRow>();
            Task tk = new Task(() =>
            {
                int soluong_1proxy = soluong / soProxy;
                TaskQueue<JobQueue> taskQueue = new TaskQueue<JobQueue>();
                taskQueue.RunRandom = false;//true: ngẫu nhiên trong hàng chờ, không theo thứ tự trước sau.
                taskQueue.UseAsyncContext = false;//true: use Nito AsyncContext
                taskQueue.TaskScheduler = TaskScheduler.Default;
                taskQueue.MaxRun = soluong;//số lượng luồng tối đa
                taskQueue.RunAsParty = true;//true: chạy theo nhóm, tức 5 cái xong mới bắt đầu chạy 5 cái kế.
                foreach (string proxy1 in newapiproxy)
                {
                    JobQueue job = new JobQueue(proxy1);
                    job.ListTarget = new List<string>();
                    for (int i = 0; i < soluong_1proxy; i++)
                    {
                        string tempuid = listUidChangemail.Dequeue();
                        if (string.IsNullOrEmpty(tempuid)) break;
                        job.ListTarget.Add(tempuid);
                    }
                    job.Work = new Task(() =>
                    {

                        while (true)
                        {
                            string proxy = "";
                            if (!job.JobData.Equals("NoProxy"))
                            {
                                string keyapi = newapiproxy.GetRandom();
                                WebProxyApi webproxy = new WebProxyApi(keyapi);
                                RequestHTTP req = new RequestHTTP();
                                string myip = req.Get("https://api.ipify.org/").Result;
                                //code xử lý 1 luồng
                                switch (cbwebproxy)
                                {
                                    case "Không Đổi IP":
                                        RequestHTTP getIp = new RequestHTTP();
                                        string GetIp = getIp.Get("https://whoer.net/fr").Result;
                                        proxy = Regex.Match(GetIp, "ip: \"(.*?)\", iso").Groups[1].Value;
                                        break;
                                    case "TinsoftProxy.Com":
                                        string checkipTinsoft = webproxy.CheckProxyTinsoft();
                                        if (string.IsNullOrEmpty(checkipTinsoft))
                                        {
                                            proxy = webproxy.GetNewProxyTinsoft();
                                        }
                                        else
                                        {
                                            int checktime = webproxy.CheckTimeTinsoft();
                                            if (checktime > 0)
                                            {
                                                proxy = checkipTinsoft;
                                            }
                                            else
                                            {
                                                proxy = webproxy.GetNewProxyTinsoft();
                                            }
                                        }
                                        break;
                                    case "proxy.shoplike.vn":
                                        proxy = webproxy.GetNewProxyShoplike();
                                        break;
                                    case "proxyv6.net":
                                        webproxy.MyIP = myip;
                                        proxy = webproxy.getProxyv6net();
                                        break;
                                }
                            }
                            Parallel.For(0, soluong_1proxy, i =>
                            {
                                #region 1 LUỒNG CON

                                GridRow row = new GridRow();
                                try
                                {
                                    if (isStopChange == true)
                                    {
                                        return;
                                    }
                                    //code 1 luồng con ở trong này
                                    if (i >= job.ListTarget.Count) { return; }
                                    Profile pro = MainDataGrid.Find(x1 => job.ListTarget[i].Equals(x1.UID));
                                    if (pro == null || pro == default)
                                    {
                                        //xu ly khi k tim thay profile
                                        return;
                                    }
                                    pro.ProxyUrl = proxy;
                                    row.IP = proxy;
                                    this.Dispatcher.Invoke(() =>
                                    {
                                        row.ID = DataChangeAccount.Count + 1;
                                        row.UID = pro.UID;
                                        row.Status = "Bắt đầu Thay Thông Tin...";
                                        DataChangeAccount.Add(row);
                                    });
                                    if (typelogin == "Id|Pass|2fa")
                                    {
                                        #region CODE LOGIN = 2FA RỒI GET COOKIE
                                        RequestHTTP requestlogin = new RequestHTTP("", ProxyUrl: proxy);
                                        requestlogin.LoginFacebookGetToken(pro, row);
                                        if (row.Status == "CP 282!")
                                        {
                                            return;
                                        }
                                        if (row.Status == "CP 956!")
                                        {
                                            return;
                                        }
                                        if (row.Status == "Sai pass")
                                        {
                                            return;
                                        }
                                        if (row.Status == "Lỗi mạng")
                                        {
                                            return;
                                        }
                                        if (row.Status == "Sai 2FA")
                                        {
                                            return;
                                        }
                                        if (row.Status == "ERROR COOKIE!")
                                        {
                                            return;
                                        }
                                        #endregion
                                    }

                                    RequestHTTP requestChangeEmail = new RequestHTTP(cookies: pro.Cookie, ProxyUrl: proxy);
                                    string Newpassword = "";
                                    if (isRandompass)
                                    {
                                        Newpassword = $"{password}{GetRandompass(5)}";
                                    }
                                    else
                                    {
                                        Newpassword = password;
                                    }
                                    string userEmail = "";
                                    string passEmail = "";
                                    if (isAddnewmail)
                                    {
                                        row.Status = "Đang change mail mới...";
                                        string email = listEmailQueue.Dequeue();
                                        userEmail = email.Split('|')[0];
                                        passEmail = email.Split('|')[1];
                                        string codeemail = "";
                                        string Linkconfirm = "";
                                        string addEmailnopass = requestChangeEmail.Addmailnopass(userEmail).Result;
                                        if (!addEmailnopass.Contains("facebookdotcom"))
                                        {
                                            row.Status = "Add mail thất bại!!!";
                                            return;
                                        }
                                        row.Status = $"Đang vào {userEmail} Xác nhận...";
                                        #region VÀO EMAIL BẤM NÚT XÁC NHẬN EMAIL CHỨ KH LẤY CODE
                                        int demcheck = 0;
                                        int port = 993;
                                        string host = "outlook.office365.com";
                                        try
                                        {
                                            using (var client = new ImapClient())
                                            {
                                                client.SslProtocols = SslProtocols.Ssl3 | SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
                                                client.Connect(host, port, SecureSocketOptions.SslOnConnect);
                                                client.AuthenticationMechanisms.Remove("XOAUTH2");
                                                client.Authenticate(userEmail, passEmail);
                                                Task.Delay(1000).Wait();
                                                MimeMessage mess = new MimeMessage() { Date = DateTime.Now };
                                                do
                                                {
                                                    Task.Delay(3000).Wait();
                                                    client.Inbox.Open(FolderAccess.ReadOnly);
                                                    var messengeUIDs = client.Inbox.Search(SearchQuery.FromContains("facebook")).ToList();
                                                    int countmess = messengeUIDs.Count - 1;
                                                    while (messengeUIDs.Count > 0 && countmess >= 0)
                                                    {
                                                        mess = client.Inbox.GetMessage(messengeUIDs[countmess]);
                                                        if (DateTime.UtcNow - mess.Date.UtcDateTime > TimeSpan.FromSeconds(120))
                                                        {
                                                            countmess--;
                                                            continue;
                                                        }
                                                        string textinput = mess.HtmlBody;
                                                        if (string.IsNullOrEmpty(textinput)) textinput = mess.TextBody;
                                                        string getLinkconfirm = Regex.Match(textinput, "href=\"https://www.facebook.com/confirmcontact.php(.*?)\"").Groups[1].Value;
                                                        if (string.IsNullOrEmpty(getLinkconfirm))
                                                        {
                                                            countmess--;
                                                            continue;
                                                        }
                                                        Linkconfirm = $"https://www.facebook.com/confirmcontact.php{getLinkconfirm}";

                                                        if (!string.IsNullOrEmpty(Linkconfirm)) break;
                                                    }
                                                    demcheck++;
                                                    Task.Delay(3000).Wait();
                                                } while (string.IsNullOrEmpty(Linkconfirm) && demcheck < 30);
                                                client.Disconnect(true);
                                            }
                                        }
                                        catch (Exception ex) { }
                                        #endregion
                                        if (string.IsNullOrEmpty(Linkconfirm))
                                        {
                                            row.Status = "Thêm Mail Thất Bại!!!";
                                            return;
                                        }
                                        string confirmEmail = requestChangeEmail.Get(Linkconfirm).Result;
                                        row.Status = "Xác nhận thành công!";
                                        pro.Email = userEmail;
                                        pro.PassEmail = passEmail;
                                        Task.Delay(1000).Wait();
                                    }
                                    if (isResetPassword)
                                    {
                                        row.Status = "Đang đổi Pass...";
                                        string getName = requestChangeEmail.Get("https://accountscenter.facebook.com/password_and_security").Result;
                                        string doipass = requestChangeEmail.GraphApi("&variables={\"account_id\":\"" + pro.UID + "\",\"account_type\":\"FACEBOOK\",\"current_password_enc\":\"" + pro.Password + "\",\"new_password_enc\":\"" + Newpassword + "\",\"new_password_confirm_enc\":\"" + Newpassword + "\",\"client_mutation_id\":\"395d5761-7cd3-452f-aa5a-5494d9177643\"}&doc_id=4872350656193366").Result;
                                        if (doipass.Contains("\"success\":true"))
                                        {
                                            pro.Password = Newpassword;
                                            row.Status = "Đổi pass thành công!!";
                                            Task.Delay(1000).Wait();
                                        }
                                        else
                                        {
                                            row.Status = "Đổi pass thất bại!!";
                                            return;
                                        }
                                    }
                                    if (isDeleteOldMail)
                                    {
                                        row.Status = "Đang xóa all mail cũ...";
                                        string getAllEmail = requestChangeEmail.GraphApi("&variables={\"interface\":\"FB_WEB\"}&doc_id=6147621405319737").Result;
                                        var AllEmail = Regex.Matches(getAllEmail, "EMAIL\",\"normalized_contact_point\":\"(.*?)\"");
                                        if (AllEmail.Count == 1)
                                        {
                                            row.Status = "Không có email nào cần xóa !!";
                                        }
                                        else
                                        {
                                            foreach (Match item in AllEmail)
                                            {
                                                string itemEmail = item.Groups[1].Value;
                                                string ResultEmail = itemEmail.Trim().Replace("\\u0040", "@");
                                                if (ResultEmail == pro.Email)
                                                {
                                                    continue;
                                                }
                                                string step1DeleteMail = requestChangeEmail.GraphApi("&variables={\"contact_point_type\":\"email\",\"interface\":\"FB_WEB\",\"normalized_contact_point\":\"" + ResultEmail + "\"}&doc_id=5534893423307136").Result;
                                                string step2DeleteMail = requestChangeEmail.GraphApi("&variables={\"input\":{\"account_id\":" + pro.UID + ",\"account_type\":\"Facebook\",\"password\":\"" + Newpassword + "\",\"actor_id\":\"" + pro.UID + "\",\"client_mutation_id\":\"1\"}}&doc_id=5864546173675027").Result;
                                                string step3DeleteMail = requestChangeEmail.GraphApi("&variables={\"normalized_contact_point\":\"" + ResultEmail + "\",\"contact_point_type\":\"EMAIL\",\"selected_accounts\":[\"" + pro.UID + "\"],\"client_mutation_id\":\"mutation_id_1687774231712\",\"family_device_id\":\"device_id_fetch_datr\"}&doc_id=6407508339305569").Result;
                                                string DeleteOldMail = requestChangeEmail.GraphApi("&variables={\"contact_point_event_type\":\"DELETE\",\"contact_point_type\":\"EMAIL\",\"interface\":\"FB_WEB\",\"normalized_contact_point\":\"kuchlertfn294405@hotmail.com\"}&doc_id=5788102017946779").Result;
                                            }
                                            row.Status = "Xóa mail cũ xong!";
                                            Task.Delay(1000).Wait();
                                        }
                                    }
                                    if (isDeletePhone)
                                    {
                                        row.Status = "Đang xóa all sđt...";
                                        string getAllPhone = requestChangeEmail.GraphApi("&variables={\"interface\":\"FB_WEB\"}&doc_id=6147621405319737").Result;
                                        var AllPhone = Regex.Matches(getAllPhone, "PHONE_NUMBER\",\"normalized_contact_point\":\"(.*?)\"");
                                        if (AllPhone.Count == 0)
                                        {
                                            row.Status = "Không có SĐT nào!!!";
                                        }
                                        else
                                        {
                                            foreach (Match item in AllPhone)
                                            {
                                                string itemPhone = item.Groups[1].Value;
                                                string delphone = requestChangeEmail.GraphApi("&variables={\"normalized_contact_point\":\"" + HttpUtility.UrlEncode(itemPhone) + "\",\"contact_point_type\":\"PHONE_NUMBER\",\"selected_accounts\":[\"" + pro.UID + "\"],\"client_mutation_id\":\"mutation_id_1687774231712\",\"family_device_id\":\"device_id_fetch_datr\"}&doc_id=6407508339305569").Result;
                                            }
                                            row.Status = "Xóa sđt xong!!!";
                                            Task.Delay(1000).Wait();
                                        }
                                    }
                                   if (string.IsNullOrEmpty(pro.SecrectKey))
                                    {
                                        row.Status = "Không có 2FA không thể get token";
                                        Task.Delay(1000).Wait();
                                    }
                                    else
                                    {
                                        row.Status = "Đang check Birthday";
                                        string getToken = requestChangeEmail.Get("https://business.facebook.com/billing_hub/payment_settings").Result;
                                        string token = Regex.Match(getToken, "\"EAAG(.*?)\"").Groups[1].Value;
                                        if(string.IsNullOrEmpty(token))
                                        {
                                            row.Status = "Get Token Thất bại!";
                                        }
                                        string resultToken = $"EAAG{token}";
                                        string getInfo = requestChangeEmail.Get($"https://graph.facebook.com/v17.0/me?fields=name%2Cbirthday&access_token={resultToken}").Result;
                                        pro.birthday = Regex.Match(getInfo.Replace("\r", "").Replace("\n", "").Replace("\"", ""), "birthday: (.*?),").Groups[1].Value;
                                        row.Status = "Đang get info ADS...";
                                        string checkXmdt = requestChangeEmail.GraphApi("&variables={\"assetOwnerId\":\""+pro.UID+"\"}&doc_id=6857420234315472").Result;
                                        string checkStatus = Regex.Match(checkXmdt, ",\"status\":\"(.*?)\"").Groups[1].Value;
                                        string checkTick = Regex.Match(checkXmdt, "restriction_type\":\"(.*?)\",").Groups[1].Value;
                                        if (checkStatus == "NOT_RESTRICTED")
                                        {
                                            row.HCQC = "Live ADS";
                                        }
                                        else if (checkStatus == "APPEAL_ACCEPTED")
                                        {
                                            if(checkTick == "PREHARM")
                                            {
                                                row.HCQC = "Live ADS - XMDT";
                                            }
                                            if(checkTick == "ALE")
                                            {
                                                row.HCQC = "Live ADS - 902";
                                            }
                                        }
                                        else if(checkStatus == "RISK_REVIEW_EMAIL_VERIFICATION")
                                        {
                                            row.HCQC = "HCQC - VERI MAIL";
                                        }
                                        else
                                        {
                                            row.HCQC = "HCQC";
                                        }
                                        string getInfoads = requestChangeEmail.Get($"https://graph.facebook.com/v17.0/me?fields=personal_ad_accounts%7Baccount_status%2Cadtrust_dsl%2Ccurrency%7D&access_token={resultToken}").Result;
                                        getInfoads = getInfoads.Replace("\r", "").Replace("\n", "").Replace(" ", "").Replace("\"", "");
                                        var allIDAds = Regex.Matches(getInfoads, "{account_status:(.*?),adtrust_dsl:(.*?),currency:(.*?),id:act_(.*?)}");
                                        int countAds = allIDAds.Count;
                                        string thongtinads = "";
                                        foreach ( Match ad in allIDAds)
                                        {
                                            string idAds = ad.Groups[4].Value;
                                            string limitAds = ad.Groups[2].Value;
                                            if(limitAds == "-1")
                                            {
                                                limitAds = "Nolimit";
                                            }
                                            string curren = ad.Groups[3].Value;
                                            thongtinads += idAds + "|" + limitAds + "|" + curren + ",";
                                        }
                                        row.IdAds = $"Có {countAds} TKQC : {thongtinads}";
                                    }
                                    row.Status = "Đang đăng xuất thiết bị...";
                                    string result = requestChangeEmail.GraphApi("&variables={\"session_count\":10}&doc_id=7231781343562346").Result;
                                    List<string> resultList = new List<string>();
                                    var listSessions = Regex.Matches(result, "sid\":\"(\\d+)\"");
                                    foreach (Match ssid in listSessions)
                                    {
                                        resultList.Add(ssid.Groups[1].Value);
                                    }
                                    string allsession = JsonConvert.SerializeObject(resultList);
                                    string logoutSession = requestChangeEmail.GraphApi("&variables={\"account_id\":\"" + pro.UID + "\",\"account_type\":\"FACEBOOK\",\"logout_all\":false,\"logout_run_id\":1689911804,\"session_ids\":" + allsession + ",\"client_mutation_id\":\"3d575d03-925c-4758-abb1-313c247358ef\"}&doc_id=5522376627785944").Result;
                                    row.Status = "Đăng xuất thiết bị thành công!!";
                                    Task.Delay(1000).Wait();
                                    RequestHTTP requestcheckcreate = new RequestHTTP();
                                    string getTime = requestcheckcreate.Post("https://www.facebook.com/api/graphql?q=node(" + pro.UID + "){created_time}", "").Result;
                                    int ngaytao = Regex.Match(getTime, "created_time\":(\\d+)").Groups[1].Value.ToInt(1);
                                    DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                                    dtDateTime = dtDateTime.AddSeconds(ngaytao).ToLocalTime();
                                    int day = dtDateTime.Day;
                                    int month = dtDateTime.Month;
                                    int year = dtDateTime.Year;
                                    pro.createDate = $"{day}-{month}-{year}";
                                    string checklive = requestChangeEmail.Get($"https://graph.facebook.com/{row.UID}?fields=picture").Result;
                                    if (checklive.Contains("error"))
                                    {
                                        row.Status = "Change xong - DIE!!!";
                                        pro.Status = "DIE";
                                    }
                                    else
                                    {
                                        string gohome = requestChangeEmail.Get("https://www.facebook.com/").Result;
                                        string cookienew = requestChangeEmail.GetCookie();
                                        pro.Cookie = cookienew;
                                        row.Status = "Change xong - LIVE!!!";
                                        pro.Status = "LIVE";
                                    }
                                }
                                catch
                                {
                                    row.Status = "Lỗi mạng";
                                    return;
                                }



                                #endregion
                            });
                            job.ListTarget = new List<string>();
                            for (int i = 0; i < soluong_1proxy; i++)
                            {
                                string tempuid = listUidChangemail.Dequeue();
                                if (string.IsNullOrEmpty(tempuid)) return;
                                job.ListTarget.Add(tempuid);
                            }
                            Task.Delay(delay * 1000).Wait();

                        }



                    });
                    taskQueue.Add(job);

                }
                taskQueue.WaitForShutDown();
                this.Dispatcher.Invoke(() =>
                {
                    MessageBox.Show("Thay Thông Tin Xong!");
                    btnStartChangebyIdpass.IsEnabled = true;
                    btnStopChange.IsEnabled = true;
                });
            }); tk.Start();
        }


        bool isStopChange = false;

        private void Click_btnStopChange(object sender, RoutedEventArgs e)
        {
            isStopChange = true;
            btnStopChange.IsEnabled = false;
        }

        private void checked_deleteoldmail(object sender, RoutedEventArgs e)
        {

        }

        private void unchecked_deleteoldmail(object sender, RoutedEventArgs e)
        {

        }

        private void chk_changepass(object sender, RoutedEventArgs e)
        {
            txt_newpassChangemail.IsEnabled = true;
            tgbtn_randomPass.IsEnabled = true;
        }

        private void Unchk_changepass(object sender, RoutedEventArgs e)
        {
            txt_newpassChangemail.IsEnabled = false;
            tgbtn_randomPass.IsEnabled = false;
        }

        private void Click_btnStartXMDTverimail(object sender, RoutedEventArgs e)
        {
            MyQueue<string> listUidChangemail = new MyQueue<string>(txt_listUidChangemail.Text.GetAllLines());
            List<string> listHttps = txt_listProxyChangemail.Text.GetAllLines();
            //MyQueue<string> listHttps = new MyQueue<string>(txt_listProxyChangemail.Text.GetAllLines());
            Random random = new Random();
            string typelogin = cb_loginChangeidpass.Text;
            List<string> newapiproxy = txt_listProxyChangemail.Text.GetAllLines();
            string cbwebproxy = cb_webproxyChangemail.Text;
            int soluong = txt_soluongChangemail.Text.ToInt(1);
            int delay = txt_delayChangemail.Text.ToInt(7);
            if (newapiproxy.Count == 0)
            {
                for (int i = 0; i < soluong; i++)
                {
                    newapiproxy.Add("NoProxy");
                }
            }
            int soProxy = newapiproxy.Count;
            if (cbwebproxy == "HTTPS")
            {
                if (soluong < soProxy)
                {
                    soProxy = soluong;
                }
            }
            btnStartXMDTverimail.IsEnabled = false; // khi start, nút start sẽ bị đen
            isStopChange = false;
            DataChangeAccount = new ObservableCollection<GridRow>();
            Task tk = new Task(() =>
            {
                int soluong_1proxy = soluong / soProxy;
                TaskQueue<JobQueue> taskQueue = new TaskQueue<JobQueue>();
                taskQueue.RunRandom = false;//true: ngẫu nhiên trong hàng chờ, không theo thứ tự trước sau.
                taskQueue.UseAsyncContext = false;//true: use Nito AsyncContext
                taskQueue.TaskScheduler = TaskScheduler.Default;
                taskQueue.MaxRun = soluong;//số lượng luồng tối đa
                taskQueue.RunAsParty = true;//true: chạy theo nhóm, tức 5 cái xong mới bắt đầu chạy 5 cái kế.
                foreach (string proxy1 in newapiproxy)
                {
                    JobQueue job = new JobQueue(proxy1);
                    job.ListTarget = new List<string>();
                    for (int i = 0; i < soluong_1proxy; i++)
                    {
                        string tempuid = listUidChangemail.Dequeue();
                        if (string.IsNullOrEmpty(tempuid)) break;
                        job.ListTarget.Add(tempuid);
                    }
                    job.Work = new Task(() =>
                    {

                        while (true)
                        {
                            string proxy = "";
                            if (!job.JobData.Equals("NoProxy"))
                            {
                                string keyapi = newapiproxy.GetRandom();
                                WebProxyApi webproxy = new WebProxyApi(keyapi);
                                RequestHTTP req = new RequestHTTP();
                                string myip = req.Get("https://api.ipify.org/").Result;
                                //code xử lý 1 luồng
                                switch (cbwebproxy)
                                {
                                    case "Không Đổi IP":
                                        RequestHTTP getIp = new RequestHTTP();
                                        string GetIp = getIp.Get("https://whoer.net/fr").Result;
                                        proxy = Regex.Match(GetIp, "ip: \"(.*?)\", iso").Groups[1].Value;
                                        break;
                                    case "TinsoftProxy.Com":
                                        string checkipTinsoft = webproxy.CheckProxyTinsoft();
                                        if (string.IsNullOrEmpty(checkipTinsoft))
                                        {
                                            proxy = webproxy.GetNewProxyTinsoft();
                                        }
                                        else
                                        {
                                            int checktime = webproxy.CheckTimeTinsoft();
                                            if (checktime > 0)
                                            {
                                                proxy = checkipTinsoft;
                                            }
                                            else
                                            {
                                                proxy = webproxy.GetNewProxyTinsoft();
                                            }
                                        }
                                        break;
                                    case "proxy.shoplike.vn":
                                        proxy = webproxy.GetNewProxyShoplike();
                                        break;
                                    case "proxyv6.net":
                                        webproxy.MyIP = myip;
                                        proxy = webproxy.getProxyv6net();
                                        break;
                                }
                            }
                            Parallel.For(0, soluong_1proxy, i =>
                            {
                                #region 1 LUỒNG CON

                                GridRow row = new GridRow();
                                try
                                {
                                    if (isStopChange == true)
                                    {
                                        return;
                                    }
                                    //code 1 luồng con ở trong này
                                    if (i >= job.ListTarget.Count) { return; }
                                    Profile pro = MainDataGrid.Find(x1 => job.ListTarget[i].Equals(x1.UID));
                                    if (pro == null || pro == default)
                                    {
                                        //xu ly khi k tim thay profile
                                        return;
                                    }
                                    pro.ProxyUrl = proxy;
                                    row.IP = proxy;
                                    this.Dispatcher.Invoke(() =>
                                    {
                                        row.ID = DataChangeAccount.Count + 1;
                                        row.UID = pro.UID;
                                        row.Status = "Bắt đầu Thay XMDT...";
                                        DataChangeAccount.Add(row);
                                    });
                                    if (typelogin == "Id|Pass|2fa")
                                    {
                                        #region CODE LOGIN = 2FA RỒI GET COOKIE
                                        RequestHTTP requestlogin = new RequestHTTP("", ProxyUrl: proxy);
                                        requestlogin.LoginFacebookGetToken(pro, row);
                                        if (row.Status == "CP 282!")
                                        {
                                            return;
                                        }
                                        if (row.Status == "CP 956!")
                                        {
                                            return;
                                        }
                                        if (row.Status == "Sai pass")
                                        {
                                            return;
                                        }
                                        if (row.Status == "Lỗi mạng")
                                        {
                                            return;
                                        }
                                        if (row.Status == "Sai 2FA")
                                        {
                                            return;
                                        }
                                        if (row.Status == "ERROR COOKIE!")
                                        {
                                            return;
                                        }
                                        return;
                                        #endregion
                                    }
                                    RequestHTTP requestChangeEmail = new RequestHTTP(cookies: pro.Cookie, ProxyUrl: proxy);
                                    row.Status = "Đang check xem có phải XMDT Email không...";
                                    string checkXmdt = requestChangeEmail.GraphApi("&variables={\"assetOwnerId\":\"" + pro.UID + "\"}&doc_id=6857420234315472").Result;
                                    string checkStatus = Regex.Match(checkXmdt, "restriction_type\":\"(.*?)\"").Groups[1].Value;
                                    if (checkStatus != "RISK_REVIEW_EMAIL_VERIFICATION")
                                    {
                                        row.Status = "Không phải dạng veri mail";
                                        return;
                                    }
                                    row.Status = "XMDT Email , bắt đầu XMDT...";
                                    string randomSession = Guid.NewGuid().ToString();
                                    string clickStart = requestChangeEmail.GraphApi("&variables={\"input\":{\"challenge_scenario\":\"MAIN_FEV_WIZARD\",\"business_verification_design_system\":\"GEODESIC\",\"email_domain\":\"\",\"email_user\":\"\",\"fev_wizard_product\":\"STANDALONE_EMAIL_VERIFICATION\",\"hide_initial_back_button\":true,\"location\":\"BUSINESS_VERIFICATION_WIZARD_INTERNAL_TOOL\",\"business_verification_ui_type\":\"ACCOUNT_QUALITY\",\"authenticatable_entity_id\":\""+pro.UID+"\",\"page_id\":\""+pro.UID+"\",\"trigger_event_type\":\"DIRECT_OPEN_ADVERTISER_AUTHENTICITY_EMAIL_CONFIRM\",\"website\":\"\",\"bap_product\":\"BU_COMPROMISE\",\"nt_context\":null,\"trigger_session_id\":\""+randomSession+"\"},\"scale\":1}&doc_id=6698265226896951").Result;
                                    string emailCheck = pro.Email.Replace("@", "\\u0040");
                                    if(!clickStart.Contains(emailCheck))
                                    {
                                        row.Status = "Xác minh email không có trong tool";
                                        return;
                                    }
                                    string serialized_state = Regex.Match(clickStart, "serialized_state\":\"(.*?)\"").Groups[1].Value;
                                    if(string.IsNullOrEmpty(serialized_state))
                                    {
                                        row.Status = "Bấm bắt đầu XMDT thất bại";
                                        return;
                                    }
                                    row.Status = $"Gửi code về email {pro.Email}";
                                    string clickSendemail = requestChangeEmail.GraphApi("&variables={\"input\":{\"advertiser_authenticity_email_challenge\":{\"email_address\":\""+pro.Email+"\",\"org_id\":\""+pro.UID+"\",\"serialized_state\":\""+serialized_state+"\",\"website\":\"\"},\"actor_id\":\""+pro.UID+"\",\"client_mutation_id\":\"1\"},\"scale\":1}&doc_id=6557544844299820").Result;
                                    string serialized_state1 = Regex.Match(clickSendemail, "serialized_state\":\"(.*?)\"").Groups[1].Value;
                                    if (string.IsNullOrEmpty(serialized_state1))
                                    {
                                        row.Status = "Bấm gửi code về mail thất bại";
                                        return;
                                    }
                                    string codeemail = "";

                                    #region LẤY CODE VERIMAIL HOTMAIL/OUTLOOK
                                    int demcheck = 0;
                                    int port = 993;
                                    string host = "outlook.office365.com";
                                    try
                                    {
                                        using (var client = new ImapClient())
                                        {
                                            client.SslProtocols = SslProtocols.Ssl3 | SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
                                            client.Connect(host, port, SecureSocketOptions.SslOnConnect);
                                            client.AuthenticationMechanisms.Remove("XOAUTH2");
                                            client.Authenticate(pro.Email, pro.PassEmail);
                                            Task.Delay(1000).Wait();
                                            MimeMessage mess = new MimeMessage() { Date = DateTime.Now };
                                            do
                                            {
                                                client.Inbox.Open(FolderAccess.ReadOnly);
                                                var messengeUIDs = client.Inbox.Search(SearchQuery.FromContains("facebook")).ToList();
                                                int countmess = messengeUIDs.Count - 1;
                                                while (messengeUIDs.Count > 0 && countmess >= 0)
                                                {
                                                    mess = client.Inbox.GetMessage(messengeUIDs[countmess]);
                                                    if (DateTime.UtcNow - mess.Date.UtcDateTime > TimeSpan.FromSeconds(60))
                                                    {
                                                        countmess--;
                                                        continue;
                                                    }
                                                    string textinput = mess.HtmlBody;
                                                    if (string.IsNullOrEmpty(textinput)) textinput = mess.TextBody;
                                                    codeemail = Regex.Match(textinput, "<br>(.*?): (\\d+)</div>").Groups[2].Value;
                                                    if (string.IsNullOrEmpty(codeemail))
                                                    {
                                                        countmess--;
                                                        continue;
                                                    }
                                                    if (!string.IsNullOrEmpty(codeemail)) break;
                                                }
                                                demcheck++;
                                                Task.Delay(3000).Wait();
                                            } while (string.IsNullOrEmpty(codeemail) && demcheck < 10);
                                            client.Disconnect(true);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        row.Status = "Email lỗi";
                                        return;
                                    }
                                    #endregion
                                    row.Status = $"Lấy code thành công {codeemail}, bấm xác minh...";
                                    string clickSendcode = requestChangeEmail.GraphApi("&variables={\"input\":{\"advertiser_authenticity_enter_email_code\":{\"check_id\":null,\"code\":\""+ codeemail + "\",\"serialized_state\":\""+serialized_state1+"\"},\"actor_id\":\""+pro.UID+"\",\"client_mutation_id\":\"4\"},\"scale\":1}&doc_id=6557544844299820").Result;
                                    row.Status = "XMDT EMAIL XONG";
                                }
                                catch
                                {
                                    row.Status = "Lỗi mạng";
                                    return;
                                }



                                #endregion
                            });
                            job.ListTarget = new List<string>();
                            for (int i = 0; i < soluong_1proxy; i++)
                            {
                                string tempuid = listUidChangemail.Dequeue();
                                if (string.IsNullOrEmpty(tempuid)) return;
                                job.ListTarget.Add(tempuid);
                            }
                            Task.Delay(delay * 1000).Wait();

                        }



                    });
                    taskQueue.Add(job);

                }
                taskQueue.WaitForShutDown();
                this.Dispatcher.Invoke(() =>
                {
                    MessageBox.Show("XMDT XONG!");
                    btnStartXMDTverimail.IsEnabled = true;
                    btnStopChange.IsEnabled = true;
                });
            }); tk.Start();
        }

        private void Click_btnStartOutAllTkqc(object sender, RoutedEventArgs e)
        {
            MyQueue<string> listUidChangemail = new MyQueue<string>(txt_listUidChangemail.Text.GetAllLines());
            List<string> listHttps = txt_listProxyChangemail.Text.GetAllLines();
            //MyQueue<string> listHttps = new MyQueue<string>(txt_listProxyChangemail.Text.GetAllLines());
            Random random = new Random();
            string typelogin = cb_loginChangeidpass.Text;
            List<string> newapiproxy = txt_listProxyChangemail.Text.GetAllLines();
            string cbwebproxy = cb_webproxyChangemail.Text;
            int soluong = txt_soluongChangemail.Text.ToInt(1);
            int delay = txt_delayChangemail.Text.ToInt(7);
            if (newapiproxy.Count == 0)
            {
                for (int i = 0; i < soluong; i++)
                {
                    newapiproxy.Add("NoProxy");
                }
            }
            int soProxy = newapiproxy.Count;
            if (cbwebproxy == "HTTPS")
            {
                if (soluong < soProxy)
                {
                    soProxy = soluong;
                }
            }
            btnStartOutAllTkqc.IsEnabled = false; // khi start, nút start sẽ bị đen
            isStopChange = false;
            DataChangeAccount = new ObservableCollection<GridRow>();
            Task tk = new Task(() =>
            {
                int soluong_1proxy = soluong / soProxy;
                TaskQueue<JobQueue> taskQueue = new TaskQueue<JobQueue>();
                taskQueue.RunRandom = false;//true: ngẫu nhiên trong hàng chờ, không theo thứ tự trước sau.
                taskQueue.UseAsyncContext = false;//true: use Nito AsyncContext
                taskQueue.TaskScheduler = TaskScheduler.Default;
                taskQueue.MaxRun = soluong;//số lượng luồng tối đa
                taskQueue.RunAsParty = true;//true: chạy theo nhóm, tức 5 cái xong mới bắt đầu chạy 5 cái kế.
                foreach (string proxy1 in newapiproxy)
                {
                    JobQueue job = new JobQueue(proxy1);
                    job.ListTarget = new List<string>();
                    for (int i = 0; i < soluong_1proxy; i++)
                    {
                        string tempuid = listUidChangemail.Dequeue();
                        if (string.IsNullOrEmpty(tempuid)) break;
                        job.ListTarget.Add(tempuid);
                    }
                    job.Work = new Task(() =>
                    {

                        while (true)
                        {
                            string proxy = "";
                            if (!job.JobData.Equals("NoProxy"))
                            {
                                string keyapi = newapiproxy.GetRandom();
                                WebProxyApi webproxy = new WebProxyApi(keyapi);
                                RequestHTTP req = new RequestHTTP();
                                string myip = req.Get("https://api.ipify.org/").Result;
                                //code xử lý 1 luồng
                                switch (cbwebproxy)
                                {
                                    case "Không Đổi IP":
                                        RequestHTTP getIp = new RequestHTTP();
                                        string GetIp = getIp.Get("https://whoer.net/fr").Result;
                                        proxy = Regex.Match(GetIp, "ip: \"(.*?)\", iso").Groups[1].Value;
                                        break;
                                    case "TinsoftProxy.Com":
                                        string checkipTinsoft = webproxy.CheckProxyTinsoft();
                                        if (string.IsNullOrEmpty(checkipTinsoft))
                                        {
                                            proxy = webproxy.GetNewProxyTinsoft();
                                        }
                                        else
                                        {
                                            int checktime = webproxy.CheckTimeTinsoft();
                                            if (checktime > 0)
                                            {
                                                proxy = checkipTinsoft;
                                            }
                                            else
                                            {
                                                proxy = webproxy.GetNewProxyTinsoft();
                                            }
                                        }
                                        break;
                                    case "proxy.shoplike.vn":
                                        proxy = webproxy.GetNewProxyShoplike();
                                        break;
                                    case "proxyv6.net":
                                        webproxy.MyIP = myip;
                                        proxy = webproxy.getProxyv6net();
                                        break;
                                }
                            }
                            Parallel.For(0, soluong_1proxy, i =>
                            {
                                #region 1 LUỒNG CON

                                GridRow row = new GridRow();
                                try
                                {
                                    if (isStopChange == true)
                                    {
                                        return;
                                    }
                                    //code 1 luồng con ở trong này
                                    if (i >= job.ListTarget.Count) { return; }
                                    Profile pro = MainDataGrid.Find(x1 => job.ListTarget[i].Equals(x1.UID));
                                    if (pro == null || pro == default)
                                    {
                                        //xu ly khi k tim thay profile
                                        return;
                                    }
                                    pro.ProxyUrl = proxy;
                                    row.IP = proxy;
                                    this.Dispatcher.Invoke(() =>
                                    {
                                        row.ID = DataChangeAccount.Count + 1;
                                        row.UID = pro.UID;
                                        row.Status = "Bắt đầu Out TKQC...";
                                        DataChangeAccount.Add(row);
                                    });
                                    if (typelogin == "Id|Pass|2fa")
                                    {
                                        #region CODE LOGIN = 2FA RỒI GET COOKIE
                                        RequestHTTP requestlogin = new RequestHTTP("", ProxyUrl: proxy);
                                        requestlogin.LoginFacebookGetToken(pro, row);
                                        if (row.Status == "CP 282!")
                                        {
                                            return;
                                        }
                                        if (row.Status == "CP 956!")
                                        {
                                            return;
                                        }
                                        if (row.Status == "Sai pass")
                                        {
                                            return;
                                        }
                                        if (row.Status == "Lỗi mạng")
                                        {
                                            return;
                                        }
                                        if (row.Status == "Sai 2FA")
                                        {
                                            return;
                                        }
                                        if (row.Status == "ERROR COOKIE!")
                                        {
                                            return;
                                        }
                                        return;
                                        #endregion
                                    }
                                    RequestHTTP requestChangeEmail = new RequestHTTP(cookies: pro.Cookie, ProxyUrl: proxy);
                                    string getToken = requestChangeEmail.Get("https://business.facebook.com/billing_hub/payment_settings").Result;
                                    string token = Regex.Match(getToken, "\"EAAG(.*?)\"").Groups[1].Value;
                                    if (string.IsNullOrEmpty(token))
                                    {
                                        row.Status = "Get Token Thất bại!";
                                        return;
                                    }
                                    string resultToken = $"EAAG{token}";
                                    string getInfoads = requestChangeEmail.Get($"https://graph.facebook.com/v17.0/me?fields=personal_ad_accounts.limit(1000)%7Badtrust_dsl%2Caccount_status%2Ccurrency%2Caccount_id%2Cowner%7D&access_token={resultToken}").Result;
                                    getInfoads = getInfoads.Replace("\r", "").Replace("\n", "").Replace(" ", "").Replace("\"", "");
                                    var infoAds = Regex.Matches(getInfoads, "adtrust_dsl:(.*?),account_status:(.*?),currency:(.*?),account_id:(.*?),owner:(.*?),");
                                    int sotkqc = infoAds.Count;
                                    if(sotkqc == 1 )
                                    {
                                        row.Status = "Không có TKQC nào khác!";
                                        return;
                                    }
                                    foreach(Match match in infoAds)
                                    {
                                        string idAds = match.Groups[4].Value;
                                        string UIDowner = match.Groups[5].Value;
                                        if (string.IsNullOrEmpty(idAds))
                                        {
                                            row.Status = "Không get được TKQC!";
                                            return;
                                        }
                                        if(UIDowner == pro.UID)
                                        {
                                            continue;
                                        }
                                        requestChangeEmail.Get("https://business.facebook.com/ads/manager/account_settings/information/");
                                        string outTkqc = requestChangeEmail.OutAllTKQC(idAds).Result;
                                    }
                                    row.Status = "OUT XONG ALL TKQC";
                                }
                                catch
                                {
                                    row.Status = "Lỗi mạng";
                                    return;
                                }
                                #endregion
                            });
                            job.ListTarget = new List<string>();
                            for (int i = 0; i < soluong_1proxy; i++)
                            {
                                string tempuid = listUidChangemail.Dequeue();
                                if (string.IsNullOrEmpty(tempuid)) return;
                                job.ListTarget.Add(tempuid);
                            }
                            Task.Delay(delay * 1000).Wait();

                        }



                    });
                    taskQueue.Add(job);

                }
                taskQueue.WaitForShutDown();
                this.Dispatcher.Invoke(() =>
                {
                    MessageBox.Show("OUT XONG!");
                    btnStartOutAllTkqc.IsEnabled = true;
                    btnStopChange.IsEnabled = true;
                });
            }); tk.Start();
        }
    }
}