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();
        }
Beispiel #2
0
        public async Task SendAsync(IHubCommand command)
        {
            var eventHubClient = _commandClients[command.GetType()];
            var eventData      = new EventData(Encoding.UTF8.GetBytes(command.ToJson()));

            eventData.Properties["ContentType"] = command.GetType().AssemblyQualifiedName;
            var partitionKey = command is IAggregateHubCommand aggregateCommand?aggregateCommand.GetAggregateId() : command.MessageId.ToString();

            await eventHubClient.SendAsync(eventData, partitionKey).ConfigureAwait(false);
        }
        private async Task ProcessHubCommand(Type messageType, IHubCommand hubCommand)
        {
            var handlerType      = _commandHandlers[messageType];
            var handler          = _handlerActivator.GetInstance(handlerType);
            var handleMethodInfo = handlerType.GetMethod("HandleAsync");

            if (handleMethodInfo == null)
            {
                return;
            }
            await((Task)handleMethodInfo?.Invoke(handler, new[] { hubCommand })).ConfigureAwait(false);
        }