Exemplo n.º 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();
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
 public void BeginProcess(Context context, XsltTransformationManager manager, TextWriter writer, TransformServiceAsyncResult result)
 {
     BeginProcess(context, manager, writer, manager.BaseXsltName, result);
 }