コード例 #1
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);
        }
コード例 #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));
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 internal IRestMethodExecutor Create(RestControllerMethodInfo info)
 {
     if (info.HasBodyParameter)
     {
         return _withBodyExecutor;
     }
     else
     {
         return _withoutBodyExecutor;
     }
 }
コード例 #6
0
 internal IRestMethodExecutor Create(RestControllerMethodInfo info)
 {
     if (info.HasContentParameter)
     {
         return(_withContentExecutor);
     }
     else
     {
         return(_withoutContentExecutor);
     }
 }
コード例 #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));
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: RestMethodExecutor.cs プロジェクト: tur0kk/restup
        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.");
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: RestMethodExecutor.cs プロジェクト: tur0kk/restup
 protected abstract object ExecuteAnonymousMethod(RestControllerMethodInfo info, RestServerRequest request);