Ejemplo n.º 1
0
        public bool ExecuteConditionalAction()
        {
            // first ping
            var msgPing = ChatMessageFactory.CreateDefault(Command.REQ_PING, Participant.CLIENT);
            var dealer  = (DealerSocket)messageBroker.Socket;

            messageBroker.Client_SendMsg(dealer, msgPing);
            ConsoleUI.ShowTextLine(Phrase.AskUsername);

            return(true);
        }
Ejemplo n.º 2
0
        public bool ExecuteConditionalAction()
        {
            // last ping and good bye!
            var msgBye = ChatMessageFactory.CreateDefault(Command.REQ_END_SESSION, Participant.CLIENT, this.messageBroker.ChatRoom.UserSession);
            var dealer = (DealerSocket)messageBroker.Socket;

            messageBroker.Client_SendMsg(dealer, msgBye);

            int numChars = this.messageBroker.ChatRoom.UserSession.HasUserName() ? this.messageBroker.ChatRoom.UserSession.UserName.Length + 3 : 10;

            for (int i = 0; i < numChars; i++)
            {
                // backspace
                Console.Write("\b");
            }

            ConsoleUI.ShowTextLine(Phrase.EndSessionUsername);

            return(true);
        }
Ejemplo n.º 3
0
        private void ConsoleLoop()
        {
            ConsoleUI.ShowText(Phrase.UsernamePrefix, new[] { userSession.UserName });
            string msgChat = Console.ReadLine();

            while (msgChat != "/exit")
            {
                var chatToServer = ChatMessageFactory.CreateDefault(Command.REQ_CHAT, Participant.CLIENT, userSession);
                chatToServer.Content = msgChat;

                broker.Client_SendMsg(dealer, chatToServer);

                ConsoleUI.ShowText(Phrase.UsernamePrefix, new[] { userSession.UserName });
                msgChat = Console.ReadLine();
            }

            // exit notification
            new CommandsInvoker(new CmdNotifyExitClient(broker)).Invoke();

            Thread.Sleep(2000);
        }
Ejemplo n.º 4
0
        public bool ExecuteConditionalAction()
        {
            var regUserCmd = ChatMessageFactory.CreateDefault(Command.REQ_REGISTER_USERNAME,
                                                              Participant.CLIENT, messageBroker.ChatRoom.UserSession);

            ConsoleUI.ShowText(Phrase.GuestPrefix);
            regUserCmd.UserName = Console.ReadLine();
            while (!regUserCmd.Validate(validUserName).IsValid)
            {
                ConsoleUI.ShowTextLine(Phrase.InvalidUsernameFormat);
                ConsoleUI.ShowText(Phrase.GuestPrefix);
                regUserCmd.UserName = Console.ReadLine().ToLower();
            }

            IEnumerable <string> errors;

            if (!regUserCmd.TryValidate(validRegistration, out errors))
            {
                ThrowExHelper.ThrowException($"ERROR:Invalid registration, ChatMessage:{regUserCmd}");
            }

            var dealer = (DealerSocket)messageBroker.Socket;

            //messageBroker.Client_SendMsg(messageBroker.ChatRoom.UserSession.StrUserGuid, dealer, regUserCmd);
            messageBroker.Client_SendMsg(dealer, regUserCmd);

            // waiting the username update from server..
            while (string.IsNullOrWhiteSpace(messageBroker.ChatRoom.UserSession.UserName))
            {
                Thread.Sleep(100);
            }

            ConsoleUI.ShowTextLine(Phrase.ThankYouNewUsername, new[] { messageBroker.ChatRoom.UserSession.UserName });

            return(true);
        }