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; } }