Ejemplo n.º 1
0
        private void ParseMessage(Message message)
        {
            switch (message.PostCode)
            {
            case {} i when(i >= 1 && i <= 4):
            {
                var simpleMessage = message as SimpleMessage;
                Cmd.UserWriteLine(simpleMessage?.SendData, simpleMessage?.Sender);
                notification();

                break;
            }

            case 5:
            {
                var idMessage = message as IDMessage;
                if (idMessage?.Method == Method.Send)
                {
                    id = idMessage.SendData;
                    Cmd.WriteLine($"Your id is: {id}");
                }


                break;
            }

            case 7:
            {
                var connectionMessage = message as ConnectionMessage;
                if (connectionMessage?.Connection == Connection.Connect)
                {
                    Cmd.ConnectionMessage(connectionMessage.Sender, "has joined");
                }
                else
                {
                    Cmd.ConnectionMessage(connectionMessage?.Sender, "has disconnected");
                }

                break;
            }

            case 10:
            {
                DisconnectClient();                     //If server sends us message about stopping
                Cmd.WriteLine("Server was stopped");    //We are decide to write this

                break;
            }

            case 11:
            {
                DisconnectClient();
                Cmd.WriteLine("Hash sum is not correct");

                break;
            }

            default: return;
            }

            Cmd.SwitchToPrompt();                           //Lets go back to console
        }