protected StringBuilder WriteDebugOutput(Context context, XsltTransformationManager xsltTransformationManager, StringBuilder builder, bool CONTENT_IS_MEMCACHED) { builder.Append(CreateNode("Request_File_ETag", context.ETag)); builder.Append(CreateNode("CompilerBaseUri", xsltTransformationManager.Compiler.BaseUri)); builder.Append(CreateNode("Compiler", xsltTransformationManager.Compiler.GetHashCode())); //foreach(System.Reflection.PropertyInfo t in HttpContext.Current.GetType().GetProperties()){ // //} builder.Append(CreateNode("Serializer", xsltTransformationManager.Serializer.GetHashCode())); builder.Append(CreateNode("BaseXsltName", xsltTransformationManager.BaseXsltName)); builder.Append(CreateNode("BaseXsltUri", xsltTransformationManager.BaseXsltUri)); builder.Append(CreateNode("BaseXsltUriHash", xsltTransformationManager.BaseXsltUriHash)); builder.Append(CreateNode("UseMemcached", (bool)_context.Application["appStart_usememcached"])); builder.Append(CreateNode("Transform", xsltTransformationManager.Transform.GetHashCode())); builder.Append(CreateNode("Resolver", xsltTransformationManager.Resolver.GetHashCode())); builder.Append(CreateNode("XslTransformationManager", xsltTransformationManager.GetHashCode())); builder.Append(CreateNode("GlobalXsltParms", _xsltParams.GetHashCode())); builder.Append(CreateNode("Processor", _xslTransformationManager.Processor.GetHashCode())); builder.Append(CreateNode("RequestXmlSourceExecutionFilePath", _context.Request.MapPath(HttpContext.Current.Request.CurrentExecutionFilePath))); builder.Append(CreateNode("RequestUrl", context.RequestUri, true)); builder.Append(CreateNode("RequestIsMemcached", CONTENT_IS_MEMCACHED)); builder.Append(CreateNode("RequestHashcode", context.GetRequestHashcode(false))); builder.Append(CreateNode("ContextHashcode", context.GetHashCode())); builder.Append(CreateNode("ContextUri", context.RequestUri, true)); builder.Append(CreateNode("ContextHttpParamsCount", context.HttpParams.Count)); IEnumerator httpParamsEnum = context.HttpParams.GetEnumerator(); int i = 0; while (httpParamsEnum.MoveNext()) { string key = context.HttpParams.AllKeys[i].ToString(); builder.Append("<Param>"); builder.Append(CreateNode("Name", key)); builder.Append(CreateNode("Value", context.HttpParams[key])); builder.Append("</Param>"); i += 1; } Client mc = (Client)HttpContext.Current.Application["appStart_memcached"]; IDictionary stats = mc.Stats(); foreach (string key1 in stats.Keys) { builder.Append("<Key>"); builder.Append(CreateNode("Name", key1)); Hashtable values = (Hashtable)stats[key1]; foreach (string key2 in values.Keys) { builder.Append(CreateNode(key2, values[key2])); } builder.Append("</Key>"); } builder.Append(CreateNode("ContextXsltParamsCount", context.XsltParams.Count)); foreach (DictionaryEntry entry in context.XsltParams) { builder.Append(CreateNode("XsltParamName", (string)entry.Key)); builder.Append(CreateNode("XsltParamValue", (string)entry.Value)); } return builder; }
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData) { FileInfo fileInfo = new FileInfo(context.Request.MapPath(context.Request.CurrentExecutionFilePath)); _context = context; _httpMethod = _context.Request.HttpMethod; _memcachedClient = (Client)context.Application["memcached"]; _xslTransformationManager = (XsltTransformationManager)context.Application["xslTransformationManager"]; _transform = _xslTransformationManager.Transform; _xsltParams = (Hashtable)context.Application["globalXsltParams"]; _namedXsltHashtable = (Hashtable)context.Application["namedXsltHashtable"]; _transformContext = new Context(context, _hashAlgorithm, (string)context.Application["hashkey"], fileInfo, (Hashtable)_xsltParams.Clone(), fileInfo.LastWriteTimeUtc, fileInfo.Length); _transformAsyncResult = new TransformServiceAsyncResult(cb, extraData); _callback = cb; _transformAsyncResult._context = context; _builder = new StringBuilder(); _CONTENT_IS_MEMCACHED = false; _USE_MEMCACHED = (bool)context.Application["usememcached"]; bool hasXmlSourceChanged = _xslTransformationManager.HasXmlSourceChanged(_transformContext.RequestXmlETag); bool hasBaseXsltSourceChanged = _xslTransformationManager.HasBaseXsltSourceChanged(); if (_USE_MEMCACHED) { string obj = (string)_memcachedClient.Get(_transformContext.GetRequestHashcode(true)); if (obj != null && !(hasXmlSourceChanged || hasBaseXsltSourceChanged)) { _builder.Append(obj); _CONTENT_IS_MEMCACHED = true; if ((bool)context.Application["debug"]) context.Response.ContentType = "text"; else context.Response.ContentType = "text/xml"; } else { _writer = new StringWriter(_builder); _CONTENT_IS_MEMCACHED = false; } } else { _writer = new StringWriter(_builder); } if ((bool)context.Application["debug"]) { context.Response.Write("<debug>"); context.Response.Write("<file-info>"); context.Response.Write("Has Xml Changed: " + hasXmlSourceChanged + ":" + _transformContext.RequestXmlETag + "<br/>"); context.Response.Write("Has Xslt Changed: " + hasBaseXsltSourceChanged + "<br/>"); context.Response.Write("Xml ETag: " + _transformContext.GetRequestHashcode(true) + "<br/>"); context.Response.Write("XdmNode Count: " + _xslTransformationManager.GetXdmNodeHashtableCount() + "<br/>"); context.Response.Write("</file-info>"); context.Application["debugOutput"] = (string)("<DebugOutput>" + WriteDebugOutput(_transformContext, _xslTransformationManager, new StringBuilder(), _CONTENT_IS_MEMCACHED).ToString() + "</DebugOutput>"); context.Response.Write("</debug>"); } try { switch (_httpMethod) { case "GET": { if (_CONTENT_IS_MEMCACHED) { _transformAsyncResult.CompleteCall(); return _transformAsyncResult; } else { try { _transform.BeginProcess(_transformContext, context, _xslTransformationManager, _writer, _transformAsyncResult); return _transformAsyncResult; } catch (Exception e) { _exception = e; WriteError(); _transformAsyncResult.CompleteCall(); return _transformAsyncResult; } } } case "PUT": { _transform.BeginProcess(_transformContext, context, _xslTransformationManager, _writer, _transformAsyncResult); return _transformAsyncResult; } case "POST": { _transform.BeginProcess(_transformContext, context, _xslTransformationManager, _writer, _transformAsyncResult); return _transformAsyncResult; } case "DELETE": { _transform.BeginProcess(_transformContext, context, _xslTransformationManager, _writer, _transformAsyncResult); return _transformAsyncResult; } default: { _transform.BeginProcess(_transformContext, context, _xslTransformationManager, _writer, _transformAsyncResult); return _transformAsyncResult; } } } catch (Exception ex) { _exception = ex; WriteError(); _transformAsyncResult.CompleteCall(); return _transformAsyncResult; } }
protected void Application_BeginRequest(object sender, EventArgs e) { Hashtable xsltParams = (Hashtable)Application["appStart_globalXsltParams"]; FileInfo fileInfo = new FileInfo(HttpContext.Current.Request.MapPath(HttpContext.Current.Request.CurrentExecutionFilePath)); Context context = new Context(HttpContext.Current, _hashAlgorithm, (string)Application["hashkey"], fileInfo, (Hashtable)xsltParams.Clone(), fileInfo.LastWriteTimeUtc, fileInfo.Length); StringBuilder builder = new StringBuilder(); TextWriter writer = new StringWriter(builder); XsltTransformationManager xslTransformationManager = (XsltTransformationManager)Application["appStart_xslTransformationManager"]; bool CONTENT_IS_MEMCACHED = false; bool useMemCached = (bool)Application["appStart_usememcached"]; bool hasXmlSourceChanged = xslTransformationManager.HasXmlSourceChanged(context.RequestXmlETag); bool hasBaseXsltSourceChanged = xslTransformationManager.HasBaseXsltSourceChanged(); MemcachedClient memcachedClient = (MemcachedClient)Application["appStart_memcached"]; Application["memcached"] = memcachedClient; if (useMemCached) { string obj = (string)memcachedClient.Get(context.GetRequestHashcode(false)); if (obj != null && !(hasXmlSourceChanged || hasBaseXsltSourceChanged)) { builder.Append(obj); CONTENT_IS_MEMCACHED = true; } else { writer = new StringWriter(builder); CONTENT_IS_MEMCACHED = false; } } else { writer = new StringWriter(builder); } Application["debug"] = _DEBUG; Application["textWriter"] = writer; Application["stringBuilder"] = builder; Application["CONTENT_IS_MEMCACHED"] = CONTENT_IS_MEMCACHED; Application["USE_MEMCACHED"] = useMemCached; Application["xsltTransformationManager"] = xslTransformationManager; Application["namedXsltHashtable"] = (Hashtable)Application["appStart_namedXsltHashtable"]; Application["transformContext"] = context; if (_DEBUG) { HttpContext.Current.Response.Write("Has Xml Changed: " + hasXmlSourceChanged + ":" + context.RequestXmlETag + "<br/>"); HttpContext.Current.Response.Write("Has Xslt Changed: " + hasBaseXsltSourceChanged + "<br/>"); Application["debugOutput"] = (string)("<DebugOutput>" + WriteDebugOutput(context, xslTransformationManager, new StringBuilder(), CONTENT_IS_MEMCACHED).ToString() + "</DebugOutput>"); } }