Exemplo n.º 1
0
        public async Task <bool> Execute(HubConnection hubConnection, string methodName)
        {
            string name = await hubConnection.InvokeAsync <string>(methodName);

            ConsoleExtenstions.Show($"\nYour name: {name}\n", ConsoleColor.Green);
            return(true);
        }
Exemplo n.º 2
0
        public async Task StartChatAsync()
        {
            bool isRunning = true;

            while (isRunning)
            {
                System.Console.WriteLine("\nEnter your command (help - show all commands):");

                var input = System.Console.ReadLine();
                if (string.IsNullOrWhiteSpace(input))
                {
                    continue;
                }

                if (commands.ContainsKey(input))
                {
                    IHubCommand command = commands.GetValueOrDefault(input);
                    if (command != null)
                    {
                        isRunning = await command.Execute(HubConnection, hubMethods.GetValueOrDefault(input));
                    }
                }
                else
                {
                    ConsoleExtenstions.Show($"\nError:: Command [{input}] is not valid\n", ConsoleColor.Red);
                }
            }

            ConsoleExtenstions.Show("\nPress any key...\n", ConsoleColor.Yellow);
            System.Console.ReadLine();
        }
Exemplo n.º 3
0
        public async Task <bool> Execute(HubConnection hubConnection, string methodName)
        {
            ConsoleExtenstions.Show("\nPlease write your name: ", ConsoleColor.Yellow);

            string name = System.Console.ReadLine();

            if (string.IsNullOrWhiteSpace(name))
            {
                ConsoleExtenstions.Show("\nName is not valid.\n", ConsoleColor.Red);
                return(true);
            }

            await hubConnection.SendAsync(methodName, name);

            ConsoleExtenstions.Show("\nName sent\n", ConsoleColor.Green);
            return(true);
        }
Exemplo n.º 4
0
        public async Task <bool> Execute(HubConnection hubConnection, string methodName)
        {
            ConsoleExtenstions.Show("\nPlease write your message: ", ConsoleColor.Yellow);
            string text = System.Console.ReadLine();

            System.Console.WriteLine();
            var message = new Message
            {
                Title = "New Message",
                Text  = text
            };

            await hubConnection.SendAsync(methodName, message);

            ConsoleExtenstions.Show("Message sent\n", ConsoleColor.Green);

            return(true);
        }