예제 #1
0
 private void AnswerServer()
 {
     communication.AnswerServer();
 }
예제 #2
0
        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);
                    }
                }
            }
        }