Esempio n. 1
0
        public static async Task <TResult> ProcessRequest <TRequest, TResult>(ApiCallCommand <TRequest, TResult> request,
                                                                              Func <HttpResponseMessage, TResult> preRequestAction  = null,
                                                                              Func <TRequest, HttpRequestMessage> postRequestAction = null)
            where TResult : class
        {
            var requestHandler = new ApiCommandHandler <TRequest, TResult>(request, postRequestAction, preRequestAction);

            return(await requestHandler.HandleRequestAsync());
        }
Esempio n. 2
0
        public static async Task <TResult> ProcessRequest <TRequest, TResult>(Dictionary <string, object> requestDictionary,
                                                                              Func <TRequest, HttpRequestMessage> postRequestAction = null,
                                                                              Func <HttpResponseMessage, TResult> preRequestAction  = null)
            where TResult : class
        {
            var request = new ApiCallCommand <TRequest, TResult>((TRequest)requestDictionary["RequestObject"]);

            requestDictionary.Remove("RequestObject");
            var requestType = typeof(ApiCallCommand <TRequest, TResult>);

            foreach (var item in requestDictionary)
            {
                var property = requestType.GetProperty(item.Key);
                requestType.GetProperty(item.Key).SetValue(request, item.Value);
            }

            var requestHandler = new ApiCommandHandler <TRequest, TResult>(request, postRequestAction, preRequestAction);

            return(await requestHandler.HandleRequestAsync());
        }