public string GetResponse(string response) { var obj = Utils.DeSerlizeObject <MainRequest>(response); switch (obj.RequestType) { case MessageType.NewChatMessage: var model = Utils.DeSerlizeObject <NewChatMessage>(response); return($"{DateTime.Now.ToString("MM/dd/yyyy")} : {model.From} sent : {model.Message} "); case MessageType.UserStatus: var userStatusModel = Utils.DeSerlizeObject <StatusClientMessage>(response); return($"{DateTime.Now.ToString("MM/dd/yyyy")} : {userStatusModel.From} {userStatusModel.StatusClient}"); case MessageType.GetAllChats: var allChatsResponse = Utils.DeSerlizeObject <AllChatsMessage>(response); return(ChatUtils.GetChatsResponse(allChatsResponse.Chats)); case MessageType.GetAllUserConnected: var allUsersResponse = Utils.DeSerlizeObject <AllUsersMessage>(response); string allUsersStr = ""; allUsersResponse.Names.ForEach(n => allUsersStr += $"{n} {Environment.NewLine}"); return(allUsersStr); case MessageType.SuccessResponse: var successResponse = Utils.DeSerlizeObject <OkResponseMessage>(response); return($"request Sucess : {successResponse.Message}"); case MessageType.ErrorResponse: var errorResponse = Utils.DeSerlizeObject <ErrorMessage>(response); return($"request Failed : {errorResponse.Error}"); case MessageType.HistoryChatMessages: var chatMessageHistory = Utils.DeSerlizeObject <ChatMessageHistory>(response); string msg = ""; chatMessageHistory.AllMessages.ToList().ForEach(m => msg += $"{m.Datetime.ToString("MM/dd/yyyy")} : {m.SenderName} sent : {m.Message} {Environment.NewLine}"); return(msg); default: return(null); } }
public void Operation() { _containerInterfaces.SystemOutput.Print("All chats group chats"); List <ChatMessageModel> allChats = _serverHandler.GetAllChatGroupModels(); _containerInterfaces.SystemOutput.Print(ChatUtils.GetChatsResponse(allChats)); _containerInterfaces.SystemOutput.Print("Please enter the group name you want to remove to | CLICK --stop for stop type OR exit for exit option-- EXIT"); string groupName = _containerInterfaces.SystemInput.StringInput(); while (groupName != "stop") { if (groupName == "exit") { return; } if (allChats.Any(c => c.GroupName == groupName)) { break; } _containerInterfaces.SystemOutput.Print("Please enter the group name you want to add to | CLICK --stop for stop type OR exit for exit option-- EXIT"); groupName = _containerInterfaces.SystemInput.StringInput(); } var body = new GroupChatMessageModel { RequestType = MessageType.ExitChat, lsUsers = new List <string>() { _clientname }, GroupName = groupName }; _serverHandler.UpdateChat(body); }
public void Operation() { _containerInterfaces.SystemOutput.Print("All chats group chats"); List <ChatMessageModel> allChats = _serverHandler.GetAllChatGroupModels(); _containerInterfaces.SystemOutput.Print(ChatUtils.GetChatsResponse(allChats)); _containerInterfaces.SystemOutput.Print("Please enter the group name you want to remove permission to | CLICK --stop for stop type OR exit for exit option-- EXIT"); string groupName = _containerInterfaces.SystemInput.StringInput(); while (groupName != "stop") { if (groupName == "exit") { return; } if (allChats.Any(c => c.GroupName == groupName)) { break; } _containerInterfaces.SystemOutput.Print("Please enter the group name you want to remove permission to | CLICK --stop for stop type OR exit for exit option-- EXIT"); groupName = _containerInterfaces.SystemInput.StringInput(); } _containerInterfaces.SystemOutput.Print("All connected users"); string allConnectedUser = _serverHandler.GetAllUserConnected(); _containerInterfaces.SystemOutput.Print(allConnectedUser); _containerInterfaces.SystemOutput.Print("Please enter the group name you want to remove admin permission to | CLICK --stop for stop type OR exit for exit option-- EXIT"); string name = _containerInterfaces.SystemInput.StringInput(); List <string> userNames = new List <string>(); while (name != "stop") { if (name == "exit") { return; } bool IsNameValidate = ValidateName(allConnectedUser, name, userNames, allChats.First(c => c.GroupName == groupName)); if (IsNameValidate) { userNames.Add(name); } _containerInterfaces.SystemOutput.Print("Please enter the group name you want to remove admin permission to | CLICK --stop for stop type OR exit for exit option-- EXIT"); name = _containerInterfaces.SystemInput.StringInput(); } var body = new GroupChatMessageModel { RequestType = MessageType.RemoveAdminPermissions, lsUsers = userNames, GroupName = groupName }; _serverHandler.UpdateChat(body); }