Exemple #1
0
        public async Task <HttpResponseMessage> PutCommand(Guid commandId, CancellationToken cancellationToken)
        {
            IParsedMediaType parsedMediaType = ParseMediaType();
            Type             commandType     = ResolveCommandType(parsedMediaType);

            if (!string.Equals(parsedMediaType.SerializationType, "json", StringComparison.OrdinalIgnoreCase))
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            object command = await DeserializeCommand(commandType);

            MethodInfo dispatchCommandMethod = DispatchCommandMethodInfo.MakeGenericMethod(command.GetType());

            Func <Task> func = async() => await((Task)dispatchCommandMethod.Invoke(null,
                                                                                   new[]
            {
                _settings.HandlerResolver,
                commandId,
                command,
                _predispatch,
                Request.Headers,
                cancellationToken
            })).NotOnCapturedContext();

            await func();

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Exemple #2
0
        private Type ResolveCommandType(IParsedMediaType parsedMediaType)
        {
            Type commandType = _settings.ResolveCommandType(parsedMediaType.TypeName, parsedMediaType.Version);

            if (commandType == null)
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            return(commandType);
        }
Exemple #3
0
        private IParsedMediaType ParseMediaType()
        {
            string           mediaType       = Request.Content.Headers.ContentType.MediaType;
            IParsedMediaType parsedMediaType = _settings.ParseMediaType(mediaType);

            if (parsedMediaType == null)
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            return(parsedMediaType);
        }