private void NCAutorizeNewClient(IConnector connector, ArgComAutorize arg) { if (arg == null || connector == null) { return; } ATCPConnector atcpcon = connector as ATCPConnector; if (atcpcon == null) { return; } if (!string.IsNullOrEmpty(arg.Login) && arg.Password == "Password") { _autorizator.RemoveConnector(connector.UniqueID); ArgUniqueID argClientID = new ArgUniqueID(NComSendClientID.uniqueID); argClientID.UniqueID = Uid64.CreateNewSync().Data; TeamPainterTCPClient client = new TeamPainterTCPClient(atcpcon, argClientID.UniqueID, arg.Login); bool added = _worker.AddClient(client); if (!added) { client.Disconnect(); return; } lvClients.Invoke((MethodInvoker) delegate { ListViewItem lvi = lvClients.Items[client.Connector.UniqueID.ToString()]; if (lvi != null) { lvi.Name = client.UniqueID.ToString(); lvi.SubItems[0].Text = client.UniqueID.ToString(); lvi.SubItems[1].Text = arg.Login; lvi.BackColor = Color.WhiteSmoke; lvi.ForeColor = Color.Black; lvClients.Invalidate(); } }); connector.SendCommand(argClientID); } }
private void miDisconnect_Click(object sender, EventArgs e) { ListViewItem lvi = null; lvClients.Invoke((MethodInvoker) delegate { if (lvClients.SelectedItems != null) { if (lvClients.SelectedItems != null && lvClients.SelectedItems.Count > 0) { lvi = lvClients.SelectedItems[0]; } } }); if (lvi == null) { return; } long id = 0; long.TryParse(lvi.Name, out id); if (id != 0) { string s = lvi.SubItems[1].Text; if (s == "No autorized") { IConnector con = _autorizator.GetConnector(id); if (con != null) { con.Disconnect(); } } else { TeamPainterTCPClient client = _worker.GetClient(id); if (client != null) { client.Disconnect(); } } } }