Example #1
0
        /// <summary>
        /// Render the html and adds it to the cache.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="partialRequest">The partial request.</param>
        /// <param name="content">The content.</param>
        /// <param name="templateModel">The template model.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="cacheKey">The cache key.</param>
        protected virtual void RenderAndAddToCache(HtmlHelper helper, PartialRequest partialRequest, IContent content, TemplateModel templateModel, ICacheableSettings settings, string cacheKey)
        {
            using (var cacheWriter = new StringWriter())
            {
                var currentWriter = helper.ViewContext.Writer;
                helper.ViewContext.Writer = cacheWriter;
                DefaultRenderer.Render(helper, partialRequest, content, templateModel);
                var html = cacheWriter.ToString();
                currentWriter.Write(html);
                helper.ViewContext.Writer = currentWriter;

                if (helper.ViewContext.HttpContext.Error == null)
                {
                    InsertToCache(html);
                }
            }

            void InsertToCache(string html)
            {
                if (settings.MaxTimeInCache == TimeSpan.Zero)
                {
                    Cache.Insert(cacheKey, html, new CacheEvictionPolicy(null, MasterCacheKeys));
                }
                else
                {
                    Cache.Insert(cacheKey, html, new CacheEvictionPolicy(settings.MaxTimeInCache, CacheTimeoutType.Absolute, null, MasterCacheKeys));
                }
            }
        }
        public void Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel)
        {
            var output = _htmlCache.GetOrAdd(CreateCacheKey(contentData, templateModel), context =>
            {
                AddDependecies(context, contentData);
                var buffer = new StringBuilder();
                using (var writer = new StringWriter(buffer))
                {
                    var orgWriter = helper.ViewContext.Writer;
                    try
                    {
                        helper.ViewContext.Writer = writer;
                        _defaultRenderer.Render(helper, partialRequestHandler, contentData, templateModel);
                    }
                    finally
                    {
                        helper.ViewContext.Writer = orgWriter;
                    }
                }

                return(buffer.ToString());
            });

            helper.ViewContext.Writer.Write(output);
        }
Example #3
0
 public void Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel)
 {
     if (contentData is IContent content)
     {
         helper.ViewContext.TrackContent(content);
     }
     _defaultRenderer.Render(helper, partialRequestHandler, contentData, templateModel);
 }
        public HtmlTag HtmlPartial(PartialRequest request)
        {
            var inner = new HtmlTag("div");
            for (var i = 0; i < 5; i++)
            {
                inner.Add("p").Text(Guid.NewGuid().ToString());
            }

            return inner;
        }
Example #5
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: protected void handleRequest(org.jboss.netty.buffer.ChannelBuffer buffer, final org.jboss.netty.channel.Channel channel)
        protected internal virtual void HandleRequest(ChannelBuffer buffer, Channel channel)
        {
            sbyte?continuation = ReadContinuationHeader(buffer, channel);

            if (continuation == null)
            {
                return;
            }
            if (continuation.Value == ChunkingChannelBuffer.CONTINUATION_MORE)
            {
                PartialRequest partialRequest = _partialRequests[channel];
                if (partialRequest == null)
                {
                    // This is the first chunk in a multi-chunk request
                    RequestType    type         = GetRequestContext(buffer.readByte());
                    RequestContext context      = ReadContext(buffer);
                    ChannelBuffer  targetBuffer = MapSlave(channel, context);
                    partialRequest            = new PartialRequest(this, type, context, targetBuffer);
                    _partialRequests[channel] = partialRequest;
                }
                partialRequest.Add(buffer);
            }
            else
            {
                PartialRequest partialRequest = _partialRequests.Remove(channel);
                RequestType    type;
                RequestContext context;
                ChannelBuffer  targetBuffer;
                ChannelBuffer  bufferToReadFrom;
                ChannelBuffer  bufferToWriteTo;
                if (partialRequest == null)
                {
                    // This is the one and single chunk in the request
                    type             = GetRequestContext(buffer.readByte());
                    context          = ReadContext(buffer);
                    targetBuffer     = MapSlave(channel, context);
                    bufferToReadFrom = buffer;
                    bufferToWriteTo  = targetBuffer;
                }
                else
                {
                    // This is the last chunk in a multi-chunk request
                    type         = partialRequest.Type;
                    context      = partialRequest.Context;
                    targetBuffer = partialRequest.Buffer;
                    partialRequest.Add(buffer);
                    bufferToReadFrom = targetBuffer;
                    bufferToWriteTo  = ChannelBuffers.dynamicBuffer();
                }

                bufferToWriteTo.clear();
                ChunkingChannelBuffer chunkingBuffer = NewChunkingBuffer(bufferToWriteTo, channel, _chunkSize, InternalProtocolVersion, _applicationProtocolVersion);
                SubmitSilent(_targetCallExecutor, new TargetCaller(this, type, channel, context, chunkingBuffer, bufferToReadFrom));
            }
        }
Example #6
0
        /// <summary>
        /// Renders from the cache or adds the result to the cache.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="partialRequest">The partial request.</param>
        /// <param name="content">The content.</param>
        /// <param name="templateModel">The template model.</param>
        /// <param name="settings">The settings.</param>
        protected virtual void RenderFromOrAddToCache(HtmlHelper helper, PartialRequest partialRequest, IContent content, TemplateModel templateModel, ICacheableSettings settings)
        {
            string cacheKey = KeyCreator.GenerateCacheKey(settings, helper, content);

            if (Cache.TryGet(cacheKey, ReadStrategy.Immediate, out string cachedHtml))
            {
                helper.ViewContext.Writer.Write(cachedHtml);
            }
            else
            {
                RenderAndAddToCache(helper, partialRequest, content, templateModel, settings, cacheKey);
            }
        }
Example #7
0
 /// <summary>
 /// Renders the contentData using the wrapped renderer and catches common, non-critical exceptions.
 /// </summary>
 public void Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel)
 {
     try
     {
         _mvcRenderer.Render(helper, partialRequestHandler, contentData, templateModel);
     }
     catch (Exception) when(HttpContext.Current.IsDebuggingEnabled)
     {
         //If debug="true" we assume a developer is making the request
         throw;
     }
     catch (NullReferenceException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (ArgumentException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (ApplicationException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (InvalidOperationException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (NotImplementedException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (IOException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (EPiServerException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (XFormException ex)
     {
         HandlerError(helper, contentData, ex);
     }
 }
Example #8
0
        /// <summary>
        /// Tries to render the HTML from cache, falls back to the default renderer if the content is not cacheable.
        /// </summary>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <param name="partialRequest">The partial request.</param>
        /// <param name="contentData">The content data.</param>
        /// <param name="templateModel">The template model.</param>
        public void RenderFromCache(HtmlHelper htmlHelper, PartialRequest partialRequest, IContentData contentData, TemplateModel templateModel)
        {
            if (SettingsService.TryGetSettingsFromContentData(contentData, out ICacheableSettings settings) &&
                IsCacheEnabled() &&
                contentData is IContent content)
            {
                RenderFromOrAddToCache(htmlHelper, partialRequest, content, templateModel, settings);
            }
            else
            {
                DefaultRenderer.Render(htmlHelper, partialRequest, contentData, templateModel);
            }

            bool IsCacheEnabled()
            {
                if (PageEditing.PageIsInEditMode)
                {
                    return(settings.IsCacheEnabled && settings.CacheInCmsEditor);
                }
                return(settings.IsCacheEnabled);
            }
        }
 /// <summary>
 /// Renders the contentData using the wrapped renderer and catches common, non-critical exceptions.
 /// </summary>
 public void Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel)
 {
     try
     {
         _mvcRenderer.Render(helper, partialRequestHandler, contentData, templateModel);
     }
     catch (NullReferenceException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             //If debug="true" we assume a developer is making the request
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (ArgumentException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (ApplicationException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (InvalidOperationException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (NotImplementedException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (IOException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (EPiServerException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (XFormException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
 }
Example #10
0
 public void Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel)
 {
     try
     {
         _mvcRenderer.Render(helper, partialRequestHandler, contentData, templateModel);
     }
     catch (NullReferenceException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (ArgumentException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (ApplicationException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (InvalidOperationException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (NotImplementedException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (IOException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (EPiServerException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
 }
Example #11
0
 public void Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel)
 {
     CacheableContentRendererService.RenderFromCache(helper, partialRequestHandler, contentData, templateModel);
 }