protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { Console.WriteLine("test connection request recieved"); System.Diagnostics.Trace.WriteLine("test my trace logger"); // GET operations get their data through the query string, while POST operations expect a JSON // object being put in the body. string queryData = request.Method == HttpMethod.Get ? SerializationHelpers.ConvertQueryStringToJson(request.RequestUri.Query) : await request.Content.ReadAsStringAsync(); // GetDependencyScope() calls IDependencyResolver.BeginScope internally. request.GetDependencyScope(); this.ApplyHeaders(request); try { var _requestOrchestrator = Bootstrapper.Container.GetInstance <WebApiRequestOrchestrator>(); var orchestrator = _requestOrchestrator; var result = orchestrator.GetConnectionInfo(); return(CreateResponse(result, typeof(ConnectionInfo), HttpStatusCode.OK, request)); } catch (Exception ex) { var response = WebApiErrorResponseBuilder.CreateErrorResponseOrNull(ex, request); if (response != null) { return(response); } throw; } }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { System.Diagnostics.Trace.WriteLine("test my trace request logger"); string rawQueryName = request.GetRouteData().Values["query"].ToString(); var queryName = rawQueryName.Replace("Query", string.Empty); logger.Log("Recieved Query: " + queryName); if (!this.queryTypes.ContainsKey(queryName)) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.NotFound, RequestMessage = request }); } // GET operations get their data through the query string, while POST operations expect a JSON // object being put in the body. string queryData = request.Method == HttpMethod.Get ? SerializationHelpers.ConvertQueryStringToJson(request.RequestUri.Query) : await request.Content.ReadAsStringAsync(); QueryInfo info = this.queryTypes[queryName]; Type handlerType = typeof(IQueryHandler <,>).MakeGenericType(info.QueryType, info.ResultType); // GetDependencyScope() calls IDependencyResolver.BeginScope internally. request.GetDependencyScope(); this.ApplyHeaders(request); try { using (AsyncScopedLifestyle.BeginScope(Bootstrapper.Container)) { var queryProcessor = Bootstrapper.Container.GetInstance <IQueryProcessor>(); dynamic query = DeserializeQuery(request, queryData, info.QueryType); var result = queryProcessor.SubmitBatch(query); return(CreateResponse(result, info.ResultType, HttpStatusCode.OK, request)); } } catch (Exception ex) { //Console.WriteLine(ex.Message); System.Diagnostics.Trace.WriteLine("test my trace exception logger"); System.Diagnostics.Trace.WriteLine(ex.Message); System.Diagnostics.Trace.WriteLine(ex); Console.WriteLine(ex); var response = WebApiErrorResponseBuilder.CreateErrorResponseOrNull(ex, request); if (response != null) { logger.Log("Error Translated", ex); return(response); } logger.Log(LoggingEventType.Fatal, "Unknown Error", ex); throw; } }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { string commandName = request.GetRouteData().Values["command"].ToString(); logger.Log("Recieved Command: " + commandName); if (request.Method != HttpMethod.Post) { return(request.CreateErrorResponse(HttpStatusCode.MethodNotAllowed, "The requested resource does not support http method '" + request.Method + "'.")); } if (!this.commandTypes.ContainsKey(commandName)) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.NotFound, RequestMessage = request }); } Type commandType = this.commandTypes[commandName]; string requestData = await request.Content.ReadAsStringAsync(); Type handlerType = typeof(ICommandHandler <>).MakeGenericType(commandType); // GetDependencyScope() calls IDependencyResolver.BeginScope internally. request.GetDependencyScope(); this.ApplyHeaders(request); //dynamic handler = this.handlerFactory.Invoke(handlerType); try { var logger = Bootstrapper.Container.GetInstance <ILogger>(); using (AsyncScopedLifestyle.BeginScope(Bootstrapper.Container)) { //var commandVessel = DeserializeCommandVessel(request, requestData); var routingKey = request.Headers.GetValueOrNull("eventRoutingKey"); var eventPublisher = Bootstrapper.Container.GetInstance <EventPublisher>(); eventPublisher.RoutingKey = routingKey; dynamic command = DeserializeCommand(request, requestData, commandType); var commandProcessor = Bootstrapper.Container.GetInstance <ICommandProcessor>(); commandProcessor.SubmitBatch(command); //handler.Handle(command); return(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, RequestMessage = request }); } } catch (Exception ex) { var response = WebApiErrorResponseBuilder.CreateErrorResponseOrNull(ex, request); if (response != null) { logger.Log("Error Translated", ex); return(response); } logger.Log(LoggingEventType.Fatal, "Unknown Error", ex); throw; } }