Пример #1
0
 public override string ToString()
 {
     using (var writer = new StringBlockWriter(CultureInfo.InvariantCulture))
     {
         _action(writer);
         return writer.ToString();
     }
 }
 public static MvcHtmlString Action(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues)
 {
     using (var writer = new StringBlockWriter(CultureInfo.CurrentCulture))
     {
         ActionHelper(htmlHelper, actionName, controllerName, routeValues, writer);
         return MvcHtmlString.Create(writer.ToString());
     }
 }
 public static MvcHtmlString Partial(this HtmlHelper htmlHelper, string partialViewName, object model, ViewDataDictionary viewData)
 {
     using (var writer = new StringBlockWriter(CultureInfo.CurrentCulture))
     {
         htmlHelper.RenderPartialInternal(partialViewName, viewData, model, writer, ViewEngines.Engines);
         return MvcHtmlString.Create(writer.ToString());
     }
 }
 public static async Task<MvcHtmlString> PartialAsync(this HtmlHelper htmlHelper, string partialViewName, object model, ViewDataDictionary viewData)
 {
     using (var writer = new StringBlockWriter(CultureInfo.CurrentCulture))
     {
         await htmlHelper.RenderPartialInternalAsync(partialViewName, viewData, model, writer, ViewEngines.Engines).ConfigureAwait(false);
         return MvcHtmlString.Create(writer.ToString());
     }
 }
Пример #5
0
 public override string ToString()
 {
     using (var writer = new StringBlockWriter(CultureInfo.InvariantCulture))
     {
         _action(writer);
         return(writer.ToString());
     }
 }
Пример #6
0
        private async Task <HelperResult> RenderPageCoreAsync(string path, bool isLayoutPage, object[] data)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "path");
            }
            WebPageContext pageContext;
            var            subPage = PrepareRenderPage(path, isLayoutPage, data, out pageContext);
            var            writer  = new StringBlockWriter(_currentWriter.FormatProvider);
            await subPage.ExecutePageHierarchyAsync(pageContext, writer).ConfigureAwait(false);

            return(new HelperResult(writer.CopyTo));
        }
Пример #7
0
        public void PushContext(WebPageContext pageContext, TextWriter writer)
        {
            _currentWriter   = writer;
            PageContext      = pageContext;
            pageContext.Page = this;

            InitializePage();

            // Create a temporary writer
            _tempWriter = new StringBlockWriter(CultureInfo.InvariantCulture);

            // Render the page into it
            OutputStack.Push(_tempWriter);
            SectionWritersStack.Push(new Dictionary <string, SectionWriter>(StringComparer.OrdinalIgnoreCase));

            // If the body is defined in the ViewData, remove it and store it on the instance
            // so that it won't affect rendering of partial pages when they call VerifyRenderedBodyOrSections
            if (PageContext.BodyAction != null)
            {
                _body = PageContext.BodyAction;
                PageContext.BodyAction = null;
            }
        }
 public static async Task<MvcHtmlString> ActionAsync(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues)
 {
     using (var writer = new StringBlockWriter(CultureInfo.CurrentCulture))
     {
         await ActionHelperAsync(htmlHelper, actionName, controllerName, routeValues, writer).ConfigureAwait(false);
         return MvcHtmlString.Create(writer.ToString());
     }
 }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            if (filterContext.IsChildAction)
            {
                // Skip validation and caching if there's no caching on the server for this action. It's ok to 
                // explicitly disable caching for a child action, but it will be ignored if the parent action
                // is using caching.
                if (IsServerSideCacheDisabled())
                {
                    return;
                }

                ValidateChildActionConfiguration();

                // Already actively being captured? (i.e., cached child action inside of cached child action)
                // Realistically, this needs write substitution to do properly (including things like authentication)
                if (GetChildActionFilterFinishCallback(filterContext) != null)
                {
                    throw new InvalidOperationException(MvcResources.OutputCacheAttribute_CannotNestChildCache);
                }

                // Already cached?
                string uniqueId = GetChildActionUniqueId(filterContext);
                string cachedValue = ChildActionCacheInternal.Get(uniqueId) as string;
                if (cachedValue != null)
                {
                    filterContext.Result = new ContentResult() { Content = cachedValue };
                    return;
                }

                // Swap in a new TextWriter so we can capture the output
                var cachingWriter = new StringBlockWriter(CultureInfo.InvariantCulture);
                TextWriter originalWriter = filterContext.HttpContext.Response.Output;
                filterContext.HttpContext.Response.Output = cachingWriter;

                // Set a finish callback to clean up
                SetChildActionFilterFinishCallback(filterContext, wasException =>
                {
                    // Restore original writer
                    filterContext.HttpContext.Response.Output = originalWriter;

                    // Grab output and write it
                    string capturedText = cachingWriter.ToString();
                    filterContext.HttpContext.Response.Write(capturedText);

                    // Only cache output if this wasn't an error
                    if (!wasException)
                    {
                        ChildActionCacheInternal.Add(uniqueId, capturedText, DateTimeOffset.UtcNow.AddSeconds(Duration));
                    }
                });
            }
        }
Пример #10
0
 private async Task<HelperResult> RenderPageCoreAsync(string path, bool isLayoutPage, object[] data)
 {
     if (String.IsNullOrEmpty(path))
     {
         throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "path");
     }
     WebPageContext pageContext;
     var subPage = PrepareRenderPage(path, isLayoutPage, data, out pageContext);
     var writer = new StringBlockWriter(_currentWriter.FormatProvider);
     await subPage.ExecutePageHierarchyAsync(pageContext, writer).ConfigureAwait(false);
     return new HelperResult(writer.CopyTo);
 }
Пример #11
0
        public void PushContext(WebPageContext pageContext, TextWriter writer)
        {
            _currentWriter = writer;
            PageContext = pageContext;
            pageContext.Page = this;

            InitializePage();

            // Create a temporary writer
            _tempWriter = new StringBlockWriter(CultureInfo.InvariantCulture);

            // Render the page into it
            OutputStack.Push(_tempWriter);
            SectionWritersStack.Push(new Dictionary<string, SectionWriter>(StringComparer.OrdinalIgnoreCase));

            // If the body is defined in the ViewData, remove it and store it on the instance
            // so that it won't affect rendering of partial pages when they call VerifyRenderedBodyOrSections
            if (PageContext.BodyAction != null)
            {
                _body = PageContext.BodyAction;
                PageContext.BodyAction = null;
            }
        }
 private void Write(StringBlockWriter writer)
 {
     Flush();
     _parts.Add(writer);
 }
 private void Write(StringBlockWriter writer)
 {
     Flush();
     _parts.Add(writer);
 }