public override void Render(HttpContextBase httpContext, 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
            {
                var templateTuple = manager.RenderTemplate(requestContext.Response.RenderTarget, (IDictionary<string, object>)requestContext);
                manager = templateTuple.Item1;
                TextReader reader = templateTuple.Item2;
                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));
            }
        }
示例#2
0
        public override void Render(HttpContextBase httpContext, 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
            {
                var templateTuple = manager.RenderTemplate(requestContext.Response.RenderTarget, (IDictionary <string, object>)requestContext);
                manager = templateTuple.Item1;
                TextReader reader = templateTuple.Item2;
                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.Write(RenderException(requestContext.Response.RenderTarget, ex, true));
            }
        }
示例#3
0
 public void Setup()
 {
     provider = new TemplateManagerProvider()
         .WithLoader(new Loader())
         .WithTag("non-nested", new TestDescriptor.SimpleNonNestedTag())
         .WithTag("nested", new TestDescriptor.SimpleNestedTag())
         .WithTag("url", new TestUrlTag())
         ;
     provider = FilterManager.Initialize(provider);
     manager = provider.GetNewManager();
 }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NDjangoHandle"/> class.
        /// </summary>
        /// <param name="application">The application.</param>
        public NDjangoHandle(HttpApplication application)
        {
            this.application          = application;
            application.BeginRequest += new EventHandler(application_BeginRequest);

            lock (handleLock)
            {
                if (!initialized)
                {
                    engine      = new NDjangoViewEngine();
                    initialized = true;
                }
            }

            manager = engine.Provider.GetNewManager();
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NDjangoHandle"/> class.
        /// </summary>
        /// <param name="application">The application.</param>
        public NDjangoHandle(HttpApplication application)
        {
            this.application = application;
            application.BeginRequest += new EventHandler(application_BeginRequest);

            lock (handleLock)
            {
                if (!initialized)
                {
                    engine = new NDjangoViewEngine();
                    initialized = true;
                }
            }

            manager = engine.Provider.GetNewManager();
        }
示例#6
0
 /// <summary>
 /// Updates the manager with the one returned by rendering operations
 /// </summary>
 /// <param name="manager">The manager.</param>
 /// <param name="viewContext">The view context.</param>
 protected virtual void ReturnManager(NDjango.Interfaces.ITemplateManager manager, ViewContext viewContext)
 {
     viewContext.HttpContext.Items[NDjangoHandle.MANAGER_HANDLE] = manager;
 }
示例#7
0
 /// <summary>
 /// Handles the EndRequest event of the application control. This event handler is
 /// used to update local instance of the manager.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 void application_EndRequest(object sender, EventArgs e)
 {
     manager = (NDjango.Interfaces.ITemplateManager)application.Context.Items[MANAGER_HANDLE];
 }
示例#8
0
 /// <summary>
 /// Handles the EndRequest event of the application control. This event handler is
 /// used to update local instance of the manager.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 void application_EndRequest(object sender, EventArgs e)
 {
     manager = (NDjango.Interfaces.ITemplateManager)application.Context.Items[MANAGER_HANDLE];
 }