Example #1
0
        public void BeginProcess(Context context, XsltTransformationManager manager, TextWriter writer, String xsltName, TransformServiceAsyncResult result)
        {
            XsltTransformer transformer = manager.GetTransformer(xsltName);

            if (context.XsltParams.Count > 0)
            {
                foreach (DictionaryEntry param in context.XsltParams)
                {
                    string name = (string)param.Key;
                    transformer.SetParameter(new QName("", "", name), new XdmValue((XdmItem)XdmAtomicValue.wrapExternalObject(param.Value)));
                }
            }

            Uri requestXmlUri = new Uri(context.RequestUri);

            transformer.InputXmlResolver = manager.Resolver;
            transformer.InitialContextNode = manager.GetXdmNode(context.RequestXmlETag, context.RequestUri);

            Serializer destination = manager.Serializer;
            destination.SetOutputWriter(writer);

            lock (transformer)
            {
                transformer.Run(destination);
            }

            result.CompleteCall();
        }
Example #2
0
    public void ProcessRequest(HttpContext context) {

      _requestMethod = context.Request.HttpMethod;
      _writer = context.Response.Output;
      _context = context;
      _processor = (Processor)context.Application["processor"];
      _compiler = (XsltCompiler)context.Application["compiler"];
      _serializer = (Serializer)context.Application["serializer"];
      _resolver = (XmlUrlResolver)context.Application["resolver"];
      _globalXsltParams = (Hashtable)context.Application["globalXsltParams"];
      _sessionXsltParams = (Hashtable)context.Application["sessionXsltParams"];
      _requestXsltParams = (Hashtable)context.Application["requestXsltParams"];
      Hashtable xsltParams = new Hashtable();
      foreach (DictionaryEntry param in _globalXsltParams) {
        xsltParams[param.Key] = param.Value;
      }
      foreach (DictionaryEntry param in _sessionXsltParams) {
        xsltParams[param.Key] = param.Value;
      }
      foreach (DictionaryEntry param in _requestXsltParams) {
        xsltParams[param.Key] = param.Value;
      }
      _transformContext = new Context(context, _processor, _compiler, _serializer, _resolver, xsltParams);

      switch (_requestMethod) {

        case "GET": {
            new Transform().Process(_transformContext);
            break;
          }
        case "PUT": {
            new Transform().Process(_transformContext);
            break;
          }
        case "POST": {
            new Transform().Process(_transformContext);
            break;
          }
        case "DELETE": {
            new Transform().Process(_transformContext);
            break;
          }
        default: {
            new Transform().Process(_transformContext);
            break;
          }
      }
    }
Example #3
0
    public void Process(Context context) {


      XsltTransformer transformer = context.XslTransformationManager.GetTransformer(context.XslTransformationManager.BaseXsltUriHash, context.XslTransformationManager.BaseXsltUri);

      if (context.XsltParams.Count > 0) {
        foreach (DictionaryEntry param in context.XsltParams) {
          string name = (string)param.Key;
          transformer.SetParameter(new QName("", "", name), new XdmValue((XdmItem)XdmAtomicValue.wrapExternalObject(param.Value)));
        }
      }

      transformer.InputXmlResolver = context.XslTransformationManager.Resolver;
      transformer.InitialContextNode = context.XslTransformationManager.GetXdmNode("foo", new Uri(HttpContext.Current.Request.MapPath(HttpContext.Current.Request.CurrentExecutionFilePath)));

      lock (transformer) {
        transformer.Run(context.Destination);
      }
    }
        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 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;
        }
Example #6
0
 public void BeginProcess(Context context, XsltTransformationManager manager, TextWriter writer, TransformServiceAsyncResult result)
 {
     BeginProcess(context, manager, writer, manager.BaseXsltName, result);
 }
Example #7
0
        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>");
            }

        }