Beispiel #1
0
        internal static ChatMessage CreateDefault(Command command, Participant sender, UserSession chatUserOrigin = null)
        {
            if (command == Command.UNKNOWN)
            {
                ThrowExHelper.ThrowValidationException($"Invalid option for command:{command}");
            }

            return(new ChatMessage
            {
                UserGuid = chatUserOrigin?.UserGuid ?? default,
                UserName = chatUserOrigin?.UserName ?? default,
                Command = command,
                Sender = sender
            });
Beispiel #2
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);
        }