private void LoadFileSshToLookUpEdit(LookUpEdit le)
        {
            var sshFiles = StaticSsh.LoadFileSshFromFolder();

            le.Properties.DataSource = sshFiles;
            le.EditValue             = sshFiles[index];
        }
        private void LoadSshToGridControl(string sshName)
        {
            var listSsh = StaticSsh.LoadListSshFromFile(sshName);

            gridControl1.DataSource = listSsh;
            gridControl1.RefreshDataSource();
            gridView1.Columns["Id"].Visible = false;
        }
        private void leProxy_EditValueChanged(object sender, EventArgs e)
        {
            var ListSshFromFile = StaticSsh.LoadListSshFromFile(leProxy.EditValue.ToString());

            teProxyCount.Text = ListSshFromFile.Count.ToString();

            listSsh = new List <SshDetail>();
            listSsh = ListSshFromFile;
        }
        public void LoadDefaultSettings()
        {
            StaticSaveOptions.CreatFolderIfNotExist();
            StaticSaveOptions.CreatFileSaveIfNotExist();
            var sshFiles = StaticSsh.LoadFileSshFromFolder();

            leProxy.Properties.DataSource = sshFiles;
            leProxy.EditValue             = sshFiles[0];
            var countListSshFromFile = StaticSsh.LoadListSshFromFile(leProxy.EditValue.ToString()).Count;

            teProxyCount.Text = countListSshFromFile.ToString();
        }
        private ConcurrentBag <SshDetail> RenewSsh(string countrySelected)
        {
            var _sshes   = new ConcurrentBag <SshDetail>();
            var sshItems = StaticSsh.LoadListSshFromFile(countrySelected);

            sshItems = sshItems.OrderBy(s => Guid.NewGuid()).Take(sshItems.Count).ToList();
            foreach (var item in sshItems)
            {
                _sshes.Add(item);
            }

            return(_sshes);
        }
        private void sbSave_Click(object sender, EventArgs e)
        {
            if (teNewSshFile.Text == string.Empty)
            {
                XtraMessageBox.Show("Name must have value.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var isCreateSuccess = StaticSsh.CreatNewFileSsh(teNewSshFile.Text);

            if (isCreateSuccess == false)
            {
                XtraMessageBox.Show("Creat Failed. Try again.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            LoadFileSshToLookUpEdit(leSshFiles);
            lblTotalSsh.Text = $"Total : {(gridControl1.DataSource as List<SshDetail>).Count} SSH";
            flyoutPanel1.HideBeakForm(false);
        }
        private void lblDeleteFileSsh_Click(object sender, EventArgs e)
        {
            var deleteConfirm = XtraMessageBox.Show($"Delete File '{leLoadSshFile.EditValue.ToString()}' ?", "Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (deleteConfirm == DialogResult.Cancel)
            {
                return;
            }
            var isDeletedSuccess = StaticSsh.DeleteFileSsh(leLoadSshFile.EditValue.ToString());

            if (isDeletedSuccess == false)
            {
                XtraMessageBox.Show("Delete Failed. Try Again", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            LoadFileSshToLookUpEdit(leLoadSshFile);
            LoadFileSshToLookUpEdit(leSshFiles);
        }
        private void sbRemoveSsh_Click(object sender, EventArgs e)
        {
            var countrySelected = leSshFiles.EditValue.ToString();
            var selectedItems   = gridView1.GetSelectedItems <SshDetail>()?.ToList();
            var listSsh         = gridControl1.DataSource as List <SshDetail>;
            var remoConfirm     = XtraMessageBox.Show($"Delete {selectedItems.Count} SSH ?", "Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (remoConfirm == DialogResult.Cancel)
            {
                return;
            }
            foreach (var item in selectedItems)
            {
                listSsh.Remove(item);
            }
            StaticSsh.SaveSshToFile(countrySelected, listSsh);
            LoadSshToGridControl(countrySelected);
            lblTotalSsh.Text = $"Total : {(gridControl1.DataSource as List<SshDetail>).Count} SSH";
        }
        private void sbLoadSsh_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.Filter = "SSH File|*.txt";
            ofd.Title  = "SSH File";
            if (ofd.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            var files = File.ReadAllLines(ofd.FileName);

            if (files.Length == 0)
            {
                return;
            }
            var listSsh = new List <SshDetail>();

            foreach (var item in files)
            {
                var ssh   = new SshDetail();
                var split = item.Split('|');
                if (split.Length < 3)
                {
                    continue;
                }
                ssh.Host = split[0];
                ssh.User = split[1];
                ssh.Pass = split[2];
                listSsh.Add(ssh);
            }
            var sshListInGridControl = gridControl1.DataSource as List <SshDetail>;

            foreach (var item in sshListInGridControl)
            {
                listSsh.Add(item);
            }
            StaticSsh.SaveSshToFile(leSshFiles.Text, listSsh);
            LoadSshToGridControl(leSshFiles.Text);
            lblTotalSsh.Text = $"Total : {(gridControl1.DataSource as List<SshDetail>).Count} SSH";
        }
        public async Task CheckBalanceAsyn(InfoRequired info)
        {
            StaticHomeModule.KillProcessByName("BvSsh");
            _taskManagers.Clear();
            cancelSources.Clear();

            AddTaskManager(info);
            var keyBag    = new ConcurrentBag <BtcKeys>(info.keys);
            var sshBag    = RenewSsh(info.SshFileSelected);
            var temKeyBag = keyBag.Count;

            temSshCount = StaticSsh.LoadListSshFromFile(info.SshFileSelected).Count;

            listKeyHaveMoney = new List <WithBalanceToSave>();
            listEmptyBalance = new List <EmptyBalanceToSave>();
            listErrorKey     = new List <ErrorKeyToSave>();
            await Task.Run(async() =>
            {
                int taskCancel = 0;
                var tasks      = new List <Task>();
                for (int i = 1; i <= info.Thread; i++)
                {
                    var _cancelSource = new CancellationTokenSource();
                    int taskId        = i;
                    Thread.Sleep(20);
                    var t = Task.Run(() =>
                    {
                        var temTask = taskId;
                        var manager = GetTaskManager(taskId);
                        try
                        {
                            manager.ChangeIp(sshBag);
                            OnProxyUsed(new ProxyUsedEventArg()
                            {
                                ProxyUsed = temSshCount - sshBag.Count,
                            });
                            while (!keyBag.IsEmpty) // >>>>>>>>>>
                            {
                                _cancelSource.Token.ThrowIfCancellationRequested();

                                OnKeyQueue(new KeyQueueEventArgs()
                                {
                                    KeyQueue = keyBag.Count,
                                });
                                OnKeyChecked(new KeyCheckedEventArgs()
                                {
                                    KeyChecked = temKeyBag - keyBag.Count,
                                });
                                if (keyBag.TryTake(out BtcKeys key))
                                {
                                    lock (o) { GetKeybalanceInfo(key, manager, sshBag, temSshCount); }
                                }
                            }
                        }
                        catch (OperationCanceledException)
                        {
                            taskCancel++;
                            OnTaskStop(new TaskStopEventArg()
                            {
                                ThreadNumber = taskCancel,
                                StopReason   = $"Stop Thread: "
                            });
                        }
                    }, _cancelSource.Token);
                    cancelSources.Add(_cancelSource);
                    tasks.Add(t);
                }
                await Task.WhenAll(tasks);
                if (taskCancel == info.Thread)
                {
                    return;
                }
                tasks.Clear();
                cancelSources.Clear();
            });
        }
 private void leSshFiles_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
 {
     index = StaticSsh.GetIndexOfSshFile(e.NewValue.ToString());
     LoadSshToGridControl(e.NewValue.ToString());
     lblTotalSsh.Text = $"Total : {(gridControl1.DataSource as List<SshDetail>).Count} SSH";
 }