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
        protected void Application_Start(object sender, EventArgs e)
        {
            if (_xameleonConfiguration.DebugMode == "yes") _DEBUG = true;

            if (_xameleonConfiguration.UseMemcached == "yes")
            {
                _useMemCached = true;
                _memcachedClient = new Client(new MemcachedClient(), AspNetMemcachedConfiguration.GetConfig());
            }

            string baseUri = (string)_xameleonConfiguration.PreCompiledXslt.BaseUri;
            if (baseUri != String.Empty)
                baseUri = (string)_xameleonConfiguration.PreCompiledXslt.BaseUri;
            else
                baseUri = "~";

            _xsltTransformationManager = new XsltTransformationManager(_processor, _transform, _resolver, _serializer);
            _xsltTransformationManager.HashAlgorithm = _hashAlgorithm;
            _resolver.Credentials = CredentialCache.DefaultCredentials;
            _namedXsltHashtable = _xsltTransformationManager.NamedXsltHashtable;

            string hashkey = (string)_xameleonConfiguration.BaseSettings.ObjectHashKey;
            Application["hashkey"] = hashkey;

            foreach (PreCompiledXslt xslt in _xameleonConfiguration.PreCompiledXslt)
            {
                string localBaseUri = (string)_xameleonConfiguration.PreCompiledXslt.BaseUri;
                if (localBaseUri == String.Empty)
                    localBaseUri = baseUri;
                Uri xsltUri = new Uri(HttpContext.Current.Server.MapPath(localBaseUri + xslt.Uri));
                _xsltTransformationManager.Compiler.BaseUri = xsltUri;
                _xsltTransformationManager.AddTransformer(xslt.Name, xsltUri, _resolver, xslt.InitialMode, xslt.InitialTemplate);
                _namedXsltHashtable.Add(xslt.Name, xsltUri);
                if (xslt.UseAsBaseXslt == "yes")
                {
                    _baseXsltContext = new BaseXsltContext(xsltUri, XsltTransformationManager.GenerateNamedETagKey(xslt.Name, xsltUri), xslt.Name);
                }
            }

            _xsltTransformationManager.SetBaseXsltContext(_baseXsltContext);

            foreach (XsltParam xsltParam in _xameleonConfiguration.GlobalXsltParam)
            {
                _globalXsltParams[xsltParam.Name] = (string)xsltParam.Select;
            }

            if (_memcachedClient != null)
                Application["as_memcached"] = _memcachedClient;
            Application["as_usememcached"] = _useMemCached;
            Application["as_xslTransformationManager"] = _xsltTransformationManager;
            Application["as_namedXsltHashtable"] = _namedXsltHashtable;
            Application["as_globalXsltParams"] = _globalXsltParams;
            Application["as_debug"] = _DEBUG;

        }
        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 #5
0
 public void BeginProcess(Context context, XsltTransformationManager manager, TextWriter writer, TransformServiceAsyncResult result)
 {
     BeginProcess(context, manager, writer, manager.BaseXsltName, result);
 }
Example #6
0
        protected void Application_Start(object sender, EventArgs e)
        {

            if (_xameleonConfiguration.UseMemcached == "yes")
            {
                _useMemCached = true;
                _memcachedClient = new MemcachedClient();
                _pool = SockIOPool.GetInstance();
                List<string> serverList = new List<string>();
                foreach (MemcachedServer server in _memcachedConfiguration.MemcachedServerCollection)
                {
                    serverList.Add(server.IP + ":" + server.Port);
                }
                _pool.SetServers(serverList.ToArray());

                if (_memcachedConfiguration.UseCompression != null && _memcachedConfiguration.UseCompression == "yes")
                    _memcachedClient.EnableCompression = true;
                else
                    _memcachedClient.EnableCompression = false;

                MemcachedPoolConfig poolConfig = (MemcachedPoolConfig)_memcachedConfiguration.PoolConfig;
                _pool.InitConnections = (int)poolConfig.InitConnections;
                _pool.MinConnections = (int)poolConfig.MinConnections;
                _pool.MaxConnections = (int)poolConfig.MaxConnections;
                _pool.SocketConnectTimeout = (int)poolConfig.SocketConnectTimeout;
                _pool.SocketTimeout = (int)poolConfig.SocketConnect;
                _pool.MaintenanceSleep = (int)poolConfig.MaintenanceSleep;
                _pool.Failover = (bool)poolConfig.Failover;
                _pool.Nagle = (bool)poolConfig.Nagle;
                _pool.Initialize();
            }

            string baseUri = (string)_xameleonConfiguration.PreCompiledXslt.BaseUri;
            if (baseUri != String.Empty)
                baseUri = (string)_xameleonConfiguration.PreCompiledXslt.BaseUri;
            else
                baseUri = "~";

            _xsltTransformationManager = new XsltTransformationManager(_processor, _transform, _resolver, _serializer);
            _xsltTransformationManager.HashAlgorithm = _hashAlgorithm;
            _resolver.Credentials = CredentialCache.DefaultCredentials;
            _namedXsltHashtable = _xsltTransformationManager.NamedXsltHashtable;

            string hashkey = (string)_xameleonConfiguration.BaseSettings.ObjectHashKey;
            Application["hashkey"] = hashkey;

            foreach (PreCompiledXslt xslt in _xameleonConfiguration.PreCompiledXslt)
            {
                string localBaseUri = (string)_xameleonConfiguration.PreCompiledXslt.BaseUri;
                if (localBaseUri == String.Empty)
                    localBaseUri = baseUri;
                Uri xsltUri = new Uri(HttpContext.Current.Server.MapPath(localBaseUri + xslt.Uri));
                _xsltTransformationManager.Compiler.BaseUri = xsltUri;
                _xsltTransformationManager.AddTransformer(xslt.Name, xsltUri, _resolver, xslt.InitialMode, xslt.InitialTemplate);
                _namedXsltHashtable.Add(xslt.Name, xsltUri);
                if (xslt.UseAsBaseXslt == "yes")
                {
                    _baseXsltContext = new BaseXsltContext(xsltUri, XsltTransformationManager.GenerateNamedETagKey(xslt.Name, xsltUri), xslt.Name);
                }
            }

            _xsltTransformationManager.SetBaseXsltContext(_baseXsltContext);

            foreach (XsltParam xsltParam in _xameleonConfiguration.GlobalXsltParam)
            {
                _globalXsltParams[xsltParam.Name] = (string)xsltParam.Select;
            }

            if (_memcachedClient != null)
                Application["appStart_memcached"] = _memcachedClient;
            Application["appStart_usememcached"] = _useMemCached;
            Application["appStart_xslTransformationManager"] = _xsltTransformationManager;
            Application["appStart_namedXsltHashtable"] = _namedXsltHashtable;
            Application["appStart_globalXsltParams"] = _globalXsltParams;

        }