private void StartListening() { server.Start(); UpdateGUI.UpdateControl(txtStatus, "Text", "Прослушивание подключений..."); while (!stop) { if (server != null) { if (server.Pending()) { TcpClient client = server.AcceptTcpClient(); var clientIp = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString(); connectionId++; AddConnection(clientIp, client); UpdateGUI.UpdateControl(txtStatus, "Text", $"Новое подключение: {clientIp}."); } else { ListenMessages(); } } } }
private void btnStarter_Click(object sender, EventArgs e) { if (btnStarter.Text.StartsWith("Запустить")) { if (Int32.TryParse(txtPort.Text, out port)) { if (server == null) { stop = false; server = new TcpListener(IPAddress.Any, port); Listening = new Thread(StartListening); Listening.Start(); UpdateGUI.UpdateControl(btnStarter, "Text", "Остановить прослушивание"); UpdateGUI.UpdateControl(txtStatus, "Text", "Прослушивание подключений..."); } } else { MessageBox.Show("Порт введен некорректно."); } } else { StopListening(); UpdateGUI.UpdateControl(btnStarter, "Text", "Запустить прослушивание"); UpdateGUI.UpdateControl(txtStatus, "Text", "Прослушивание остановлено."); } }
private void StopTranslationButton_Click(object sender, EventArgs e) { Button btn = (Button)sender; var btnId = ParseControlId(btn.Name, "btnStopView"); if (btnId > 0) { var ip = connectionsDictionary.Where(c => c.Value.ConnectionId == btnId).FirstOrDefault().Value.ClientIP; var connection = connectionsDictionary[ip]; connection.State = Utils.Models.ConnectionState.Off; try { connection.RdpViewer.Disconnect(); } catch { } connection.TabPage.Controls.OfType <Button>().ToList()[0].Enabled = true; connection.TabPage.Controls.OfType <Button>().ToList()[2].Enabled = false; btn.Enabled = false; UpdateGUI.UpdateControl(txtStatus, "Text", "Трансляция остановлена."); } }
private void DeleteConnection(string ip, bool disconnectRequest) { var connection = connectionsDictionary[ip]; if (disconnectRequest) { connection.MessageBroker.SendMessage(new DisconnectServerCommand(true)); } if (connection.RdpViewer != null) { connection.RdpViewer.Disconnect(); } DeleteTabPage($"tabPage{connection.ConnectionId}"); connectionsDictionary.Remove(ip); UntieDisplayToConnection(connection); var item = checkedListBox1.Items.IndexOf($"{connection.ClientIP}"); this.Invoke(new Action(() => { checkedListBox1.Items.RemoveAt(item); })); UpdateGUI.UpdateControl(txtStatus, "Text", $"Клиент {ip} отключен."); }
private void ExecuteProhibit(Connection connection, ICommand cmd) { bool prohibit = (bool)cmd.GetData()[0]; connection.ProhibitDemo = prohibit; connection.State = Utils.Models.ConnectionState.Demonstration; try { connection.RdpViewer.RequestControl(CTRL_LEVEL.CTRL_LEVEL_VIEW); } catch { } var btns = connection.TabPage.Controls.OfType <Button>().ToList(); if (prohibit == true) { UpdateGUI.UpdateControl(btns[2], "Enabled", false); UpdateGUI.UpdateControl(btns[3], "Enabled", false); } else { UpdateGUI.UpdateControl(btns[2], "Enabled", true); } }
private void btnConnect_Click(object sender, EventArgs e) { if (btnConnect.Text.StartsWith("Подключиться")) { if (firstRun) { firstRun = false; } try { if (!_client.Settings.IsEmpty()) { if (checkedListBox1.CheckedItems.Count > 0) { _client.ConnectTcp(); _client.CreateSession(desktopOption, chosenApp); _client.CreateConnectionString(); _client.SendConnectionCommand(); txtConnectionString.Text = _client.ConnectionString; UpdateGUI.UpdateControl(btnMsgSend, "Enabled", true); UpdateGUI.UpdateControl(btnSendFile, "Enabled", true); UpdateGUI.UpdateControl(btnPause, "Enabled", true); UpdateGUI.UpdateControl(btnResume, "Enabled", true); _client.MessageListener.Start(); UpdateGUI.UpdateControl(txtStatus, "Text", "Подключение к серверу выполнено успешно."); UpdateGUI.UpdateControl(btnConnect, "Text", "Отключиться от сервера"); } else { MessageBox.Show("Опция демонстрации не выбрана.\n"); } } else { MessageBox.Show("Настройки подключения не заданы!\n"); } } catch (Exception ex) { _client.TcpClient = null; _client.MessageBroker = null; _client.Connected = false; MessageBox.Show("Не удалось подключиться к севреру.\n"); UpdateGUI.UpdateControl(txtStatus, "Text", "Не удалось подключиться к севреру."); } } else { if (_client.TcpClient != null) { _client.Disconnect(true); _client.Dispose(); this.Dispose(); this.Close(); } } }
private void UntieDisplayToConnection(Connection connection) { var display = displays.Where(d => d.ConnectionId == connection.ConnectionId).FirstOrDefault(); if (display != null) { display.Unreserve(connection.ConnectionId); display.RdpDisplay.Disconnect(); UpdateGUI.UpdateControl(display.Label, "Text", string.Empty); } }
private void TieDisplayToConnection(Connection connection) { var display = FindEmptyDisplay(); var displayId = display.Id; if (display != null) { if (connection.State == Utils.Models.ConnectionState.Demonstration) { display.RdpDisplay.SmartSizing = true; display.Reserve(connection.ConnectionId); display.RdpDisplay.Connect(connection.ConnectionString, connection.AuthData.Name, connection.AuthData.Password); var name = string.IsNullOrEmpty(connection.User.LabName) ? "" : connection.User.LabName; UpdateGUI.UpdateControl(display.Label, "Text", $"{connection.ClientIP} {name}"); } } }
private void RequestControlButton_Click(object sender, EventArgs e) { Button btn = (Button)sender; var btnId = ParseControlId(btn.Name, "btnRequestControl"); var currentConnection = connectionsDictionary.Where(c => c.Value.ConnectionId == btnId).FirstOrDefault().Value; if (btnId > 0) { var ip = string.Empty; try { currentConnection.RdpViewer.RequestControl(CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE); currentConnection.State = Utils.Models.ConnectionState.Control; foreach (var connection in connectionsDictionary) { var btns = connection.Value.TabPage.Controls.OfType <Button>().ToList(); if (connection.Value.ConnectionId != btnId) { btns[2].Enabled = false; btns[3].Enabled = false; } else { ip = connection.Value.ClientIP; btn.Enabled = false; btns[0].Enabled = false; btns[1].Enabled = true; btns[3].Enabled = true; } } UpdateGUI.UpdateControl(txtStatus, "Text", $"Запущено управление клиентом {ip}."); } catch { MessageBox.Show($"Не удалось запустить управление клиентом {ip}."); UpdateGUI.UpdateControl(txtStatus, "Text", $"Не удалось запустить управление клиентом {ip}."); } } }
private void StartTranslationButton_Click(object sender, EventArgs e) { Button btn = (Button)sender; var btnId = ParseControlId(btn.Name, "btnStartView"); if (btnId > 0) { var ip = connectionsDictionary.Where(c => c.Value.ConnectionId == btnId).FirstOrDefault().Value.ClientIP; var connection = connectionsDictionary[ip]; connection.State = Utils.Models.ConnectionState.Demonstration; var conStr = connectionsDictionary[ip].ConnectionString; connection.RdpViewer.Connect(connection.ConnectionString, connection.AuthData.Name, connection.AuthData.Password); btn.Enabled = false; connection.TabPage.Controls.OfType <Button>().ToList()[1].Enabled = true; connection.TabPage.Controls.OfType <Button>().ToList()[2].Enabled = !connection.ProhibitDemo; connection.TabPage.Controls.OfType <Button>().ToList()[3].Enabled = false; UpdateGUI.UpdateControl(txtStatus, "Text", "Трансляция запущена."); } }
private void ExecuteConnectClient(Connection connection, ICommand cmd) { User user = (User)cmd.GetData()[0]; string connectionString = (string)cmd.GetData()[1]; bool prohibit = (bool)cmd.GetData()[2]; connection.User = user; connection.ProhibitDemo = prohibit; if (!String.IsNullOrEmpty(connectionString)) { connection.ConnectionString = connectionString; var tab = CreateNewTab(connection.ClientIP, true, prohibit); AxRDPViewer viewer = (AxRDPViewer)tab.Controls.Find($"rdpViewer{connectionId}", false).FirstOrDefault(); //Нужно добавить!!! viewer.OnConnectionTerminated += (reason, info) => DeleteConnection(connection.ClientIP, false); viewer.OnApplicationClose += (reason, info) => DeleteConnection(connection.ClientIP, false); viewer.OnAttendeeDisconnected += (reason, info) => DeleteConnection(connection.ClientIP, false); viewer.OnConnectionFailed += (reason, info) => DeleteConnection(connection.ClientIP, false); if (viewer != null) { UpdateGUI.UpdateControl(viewer, "SmartSizing", true); connection.RdpViewer = viewer; connection.TabPage = tab; } } else { var tab = CreateNewTab(connection.ClientIP, false, prohibit); connection.TabPage = tab; MessageBox.Show($"Не удалось получить строку подключения от клиента {connection.ClientIP}. Мониторинг невозможен."); UpdateGUI.UpdateControl(txtStatus, "Text", $"Не удалось получить строку подключения от клиента {connection.ClientIP}."); } }
private void btnUpdate_Click(object sender, EventArgs e) { FillCheckBoxList(); UpdateGUI.UpdateControl(btnConnect, "Enabled", true); }