SetContent->SetHtmlContent

This commit is contained in:
ryanbrandenburg 2016-03-25 16:15:58 -07:00
parent 5ddb17d2fe
commit 5fe284a486
7 changed files with 20 additions and 20 deletions

View File

@ -58,18 +58,18 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
{ {
throw new ArgumentNullException(nameof(output)); throw new ArgumentNullException(nameof(output));
} }
IHtmlContent content = null; IHtmlContent content = null;
if (Enabled) if (Enabled)
{ {
var key = GenerateKey(context); var key = GenerateKey(context);
MemoryCacheEntryOptions options; MemoryCacheEntryOptions options;
while (content == null) while (content == null)
{ {
Task<IHtmlContent> result = null; Task<IHtmlContent> result = null;
if (!MemoryCache.TryGetValue(key, out result)) if (!MemoryCache.TryGetValue(key, out result))
{ {
var tokenSource = new CancellationTokenSource(); var tokenSource = new CancellationTokenSource();
@ -81,13 +81,13 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
options.AddExpirationToken(new CancellationChangeToken(tokenSource.Token)); options.AddExpirationToken(new CancellationChangeToken(tokenSource.Token));
var tcs = new TaskCompletionSource<IHtmlContent>(); var tcs = new TaskCompletionSource<IHtmlContent>();
// The returned value is ignored, we only do this so that // The returned value is ignored, we only do this so that
// the compiler doesn't complain about the returned task // the compiler doesn't complain about the returned task
// not being awaited // not being awaited
var localTcs = MemoryCache.Set(key, tcs.Task, options); var localTcs = MemoryCache.Set(key, tcs.Task, options);
try try
{ {
// The entry is set instead of assigning a value to the // The entry is set instead of assigning a value to the
// task so that the expiration options are are not impacted // task so that the expiration options are are not impacted
@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
// Clear the contents of the "cache" element since we don't want to render it. // Clear the contents of the "cache" element since we don't want to render it.
output.SuppressOutput(); output.SuppressOutput();
output.Content.SetContent(content); output.Content.SetHtmlContent(content);
} }
// Internal for unit testing // Internal for unit testing

View File

@ -35,12 +35,12 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
/// <param name="htmlEncoder">The <see cref="HtmlEncoder"/>.</param> /// <param name="htmlEncoder">The <see cref="HtmlEncoder"/>.</param>
public DistributedCacheTagHelper( public DistributedCacheTagHelper(
IDistributedCacheTagHelperService distributedCacheService, IDistributedCacheTagHelperService distributedCacheService,
HtmlEncoder htmlEncoder) HtmlEncoder htmlEncoder)
: base(htmlEncoder) : base(htmlEncoder)
{ {
_distributedCacheService = distributedCacheService; _distributedCacheService = distributedCacheService;
} }
/// <summary> /// <summary>
/// Gets the <see cref="IMemoryCache"/> instance used to cache workers. /// Gets the <see cref="IMemoryCache"/> instance used to cache workers.
/// </summary> /// </summary>
@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
/// </summary> /// </summary>
[HtmlAttributeName(NameAttributeName)] [HtmlAttributeName(NameAttributeName)]
public string Name { get; set; } public string Name { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{ {
@ -85,9 +85,9 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
// Clear the contents of the "cache" element since we don't want to render it. // Clear the contents of the "cache" element since we don't want to render it.
output.SuppressOutput(); output.SuppressOutput();
output.Content.SetContent(content); output.Content.SetHtmlContent(content);
} }
// Internal for unit testing // Internal for unit testing
internal DistributedCacheEntryOptions GetDistributedCacheEntryOptions() internal DistributedCacheEntryOptions GetDistributedCacheEntryOptions()
{ {

View File

@ -82,11 +82,11 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
if (childContent.IsWhiteSpace) if (childContent.IsWhiteSpace)
{ {
// Provide default label text since there was nothing useful in the Razor source. // Provide default label text since there was nothing useful in the Razor source.
output.Content.SetContent(tagBuilder.InnerHtml); output.Content.SetHtmlContent(tagBuilder.InnerHtml);
} }
else else
{ {
output.Content.SetContent(childContent); output.Content.SetHtmlContent(childContent);
} }
} }
} }

View File

@ -264,7 +264,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
{ {
// Only HrefInclude is specified. Don't render the original tag. // Only HrefInclude is specified. Don't render the original tag.
output.TagName = null; output.TagName = null;
output.Content.SetContent(HtmlString.Empty); output.Content.SetHtmlContent(HtmlString.Empty);
} }
} }
@ -279,7 +279,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
BuildFallbackBlock(builder); BuildFallbackBlock(builder);
} }
output.PostElement.SetContent(builder); output.PostElement.SetHtmlContent(builder);
} }
private void BuildGlobbedLinkTags(TagHelperAttributeList attributes, TagHelperContent builder) private void BuildGlobbedLinkTags(TagHelperAttributeList attributes, TagHelperContent builder)

View File

@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
BuildFallbackBlock(output.Attributes, builder); BuildFallbackBlock(output.Attributes, builder);
} }
output.PostElement.SetContent(builder); output.PostElement.SetHtmlContent(builder);
} }
private void BuildGlobbedScriptTags( private void BuildGlobbedScriptTags(

View File

@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
if (tagBuilder != null) if (tagBuilder != null)
{ {
// Overwrite current Content to ensure expression result round-trips correctly. // Overwrite current Content to ensure expression result round-trips correctly.
output.Content.SetContent(tagBuilder.InnerHtml); output.Content.SetHtmlContent(tagBuilder.InnerHtml);
output.MergeAttributes(tagBuilder); output.MergeAttributes(tagBuilder);
} }

View File

@ -86,11 +86,11 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
if (childContent.IsWhiteSpace) if (childContent.IsWhiteSpace)
{ {
// Provide default label text since there was nothing useful in the Razor source. // Provide default label text since there was nothing useful in the Razor source.
output.Content.SetContent(tagBuilder.InnerHtml); output.Content.SetHtmlContent(tagBuilder.InnerHtml);
} }
else else
{ {
output.Content.SetContent(childContent); output.Content.SetHtmlContent(childContent);
} }
} }
} }