/// <summary> /// Generates a http response based on the specified <see cref="response"/> object and send it to the client /// </summary> /// <param name="response"></param> /// <param name="context"></param> private static void SendWADOResponse(WADOResponse response, HttpListenerContext context) { context.Response.StatusCode = (int)HttpStatusCode.OK; // TODO: what does http protocol say about how error that occurs after OK status has been sent should be handled? context.Response.ContentType = response.ContentType; if (response.Output == null) { context.Response.ContentLength64 = 0; } else { context.Response.ContentLength64 = response.Output.Length; Stream output = context.Response.OutputStream; output.Write(response.Output, 0, response.Output.Length); } }
private static void HandleRequest(HttpListenerContext context) { WADORequestProcessorStatistics statistics = new WADORequestProcessorStatistics("Image Streaming"); statistics.TotalProcessTime.Start(); LogRequest(context); using (WADORequestTypeHandlerManager handlerManager = new WADORequestTypeHandlerManager()) { string requestType = context.Request.QueryString["requestType"]; IWADORequestTypeHandler typeHandler = handlerManager.GetHandler(requestType); WADORequestTypeHandlerContext ctx = new WADORequestTypeHandlerContext { HttpContext = context, ServerAE = UriHelper.GetServerAE(context) }; using (WADOResponse response = typeHandler.Process(ctx)) { if (response != null) { statistics.TransmissionSpeed.Start(); SendWADOResponse(response, context); statistics.TransmissionSpeed.End(); if (response.Output != null) { statistics.TransmissionSpeed.SetData(response.Output.Length); } } } } statistics.TotalProcessTime.End(); StatisticsLogger.Log(LogLevel.Debug, statistics); }