private void SendAllConecctedClients(Guid clientGuid) { List <Guid> clientsToAdd = _data.ClientsConnectedInServer.Clients.Keys.ToList(); clientsToAdd.Remove(clientGuid); Participants participants = new Participants(clientsToAdd); _requests.SendModelMessage(_client, participants); }
private void SendAlert(TcpClient client) { MessageRequest alert = _data.ClientsAlerts.GetAlert(client); _requests.SendModelMessage(client, alert); _data.ClientsAlerts.RemoveAlert(client, alert); }
private void ExistChat(Guid clientGuid, Guid guidToSend) { MessageRequest messageRequest = new MessageRequest(MessageKey.Exit, "0"); _requests.SendModelMessage(_client, messageRequest); _data.ClientsConnectedInChat.Remove(clientGuid, guidToSend); _logger.LogInformation($"client {clientGuid} leave chat with client {guidToSend}"); }
private void SendAllAboutExist(Guid clientGuid) { string message = $"{clientGuid} exist the global chat"; SendMessageToEachClient(message); MessageRequest messageRequest = new MessageRequest(MessageKey.Exit, "0"); _requests.SendModelMessage(_client, messageRequest); _logger.LogInformation($"client {clientGuid} exit global chat"); }
public void Run() { try { _requests.SendStringMessage(_client, ClientOptions.MANAGER_SETTINGS.ToString()); AllGroupChat allGroupChat = (AllGroupChat)_requests.GetModelMessage(_client); PrintAllGroups(allGroupChat); if (allGroupChat.GroupsName.Count > 0) { _system.Write("enter group name"); string userResponse = _system.ReadString(); if (CheckGroupName(userResponse, allGroupChat)) { _requests.SendStringMessage(_client, userResponse); GroupChat groupChat = (GroupChat)_requests.GetModelMessage(_client); Participants participants = (Participants)_requests.GetModelMessage(_client); _system.Write("enter names you want to remove from group, when end enter o"); PrintParticipants(groupChat.Participants); List <Guid> usersToRemove = GetAllParticipants(groupChat.Participants); _system.Write("enter names you want to add to group, when end enter o"); PrintParticipants(participants.AllParticipants); List <Guid> usersToAdd = GetAllParticipants(participants.AllParticipants); usersToAdd.RemoveAll(u => CheckIfParticipantsExist(u, groupChat.Participants) == true); _system.Write("enter names you want to add as mangers, when end enter o"); List <Guid> usersToAddAsMangers = GetAllParticipants(groupChat.Participants); usersToAddAsMangers.RemoveAll(u => CheckIfParticipantsExist(u, usersToRemove) == true); ChangeGroup(groupChat, usersToRemove, usersToAdd, usersToAddAsMangers); _requests.SendModelMessage(_client, groupChat); } else { _requests.SendStringMessage(_client, "0"); _system.Write("the group not exist"); } } else { _requests.SendStringMessage(_client, "0"); _system.Write("you dont have any group that you managment"); } } catch (Exception) { } }
public static void SendMessageToEachClient(string message, List <TcpClient> clients, IRequests requests) { foreach (var client in clients) { if (client.Connected) { MessageRequest messageRequest = new MessageRequest(MessageKey.STRING, message); requests.SendModelMessage(client, messageRequest); } } }
private void StartGroupChat() { bool end = false; GroupChat group = null; var clientGuid = _data.ClientsConnectedInServer.GetGuid(_client); try { SendAllClientGroups(clientGuid); string dataReceived = _requests.GetStringMessage(_client); if (dataReceived == "0") { _logger.LogInformation("client dont want to enter chat in any group"); } else { group = _data.AllGroupsChat.GetGroupsChat().Where(g => g.Name == dataReceived).First(); _logger.LogInformation($"client {clientGuid} enter to group chat {group.Name}"); _data.AllGroupsChat.AddClientConnected(group, _client); SendMessagesHistory(group); while (!end) { dataReceived = _requests.GetStringMessage(_client); if (dataReceived == "0") { MessageRequest messageRequest = new MessageRequest(MessageKey.Exit, "0"); _requests.SendModelMessage(_client, messageRequest); ClientOutOfGroup(group); _data.AllGroupsChat.RemoveClientUnConnected(group, _client); end = true; } else { string message = $"{clientGuid} send: {dataReceived}"; SendMessageToEachClient(group, message); } } } } catch (Exception) { end = true; _data.AllGroupsChat.RemoveClientUnConnected(group, _client); ChatUtils.RemoveClientWhenOut(_client, clientGuid, _data); } _logger.LogInformation("client out chat"); }
public static void SendMessagesHistory(List <string> messagesInHistory, TcpClient client, IRequests requests) { string allMessages = ""; foreach (var message in messagesInHistory) { allMessages += message + "\n"; } if (allMessages != "") { MessageRequest messageRequest = new MessageRequest(MessageKey.STRING, allMessages); requests.SendModelMessage(client, messageRequest); } }
public static void SendAllGroupChat(TcpClient client, IRequests requests, List <string> grouspName) { AllGroupChat allGroupChat = new AllGroupChat(grouspName); requests.SendModelMessage(client, allGroupChat); }
public static void SandStringMessage(TcpClient client, IRequests requests, string message) { MessageRequest messageRequest = new MessageRequest(MessageKey.STRING, message); requests.SendModelMessage(client, messageRequest); }
private void SendGroupToServer(string gropuName, List <Guid> usersToAdd) { GroupChat groupChat = new GroupChat(gropuName, usersToAdd, new List <Guid>()); _requests.SendModelMessage(_client, groupChat); }