Exemplo n.º 1
0
        public override void Render(HttpContextBase httpContext, Bistro.Controllers.IContext requestContext)
        {
            if (httpContext.Session != null)
            {
                foreach (object key in httpContext.Session.Keys)
                {
                    if (requestContext.Contains(key))
                    {
                        throw new ApplicationException(String.Format("{0} is present on both the Session and the Request.", key));
                    }

                    requestContext.Add(key.ToString(), httpContext.Session[key.ToString()]);
                }
            }

            try
            {
                TextReader reader = manager.RenderTemplate(requestContext.Response.RenderTarget, (IDictionary <string, object>)requestContext);
                char[]     buffer = new char[4096];
                int        count  = 0;
                while ((count = reader.ReadBlock(buffer, 0, 4096)) > 0)
                {
                    httpContext.Response.Write(buffer, 0, count);
                }
            }
            catch (Exception ex)
            {
                httpContext.Response.StatusCode = 500;
                httpContext.Response.Write(RenderException(requestContext.Response.RenderTarget, ex, true));
            }
        }
Exemplo n.º 2
0
        public string runTemplate(NDjango.Interfaces.ITemplateManager manager, string templateName, IDictionary <string, object> context)
        {
            Stopwatch stopwatch = new Stopwatch();
            string    retStr    = "";

            stopwatch.Start();
            for (int i = 0; i < 1; i++)
            {
                var template = manager.RenderTemplate(templateName, context);
                retStr = template.ReadToEnd();
            }
            using (TextWriter stream = System.IO.File.AppendText("Timers.txt"))
                stream.WriteLine(Name + "," + stopwatch.ElapsedTicks);
            return(retStr);
        }