private void CreateChat(string clientCreator, int numberChat, List <string> clients) { Dictionary <string, bool> infoClientsForAdd = new Dictionary <string, bool>(_handlerConnection.InfoClientsAtChat); Dictionary <string, bool> infoClientsAtChat = new Dictionary <string, bool>(); foreach (var item in clients) { if (_handlerConnection.InfoClientsAtChat.TryGetValue(item, out bool activityClient)) { infoClientsAtChat.Add(item, activityClient); infoClientsForAdd.Remove(item); } } AddedChat?.Invoke(this, new AddedChatVmEventArgs(clientCreator, infoClientsAtChat, infoClientsForAdd, numberChat)); }
public void ParsePacket(Guid clientId, MessageContainer container) { switch (container.Identifier) { case nameof(ConnectionRequest): { var connectionRequest = ((JObject)container.Payload).ToObject(typeof(ConnectionRequest)) as ConnectionRequest; ClientConnected?.Invoke(this, new ClientConnectedEventArgs(connectionRequest.ClientName, clientId)); break; } case nameof(DisconnectNotice): { var disconnectionRequest = ((JObject)container.Payload).ToObject(typeof(DisconnectNotice)) as DisconnectNotice; ClientDisconnected?.Invoke(this, new ClientDisconnectedEventArgs(disconnectionRequest.NameClient, clientId)); break; } case nameof(InfoAboutAllClientsRequest): { var infoClientRequest = ((JObject)container.Payload).ToObject(typeof(InfoAboutAllClientsRequest)) as InfoAboutAllClientsRequest; RequestInfoAllClient?.Invoke(this, new InfoAboutAllClientsEventArgs(infoClientRequest.NameClient)); break; } case nameof(MessageRequest): { var messageRequest = ((JObject)container.Payload).ToObject(typeof(MessageRequest)) as MessageRequest; MessageReceived?.Invoke(this, new MessageReceivedEventArgs(messageRequest.ClientName, messageRequest.Message, messageRequest.NumberChat)); break; } case nameof(ConnectToChatRequest): { var connectionToChat = ((JObject)container.Payload).ToObject(typeof(ConnectToChatRequest)) as ConnectToChatRequest; ConnectedToChat?.Invoke(this, new ConnectionToChatEventArgs(connectionToChat.ClientName, connectionToChat.NumberChat)); break; } case nameof(AddChatRequest): { var addNewChatRequest = ((JObject)container.Payload).ToObject(typeof(AddChatRequest)) as AddChatRequest; AddedChat?.Invoke(this, new AddedNewChatEventArgs(addNewChatRequest.NameClientSender, addNewChatRequest.Clients)); break; } case nameof(RemoveChatRequest): { var removeChatRequest = ((JObject)container.Payload).ToObject(typeof(RemoveChatRequest)) as RemoveChatRequest; RemovedChat?.Invoke(this, new RemovedChatEventArgs(removeChatRequest.NameOfRemover, removeChatRequest.NumberChat)); break; } case nameof(AddClientToChatRequest): { var addNewClientToChatRequest = ((JObject)container.Payload) .ToObject(typeof(AddClientToChatRequest)) as AddClientToChatRequest; AddedClientsToChat?.Invoke(this, new AddedClientsToChatEventArgs(addNewClientToChatRequest.ClientName, addNewClientToChatRequest.NumberChat, addNewClientToChatRequest.Clients)); break; } case nameof(RemoveClientFromChatRequest): { var removeClientFromChatRequest = ((JObject)container.Payload) .ToObject(typeof(RemoveClientFromChatRequest)) as RemoveClientFromChatRequest; RemovedClientsFromChat?.Invoke(this, new RemovedClientsFromChatEventArgs(removeClientFromChatRequest.ClientName, removeClientFromChatRequest.NumberChat, removeClientFromChatRequest.Clients)); break; } case nameof(NumbersAccessibleChatsRequest): { var requestNumbersChats = ((JObject)container.Payload) .ToObject(typeof(NumbersAccessibleChatsRequest)) as NumbersAccessibleChatsRequest; RequestNumbersChats?.Invoke(this, new ClientRequestedNumbersChatEventArgs(requestNumbersChats.NameClient)); break; } } }
public void ParsePacket(MessageContainer container) { switch (container.Identifier) { case nameof(ConnectionResponse): { var connectionResponse = ((JObject)container.Payload).ToObject(typeof(ConnectionResponse)) as ConnectionResponse; ClientConnected?.Invoke(this, new ClientConnectedToServerVmEventArgs(connectionResponse.Result, connectionResponse.Reason)); break; } case nameof(ConnectionNotice): { var connectionNoticeForClients = ((JObject)container.Payload).ToObject(typeof(ConnectionNotice)) as ConnectionNotice; AnotherClientConnected?.Invoke(this, new AnotherClientConnectedVmEventArgs(connectionNoticeForClients.NameClient)); break; } case nameof(DisconnectNotice): { var disconnectionResponse = ((JObject)container.Payload).ToObject(typeof(DisconnectNotice)) as DisconnectNotice; AnotherClientDisconnected?.Invoke(this, new AnotherClientDisconnectedVmEventArgs(disconnectionResponse.NameClient)); break; } case nameof(MessageResponse): { var messageResponse = ((JObject)container.Payload).ToObject(typeof(MessageResponse)) as MessageResponse; MessageReceived?.Invoke(this, new MessageReceivedVmEventArgs(messageResponse.Message, messageResponse.NumberChat)); break; } case nameof(ConnectToChatResponse): { var connectionToChatResponse = ((JObject)container.Payload).ToObject(typeof(ConnectToChatResponse)) as ConnectToChatResponse; ConnectedToChat?.Invoke(this, new ClientConnectedToChatVmEventArgs(connectionToChatResponse.AllMessageFromChat, connectionToChatResponse.NumberChat)); break; } case nameof(AddChatResponse): { var addNewChatResponse = ((JObject)container.Payload).ToObject(typeof(AddChatResponse)) as AddChatResponse; AddedChat?.Invoke(this, new AddedNewChatModelEventArgs(addNewChatResponse.ClientCreator, addNewChatResponse.NumberChat, addNewChatResponse.Clients)); break; } case nameof(RemoveChatResponse): { var removeChatResponse = ((JObject)container.Payload).ToObject(typeof(RemoveChatResponse)) as RemoveChatResponse; RemovedChat?.Invoke(this, new RemovedChatEventArgs(removeChatResponse.NameClient, removeChatResponse.NumberChat)); break; } case nameof(AddClientToChatResponse): { var addNewClientToChatResponse = ((JObject)container.Payload) .ToObject(typeof(AddClientToChatResponse)) as AddClientToChatResponse; AddedClientsToChat?.Invoke(this, new AddedClientsToChatEventArgs(addNewClientToChatResponse.ClientName, addNewClientToChatResponse.NumberChat, addNewClientToChatResponse.Clients)); break; } case nameof(RemoveClientFromChatResponse): { var removeClientFromChatResponse = ((JObject)container.Payload) .ToObject(typeof(RemoveClientFromChatResponse)) as RemoveClientFromChatResponse; RemovedClientsFromChat?.Invoke(this, new RemovedClientsFromChatEventArgs(removeClientFromChatResponse.ClientName, removeClientFromChatResponse.NumberChat, removeClientFromChatResponse.Clients)); break; } case nameof(NumbersAccessibleChatsResponse): { var responseNumbersChats = ((JObject)container.Payload) .ToObject(typeof(NumbersAccessibleChatsResponse)) as NumbersAccessibleChatsResponse; ResponseNumbersChats?.Invoke(this, new NumbersOfChatsReceivedModelEventArgs(responseNumbersChats.AllInfoAboutChat)); break; } case nameof(InfoAboutAllClientsResponse): { var responseInfoAboutClients = ((JObject)container.Payload) .ToObject(typeof(InfoAboutAllClientsResponse)) as InfoAboutAllClientsResponse; ReceivedInfoAboutAllClients?.Invoke(this, new ReceivedInfoAboutAllClientsVmEventArgs(responseInfoAboutClients.InfoAboutAllClients)); break; } } }