private object ExecuteAnonymousMethod(RestControllerMethodInfo info, HttpRequest request)
        {
            var instantiator = InstanceCreatorCache.Default.GetCreator(info.MethodInfo.DeclaringType);

            object bodyObj = null;
            try
            {
                bodyObj = _bodySerializer.FromBody(request.Content, request.RequestContentType, info.BodyParameterType);
            }
            catch (JsonReaderException)
            {
                return _responseFactory.CreateBadRequest();
            }
            catch (InvalidOperationException)
            {
                return _responseFactory.CreateBadRequest();
            }

            object[] parameters = null;
            try
            {
                parameters = info.GetParametersFromUri(request.Uri).Concat(new[] { bodyObj }).ToArray();
            }
            catch (FormatException)
            {
                return _responseFactory.CreateBadRequest();
            }

            return info.MethodInfo.Invoke(
                    instantiator.Create(info.MethodInfo.DeclaringType, info.ControllerConstructorArgs()),
                    parameters);
        }
Esempio n. 2
0
        private object ExecuteAnonymousMethod(RestControllerMethodInfo info, HttpRequest request)
        {
            var instantiator = InstanceCreatorCache.Default.GetCreator(info.MethodInfo.DeclaringType);

            object bodyObj = null;

            try
            {
                bodyObj = _bodySerializer.FromBody(request.Content, request.RequestContentType, info.BodyParameterType);
            }
            catch (JsonReaderException)
            {
                return(_responseFactory.CreateBadRequest());
            }
            catch (InvalidOperationException)
            {
                return(_responseFactory.CreateBadRequest());
            }

            object[] parameters = null;
            try
            {
                parameters = info.GetParametersFromUri(request.Uri).Concat(new[] { bodyObj }).ToArray();
            }
            catch (FormatException)
            {
                return(_responseFactory.CreateBadRequest());
            }

            return(info.MethodInfo.Invoke(
                       instantiator.Create(info.MethodInfo.DeclaringType, info.ControllerConstructorArgs()),
                       parameters));
        }
        public async Task<IRestResponse> ExecuteMethodAsync(RestControllerMethodInfo info, RestServerRequest request)
        {
            var methodInvokeResult = ExecuteAnonymousMethod(info, request);

            if (!info.IsAsync)
                return await Task.Run(() => (IRestResponse)methodInvokeResult);

            return await (dynamic)methodInvokeResult;
        }
        public async Task <IRestResponse> ExecuteMethodAsync(RestControllerMethodInfo info, RestServerRequest request)
        {
            var methodInvokeResult = ExecuteAnonymousMethod(info, request);

            if (!info.IsAsync)
            {
                return(await Task.Run(() => (IRestResponse)methodInvokeResult));
            }

            return(await(dynamic) methodInvokeResult);
        }
 internal IRestMethodExecutor Create(RestControllerMethodInfo info)
 {
     if (info.HasBodyParameter)
     {
         return _withBodyExecutor;
     }
     else
     {
         return _withoutBodyExecutor;
     }
 }
 internal IRestMethodExecutor Create(RestControllerMethodInfo info)
 {
     if (info.HasContentParameter)
     {
         return(_withContentExecutor);
     }
     else
     {
         return(_withoutContentExecutor);
     }
 }
Esempio n. 7
0
        protected override object ExecuteAnonymousMethod(RestControllerMethodInfo info, RestServerRequest request)
        {
            var instantiator = InstanceCreatorCache.Default.GetCreator(info.MethodInfo.DeclaringType);

            object[] parameters = null;
            try
            {
                parameters = info.GetParametersFromUri(request.HttpServerRequest.Uri).ToArray();
            }
            catch (FormatException)
            {
                return(_responseFactory.CreateBadRequest());
            }

            return(info.MethodInfo.Invoke(
                       instantiator.Create(info.MethodInfo.DeclaringType, info.ControllerConstructorArgs()),
                       parameters));
        }
        private object ExecuteAnonymousMethod(RestControllerMethodInfo info, RestServerRequest request)
        {
            var instantiator = InstanceCreatorCache.Default.GetCreator(info.MethodInfo.DeclaringType);

            object[] parameters = null;
            try
            {
                parameters = info.GetParametersFromUri(request.HttpServerRequest.Uri).ToArray();
            }
            catch (FormatException)
            {
                return _responseFactory.CreateBadRequest();
            }

            return info.MethodInfo.Invoke(
                    instantiator.Create(info.MethodInfo.DeclaringType, info.ControllerConstructorArgs()),
                    parameters);
        }
Esempio n. 9
0
        public async Task <IRestResponse> ExecuteMethodAsync(RestControllerMethodInfo info, RestServerRequest request)
        {
            var methodInvokeResult = ExecuteAnonymousMethod(info, request);

            switch (info.ReturnTypeWrapper)
            {
            case RestControllerMethodInfo.TypeWrapper.None:
                return(await Task.FromResult((IRestResponse)methodInvokeResult));

            case RestControllerMethodInfo.TypeWrapper.AsyncOperation:
                return(await ConvertToTask((dynamic)methodInvokeResult));

            case RestControllerMethodInfo.TypeWrapper.Task:
                return(await(dynamic) methodInvokeResult);
            }

            throw new Exception($"ReturnTypeWrapper of type {info.ReturnTypeWrapper} not known.");
        }
        private object ExecuteAnonymousMethod(RestControllerMethodInfo info, RestServerRequest request)
        {
            var instantiator = InstanceCreatorCache.Default.GetCreator(info.MethodInfo.DeclaringType);

            object contentObj = null;

            try
            {
                if (request.HttpServerRequest.Content != null)
                {
                    contentObj = _contentSerializer.FromContent(
                        request.ContentEncoding.GetString(request.HttpServerRequest.Content),
                        request.ContentMediaType,
                        info.ContentParameterType);
                }
            }
            catch (JsonReaderException)
            {
                return(_responseFactory.CreateBadRequest());
            }
            catch (InvalidOperationException)
            {
                return(_responseFactory.CreateBadRequest());
            }

            object[] parameters = null;
            try
            {
                parameters = info.GetParametersFromUri(request.HttpServerRequest.Uri).Concat(new[] { contentObj }).ToArray();
            }
            catch (FormatException)
            {
                return(_responseFactory.CreateBadRequest());
            }

            return(info.MethodInfo.Invoke(
                       instantiator.Create(info.MethodInfo.DeclaringType, info.ControllerConstructorArgs()),
                       parameters));
        }
        private object ExecuteAnonymousMethod(RestControllerMethodInfo info, RestServerRequest request)
        {
            var instantiator = InstanceCreatorCache.Default.GetCreator(info.MethodInfo.DeclaringType);

            object contentObj = null;
            try
            {
                if (request.HttpServerRequest.Content != null)
                {
                    contentObj = _contentSerializer.FromContent(
                        request.ContentEncoding.GetString(request.HttpServerRequest.Content),
                        request.ContentMediaType,
                        info.ContentParameterType);
                }
            }
            catch (JsonReaderException)
            {
                return _responseFactory.CreateBadRequest();
            }
            catch (InvalidOperationException)
            {
                return _responseFactory.CreateBadRequest();
            }

            object[] parameters = null;
            try
            {
                parameters = info.GetParametersFromUri(request.HttpServerRequest.Uri).Concat(new[] { contentObj }).ToArray();
            }
            catch (FormatException)
            {
                return _responseFactory.CreateBadRequest();
            }

            return info.MethodInfo.Invoke(
                    instantiator.Create(info.MethodInfo.DeclaringType, info.ControllerConstructorArgs()),
                    parameters);
        }
Esempio n. 12
0
 protected abstract object ExecuteAnonymousMethod(RestControllerMethodInfo info, RestServerRequest request);