async private void UpdateClients() { if (!socket.Connected) { return; } string str = await socket.SendCommand("GetConfig"); logText.Text = str.Replace("\n", "\r\n"); if (str.Contains("Connected 1\n")) { // Connected messageLabel.Text = "Connected!\r\nPlease enjoy!"; messagePanel.Show(); findingPanel.Hide(); return; } messagePanel.Hide(); findingPanel.Show(); str = await socket.SendCommand("GetRequests"); foreach (var row in dataGridView1.Rows.Cast <DataGridViewRow>()) { // Mark as old data row.Tag = 0; } foreach (var s in str.Split('\n')) { if (s == "") { continue; } var elem = s.Split(" ".ToCharArray(), 2); bool found = false; foreach (var row in dataGridView1.Rows.Cast <DataGridViewRow>()) { if ((string)row.Cells[1].Value == elem[0]) { found = true; row.Cells[0].Value = elem[1]; // Mark as new data row.Tag = 1; } } if (!found) { int index = dataGridView1.Rows.Add(new string[] { elem[1], elem[0], "Connect" }); dataGridView1.Rows[index].Tag = 1; } } for (int j = dataGridView1.Rows.Count - 1; j >= 0; j--) { // Remove old row if ((int)dataGridView1.Rows[j].Tag == 0) { dataGridView1.Rows.RemoveAt(j); } } noClientLabel.Visible = dataGridView1.Rows.Count == 0; }
async private void UpdateClientStatistics() { string str = await socket.SendCommand("GetStat"); int i = 0; foreach (var line in str.Split("\n".ToCharArray())) { var elem = line.Split(" ".ToCharArray(), 2); if (elem.Length != 2) { continue; } if (statDataGridView.Rows.Count <= i) { statDataGridView.Rows.Add(new string[] { }); } statDataGridView.Rows[i].Cells[0].Value = elem[0]; statDataGridView.Rows[i].Cells[1].Value = elem[1]; i++; } }
async public Task <bool> Connect(ControlSocket socket, Client client) { var ret = await socket.SendCommand("Connect " + client.Address); return(ret == "OK"); }