Example #1
0
        public Task Handle(HttpContext context, int prefixLength)
        {
            var path = context.Request.Path.Value;

            if (path.Length == prefixLength)
            {
                return(context.Response.WriteError("Command not specified", HttpStatusCode.BadRequest));
            }
            var command = path.Substring(prefixLength + 1);

            if (command.Length == 0)
            {
                return(context.Response.WriteError("Command not specified", HttpStatusCode.BadRequest));
            }
            var commandType = CommandsRepository.Find(command);

            if (commandType == null)
            {
                return(context.Response.WriteError($"Unknown command: {command}", HttpStatusCode.NotFound));
            }
            switch (context.Request.Method)
            {
            case "POST":
                return(Application.Execute(commandType, context.Request.Body, context));

            case "GET":
                return(Application.Execute(commandType, null, context));

            default:
                return(Utility.WriteError(context.Response, "Unsuported method type", HttpStatusCode.MethodNotAllowed));
            }
        }
 public void ConvertStream <TCommand, TArgument>(HttpContext contex, TArgument argument)
 {
     if (argument == null)
     {
         Application.Execute(typeof(TCommand), null, contex);
         return;
     }
     using (var ms = ChunkedMemoryStream.Create())
     {
         Serialization.Serialize(argument, contex.Request.ContentType, ms);
         ms.Position = 0;
         Application.Execute(typeof(TCommand), ms, contex);
     }
 }
Example #3
0
 public void Get(string command)
 {
     Application.Execute(command, null, HttpContext);
 }