private void OpenChat() { Chat chat = new Chat(communication); chat.Run(); chat.autoResetConnectAgain.WaitOne(); communication.SendMessage("I left the chat"); communication.AnswerAndWriteServer(); while (true) { var line = Console.ReadLine(); if (line.Length > 0) { communication.SendMessage(line); communication.AnswerAndWriteServer(); communication.SendMessage("Okey"); if (communication.data.ToString() == "You left the messanger") { EndUsing = true; return; } writerGroups.Run(6); AnswerAndWriteServer(); return; } } }
public void Run() { //Interlocked Task.Run(() => secondWindowServer.Run()); secondWindowServer.autoResetCreated.WaitOne(); communication.AnswerServer(); TypeChat = communication.data.ToString(); communication.SendMessage("ok"); communication.AnswerAndWriteServer(); communication.SendMessage("ok"); WriteMessages(); Task.Run(() => AnswerUsers()); while (true) { var line = Console.ReadLine(); if (line.Length > 0) { if (line == "?/send" || line == "?/download" || line == "?/change" || line == "?/invite" || line == "?/delete" || line == "?/leave a group" || line == "?/end") { autoResetMessage.WaitOne(); communication.SendMessage(line); switch (line) { case "?/send": SendFile(); break; case "?/download": ReceiveFile(); break; case "?/change": if (TypeChat == "pp" || TypeChat == "ch") { ChangeTypeGroup(); break; } autoResetMessage.Set(); continue; case "?/invite": if (TypeChat == "pg" || TypeChat == "ug" || TypeChat == "sg") { InviteOrDeleteUser(); break; } autoResetMessage.Set(); continue; case "?/delete": InviteOrDeleteUser(); break; case "?/leave a group": var successLeave = LeaveGroup(); if (successLeave) { autoResetMessage.Set(); return; } break; case "?/end": autoResetMessage.Set(); return; } communication.SendMessage("okey"); WriteMessages(); autoResetMessage.Set(); } else { communication.SendMessage(line); } } } }