Ejemplo n.º 1
0
        public override async Task Invoke(IOwinContext context)
        {
            try
            {
                var commandName = commandNameResolver.GetCommandName();
                var command     = commandFactory.Construct(commandName);

                if (command != null)
                {
                    context.SetCommand(command);
                    await Next.Invoke(context);
                }
            }
            catch (CommandConstructionException ex)
            {
                context.Response.BadRequest(ex.Message);
            }
            catch (EmptyCommandBodyException)
            {
                context.Response.BadRequest("Command body was not provided");
            }
            catch (UnidentifiableCommandException)
            {
                context.Response.BadRequest("Could not identify command from request");
            }
            catch (UnknownCommandException ex)
            {
                context.Response.NotFound($"Command '{ex.Command}' does not exist.");
            }
        }
Ejemplo n.º 2
0
        private Type GetCommandType(IOwinContext context)
        {
            var commandName = commandNameResolver.GetCommandName(context.Environment);

            if (string.IsNullOrWhiteSpace(commandName))
            {
                throw new UnidentifiableCommandException();
            }

            var commandType = commandRegistry.GetCommandType(commandName);

            if (commandType == null)
            {
                throw new UnknownCommandException(commandName);
            }

            return(commandType);
        }