/// <summary> /// Execute command. /// </summary> public void Execute() { _log.TraceMethodCall("Execute()", _command.CommandText); QueryStart(); using (IDbConnection connection = _factory.OpenConnection(_connection)) { using (IDbCommand command = CreateExecutableCommand(connection)) { try { command.ExecuteNonQuery(); } catch (Exception e) { _log.DebugFormat(e, "Execute(): Text: '{0}', Type: {1}", _command.CommandText, _command.CommandType); throw; } finally { QueryFinished(command); } } } }
private Yield ResponseHandler(DreamMessage request, Result <DreamMessage> response, HttpListenerContext httpContext, Action <string> activity, Result result) { DreamMessage item = null; request.Close(); try { activity("begin ResponseHandler"); item = response.HasException ? DreamMessage.InternalError(response.Exception) : response.Value; // set status _log.TraceMethodCall("ResponseHandler: Status", item.Status, httpContext.Request.HttpMethod, httpContext.Request.Url); httpContext.Response.StatusCode = (int)item.Status; // remove internal headers item.Headers.DreamTransport = null; item.Headers.DreamPublicUri = null; // add out-going headers if (item.Headers.Server == null) { item.Headers.Server = ServerSignature; } // create stream for response (this will force the creation of the 'Content-Length' header as well) Stream stream = item.ToStream(); // copy headers httpContext.Response.Headers.Clear(); foreach (KeyValuePair <string, string> pair in item.Headers) { _log.TraceMethodCall("SendHttpResponse: Header", pair.Key, pair.Value); HttpUtil.AddHeader(httpContext.Response, pair.Key, pair.Value); } // add set-cookie headers to response if (item.HasCookies) { foreach (DreamCookie cookie in item.Cookies) { httpContext.Response.Headers.Add(DreamHeaders.SET_COOKIE, cookie.ToSetCookieHeader()); } } // disable keep alive behavior httpContext.Response.KeepAlive = false; // send message stream long size = item.ContentLength; if (((size == -1) || (size > 0)) && (stream != Stream.Null)) { activity(string.Format("pre CopyStream ({0} bytes)", size)); yield return(CopyStream(activity, stream, httpContext.Response.OutputStream, size, new Result <long>(DreamHostService.MAX_REQUEST_TIME)).CatchAndLog(_log)); activity("post CopyStream"); } activity("pre Flush"); httpContext.Response.OutputStream.Flush(); activity("post Flush"); result.Return(); activity("end ResponseHandler"); } finally { activity(null); if (item != null) { item.Close(); } httpContext.Response.Close(); } }
//--- Methods --- void IHttpHandler.ProcessRequest(HttpContext httpContext) { var key = new object(); DreamMessage request = null; try { string verb = httpContext.Request.HttpMethod; XUri requestUri = HttpUtil.FromHttpContext(httpContext); _env.AddActivityDescription(key, string.Format("Incoming: {0} {1}", verb, requestUri.ToString())); _log.DebugMethodCall("ProcessRequest", verb, requestUri); // create request message request = new DreamMessage(DreamStatus.Ok, new DreamHeaders(httpContext.Request.Headers), MimeType.New(httpContext.Request.ContentType), httpContext.Request.ContentLength, httpContext.Request.InputStream); DreamUtil.PrepareIncomingMessage(request, httpContext.Request.ContentEncoding, string.Format("{0}://{1}{2}", httpContext.Request.Url.Scheme, httpContext.Request.Url.Authority, httpContext.Request.ApplicationPath), httpContext.Request.UserHostAddress, httpContext.Request.UserAgent); requestUri = requestUri.AuthorizeDreamInParams(request, _dreamInParamAuthtoken); // process message Result <DreamMessage> response = _env.SubmitRequestAsync(verb, requestUri, httpContext.User, request, new Result <DreamMessage>(TimeSpan.MaxValue)).Block(); request.Close(); DreamMessage item = response.HasException ? DreamMessage.InternalError(response.Exception) : response.Value; // set status if (_log.IsDebugEnabled) { _log.DebugMethodCall("ProcessRequest[Status]", item.Status, String.Format("{0}{1}", httpContext.Request.Url.GetLeftPart(UriPartial.Authority), httpContext.Request.RawUrl).Replace("/index.aspx", "/")); } httpContext.Response.StatusCode = (int)item.Status; // remove internal headers item.Headers.DreamTransport = null; item.Headers.DreamPublicUri = null; // create stream for response (this will force the creation of the 'Content-Length' header as well) Stream stream = item.ToStream(); // copy headers foreach (KeyValuePair <string, string> pair in item.Headers) { _log.TraceMethodCall("ProcessRequest[Header]", pair.Key, pair.Value); httpContext.Response.AppendHeader(pair.Key, pair.Value); } // add set-cookie headers to response if (item.HasCookies) { foreach (DreamCookie cookie in item.Cookies) { httpContext.Response.AppendHeader(DreamHeaders.SET_COOKIE, cookie.ToSetCookieHeader()); } } // send message stream long size = item.ContentLength; if (((size == -1) || (size > 0)) && (stream != Stream.Null)) { stream.CopyToStream(httpContext.Response.OutputStream, size, new Result <long>(TimeSpan.MaxValue)).Wait(); } item.Close(); } catch (Exception ex) { _log.ErrorExceptionMethodCall(ex, "CommonRequestHandler"); if (request != null) { request.Close(); } if (httpContext != null) { httpContext.Response.Close(); } } finally { _env.RemoveActivityDescription(key); } }