public void WriteTo(TextWriter writer, IHtmlEncoder encoder) { if (Item != null) { Item.WriteTo(writer, Context); } }
/// <inheritdoc /> public void WriteTo(TextWriter writer, IHtmlEncoder encoder) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (encoder == null) { throw new ArgumentNullException(nameof(encoder)); } foreach (var entry in Entries) { if (entry == null) { continue; } var entryAsString = entry as string; if (entryAsString != null) { encoder.HtmlEncode(entryAsString, writer); } else { // Only string, IHtmlContent values can be added to the buffer. ((IHtmlContent)entry).WriteTo(writer, encoder); } } }
/// <inheritdoc /> public override void WriteTo(TextWriter writer, IHtmlEncoder encoder) { foreach (var entry in _buffer) { writer.Write(entry); } }
private void RenderEndOfFormContent() { var formContext = _viewContext.FormContext; if (formContext.HasEndOfFormContent) { var writer = _viewContext.Writer; var htmlWriter = writer as HtmlTextWriter; IHtmlEncoder htmlEncoder = null; if (htmlWriter == null) { htmlEncoder = _viewContext.HttpContext.RequestServices.GetRequiredService <IHtmlEncoder>(); } foreach (var content in formContext.EndOfFormContent) { if (htmlWriter == null) { content.WriteTo(writer, htmlEncoder); } else { htmlWriter.Write(content); } } } }
/// <summary> /// Initializes a new instance of the <see cref="ResourceResultContext" /> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="frameworkProvider">The framework provider.</param> /// <param name="serializer">The serializer.</param> /// <param name="htmlEncoder">The HTML encoder.</param> public ResourceResultContext(ILogger logger, IFrameworkProvider frameworkProvider, ISerializer serializer, IHtmlEncoder htmlEncoder) { Logger = logger; FrameworkProvider = frameworkProvider; Serializer = serializer; HtmlEncoder = htmlEncoder; }
/// <summary> /// Writes the specified <paramref name="value"/> with HTML encoding to given <paramref name="content"/>. /// </summary> /// <param name="content">The <see cref="TagHelperContent"/> to write to.</param> /// <param name="encoder">The <see cref="IHtmlEncoder"/> to use when encoding <paramref name="value"/>.</param> /// <param name="encoding">The character encoding in which the <paramref name="value"/> is written.</param> /// <param name="value">The <see cref="object"/> to write.</param> /// <returns><paramref name="content"/> after the write operation has completed.</returns> /// <remarks> /// <paramref name="value"/>s of type <see cref="Html.Abstractions.IHtmlContent"/> are written using /// <see cref="Html.Abstractions.IHtmlContent.WriteTo(System.IO.TextWriter, IHtmlEncoder)"/>. /// For all other types, the encoded result of <see cref="object.ToString"/> /// is written to the <paramref name="content"/>. /// </remarks> public static TagHelperContent Append( this TagHelperContent content, IHtmlEncoder encoder, Encoding encoding, object value) { if (content == null) { throw new ArgumentNullException(nameof(content)); } if (encoder == null) { throw new ArgumentNullException(nameof(encoder)); } if (encoding == null) { throw new ArgumentNullException(nameof(encoding)); } using (var writer = new TagHelperContentWrapperTextWriter(encoding, content)) { RazorPage.WriteTo(writer, encoder, value, escapeQuotes: true); } return content; }
public void WriteTo(TextWriter writer, IHtmlEncoder encoder) { foreach (var fragment in _fragments) { writer.Write(fragment.ToString()); } }
/// <summary> /// /// </summary> /// <param name="tagname">The tag name</param> /// <param name="htmlAttributes">A dictionary of html attributes. Values get HtmlEncoded.</param> public TagBuilder(string tagname, IDictionary<string, object> htmlAttributes) { this.TagName = tagname; this.HtmlAttributes = htmlAttributes ?? new Dictionary<string, object>(); this.encoder = (DependencyResolver.Current != null ? DependencyResolver.Current.TryGetInstance<IHtmlEncoder>() : null) ?? new HttpUtilityHtmlEncoder(); }
public BootstrapContext(ViewContext viewContext, IUrlHelper urlHelper, IHtmlEncoder htmlEncoder, ViewDataDictionary <TModel> viewData) : base(viewContext, urlHelper, htmlEncoder) { this.ViewData = viewData; this.ValidationResult = GetModelValidationResult(viewData.ModelState); this.MetadataProvider = viewContext.HttpContext.RequestServices.GetRequiredService <IModelMetadataProvider>(); }
private static void WriteTo(TextWriter writer, IHtmlEncoder encoder, string value) { if (!string.IsNullOrEmpty(value)) { encoder.HtmlEncode(value, writer); } }
public void HtmlEncodeStringToStringSmall() { IHtmlEncoder oldEncoder = HtmlEncoderOld.Default; IHtmlEncoder newEncoder = HtmlEncoder.Default; Stopwatch timer = new Stopwatch(); // warm up EncodeHtml(oldEncoder, SmallString, timer, SmallIterations); EncodeHtml(newEncoder, SmallString, timer, SmallIterations); var oldTime = EncodeHtml(oldEncoder, SmallString, timer, SmallIterations); var newTime = EncodeHtml(newEncoder, SmallString, timer, SmallIterations); var message = String.Format("HtmlEncodeStringToStringSmall: Old={0}ms, New={1}ms, Delta={2:G}%", (ulong)oldTime.TotalMilliseconds, (ulong)newTime.TotalMilliseconds, (int)((newTime.TotalMilliseconds - oldTime.TotalMilliseconds) / oldTime.TotalMilliseconds * 100)); output.WriteLine(message); oldTime = EncodeHtml(oldEncoder, LargeString, timer, LargeIterations); newTime = EncodeHtml(newEncoder, LargeString, timer, LargeIterations); message = String.Format("HtmlEncodeStringToStringLarge: Old={0}ms, New={1}ms, Delta={2:G}%", (ulong)oldTime.TotalMilliseconds, (ulong)newTime.TotalMilliseconds, (int)((newTime.TotalMilliseconds - oldTime.TotalMilliseconds) / oldTime.TotalMilliseconds * 100)); output.WriteLine(message); oldTime = EncodeHtml(oldEncoder, LargeStringThatIsNotEncoded, timer, LargeIterations); newTime = EncodeHtml(newEncoder, LargeStringThatIsNotEncoded, timer, LargeIterations); message = String.Format("HtmlEncodeStringToStringLargeNoEncoding: Old={0}ms, New={1}ms, Delta={2:G}%", (ulong)oldTime.TotalMilliseconds, (ulong)newTime.TotalMilliseconds, (int)((newTime.TotalMilliseconds - oldTime.TotalMilliseconds) / oldTime.TotalMilliseconds * 100)); output.WriteLine(message); oldTime = EncodeHtml(oldEncoder, LargeStringWithOnlyEndEncoded, timer, LargeIterations); newTime = EncodeHtml(newEncoder, LargeStringWithOnlyEndEncoded, timer, LargeIterations); message = String.Format("HtmlEncodeStringToStringLargeEndEncoding: Old={0}ms, New={1}ms, Delta={2:G}%", (ulong)oldTime.TotalMilliseconds, (ulong)newTime.TotalMilliseconds, (int)((newTime.TotalMilliseconds - oldTime.TotalMilliseconds) / oldTime.TotalMilliseconds * 100)); output.WriteLine(message); }
public void WriteTo(TextWriter writer, IHtmlEncoder encoder) { foreach (var fragment in _fragments) { fragment.WriteTo(writer, encoder); } }
public void WriteTo(TextWriter writer, IHtmlEncoder encoder) { foreach (var entry in Entries) { entry.WriteTo(writer, encoder); } }
/// <summary> /// Writes the specified <paramref name="value"/> with HTML encoding to given <paramref name="content"/>. /// </summary> /// <param name="content">The <see cref="TagHelperContent"/> to write to.</param> /// <param name="encoder">The <see cref="IHtmlEncoder"/> to use when encoding <paramref name="value"/>.</param> /// <param name="encoding">The character encoding in which the <paramref name="value"/> is written.</param> /// <param name="value">The <see cref="object"/> to write.</param> /// <returns><paramref name="content"/> after the write operation has completed.</returns> /// <remarks> /// <paramref name="value"/>s of type <see cref="Html.Abstractions.IHtmlContent"/> are written using /// <see cref="Html.Abstractions.IHtmlContent.WriteTo(System.IO.TextWriter, IHtmlEncoder)"/>. /// For all other types, the encoded result of <see cref="object.ToString"/> /// is written to the <paramref name="content"/>. /// </remarks> public static TagHelperContent Append( this TagHelperContent content, IHtmlEncoder encoder, Encoding encoding, object value) { if (content == null) { throw new ArgumentNullException(nameof(content)); } if (encoder == null) { throw new ArgumentNullException(nameof(encoder)); } if (encoding == null) { throw new ArgumentNullException(nameof(encoding)); } using (var writer = new TagHelperContentWrapperTextWriter(encoding, content)) { RazorPage.WriteTo(writer, encoder, value, escapeQuotes: true); } return(content); }
/// <summary> /// Initializes a new instance of the <see cref="HtmlHelper{TModel}"/> class. /// </summary> public HtmlHelper( IHtmlGenerator htmlGenerator, ICompositeViewEngine viewEngine, IModelMetadataProvider metadataProvider, IHtmlEncoder htmlEncoder, IUrlEncoder urlEncoder, IJavaScriptStringEncoder javaScriptStringEncoder) : base(htmlGenerator, viewEngine, metadataProvider, htmlEncoder, urlEncoder, javaScriptStringEncoder) { if (htmlGenerator == null) { throw new ArgumentNullException(nameof(htmlGenerator)); } if (viewEngine == null) { throw new ArgumentNullException(nameof(viewEngine)); } if (metadataProvider == null) { throw new ArgumentNullException(nameof(metadataProvider)); } if (htmlEncoder == null) { throw new ArgumentNullException(nameof(htmlEncoder)); } if (urlEncoder == null) { throw new ArgumentNullException(nameof(urlEncoder)); } if (javaScriptStringEncoder == null) { throw new ArgumentNullException(nameof(javaScriptStringEncoder)); } }
public MultipartFormDataSetVisitor(IHtmlEncoder htmlEncoder, Encoding encoding, String boundary) { _htmlEncoder = htmlEncoder; _encoding = encoding; _writers = new List <Action <StreamWriter> >(); _boundary = boundary; }
public EncodingFormatProvider(IFormatProvider formatProvider, IHtmlEncoder encoder) { Debug.Assert(formatProvider != null); Debug.Assert(encoder != null); _formatProvider = formatProvider; _encoder = encoder; }
/// <summary> /// Creates a new instance of <see cref="RazorTextWriter"/>. /// </summary> /// <param name="unbufferedWriter">The <see cref="TextWriter"/> to write output to when this instance /// is no longer buffering.</param> /// <param name="encoding">The character <see cref="Encoding"/> in which the output is written.</param> /// <param name="encoder">The HTML encoder.</param> public RazorTextWriter(TextWriter unbufferedWriter, Encoding encoding, IHtmlEncoder encoder) { UnbufferedWriter = unbufferedWriter; HtmlEncoder = encoder; BufferedWriter = new StringCollectionTextWriter(encoding); TargetWriter = BufferedWriter; }
/// <summary> /// Initializes a new instance of RazorViewFactory /// </summary> /// <param name="pageActivator">The <see cref="IRazorPageActivator"/> used to activate pages.</param> /// <param name="viewStartProvider">The <see cref="IViewStartProvider"/> used for discovery of _ViewStart /// pages</param> public RazorViewFactory( IRazorPageActivator pageActivator, IViewStartProvider viewStartProvider, IHtmlEncoder htmlEncoder) { _pageActivator = pageActivator; _viewStartProvider = viewStartProvider; _htmlEncoder = htmlEncoder; }
private TimeSpan EncodeHtml(IHtmlEncoder encoder, string text, Stopwatch timer, int iterations) { timer.Restart(); for (int iteration = 0; iteration < iterations; iteration++) { Ignore(encoder.HtmlEncode(text)); } return(timer.Elapsed); }
public ImageReportBlockVizualizer([NotNull] IHtmlEncoder htmlEncoder) { if (htmlEncoder == null) { throw new ArgumentNullException(nameof(htmlEncoder)); } _htmlEncoder = htmlEncoder; }
/// <summary> /// Creates a new <see cref="ImageTagHelper"/>. /// </summary> /// <param name="hostingEnvironment">The <see cref="IHostingEnvironment"/>.</param> /// <param name="cache">The <see cref="IMemoryCache"/>.</param> /// <param name="urlHelper">The <see cref="IUrlHelper"/>.</param> public ImageTagHelper( IHostingEnvironment hostingEnvironment, IMemoryCache cache, IHtmlEncoder htmlEncoder, IUrlHelper urlHelper) : base(urlHelper, htmlEncoder) { HostingEnvironment = hostingEnvironment; Cache = cache; }
/// <summary> /// Execute an individual request /// </summary> /// <param name="context"></param> public async Task ExecuteAsync(HttpContext context) { Context = context; Request = Context.Request; Response = Context.Response; Output = new StreamWriter(Response.Body, Encoding.UTF8, 4096, leaveOpen: true); HtmlEncoder = context.ApplicationServices.GetHtmlEncoder(); await ExecuteAsync(); Output.Dispose(); }
/// <summary> /// Initializes a new instance of the <see cref="HtmlHelper{TModel}"/> class. /// </summary> public HtmlHelper( [NotNull] IHtmlGenerator htmlGenerator, [NotNull] ICompositeViewEngine viewEngine, [NotNull] IModelMetadataProvider metadataProvider, [NotNull] IHtmlEncoder htmlEncoder, [NotNull] IUrlEncoder urlEncoder, [NotNull] IJavaScriptStringEncoder javaScriptStringEncoder) : base(htmlGenerator, viewEngine, metadataProvider, htmlEncoder, urlEncoder, javaScriptStringEncoder) { }
public TagBuilder(string tagName, [NotNull] IHtmlEncoder htmlEncoder) { if (string.IsNullOrEmpty(tagName)) { throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "tagName"); } TagName = tagName; Attributes = new SortedDictionary <string, string>(StringComparer.OrdinalIgnoreCase); _htmlEncoder = htmlEncoder; }
/// <summary> /// HTML-encodes a string and writes the result to the supplied output. /// </summary> /// <remarks> /// The encoded value is also safe for inclusion inside an HTML attribute /// as long as the attribute value is surrounded by single or double quotes. /// </remarks> public static void HtmlEncode(this IHtmlEncoder htmlEncoder, string value, TextWriter output) { if (htmlEncoder == null) { throw new ArgumentNullException(nameof(htmlEncoder)); } if (!String.IsNullOrEmpty(value)) { htmlEncoder.HtmlEncode(value, 0, value.Length, output); } }
public void InstantiateHtmlEncoderWithAntiXss() { var locatorMock = new Mock <IServiceLocator>(); var factory = new Factory(locatorMock.Object); IHtmlEncoder encoder = factory.InstantiateHtmlEncoder(); Assert.NotNull(encoder); Assert.NotNull(encoder as AntiXssEncoder); locatorMock.Verify(l => l.GetInstance <IHtmlEncoder>(), Times.Once()); }
/// <summary> /// Creates a new <see cref="ScriptTagHelper"/>. /// </summary> /// <param name="logger">The <see cref="ILogger{ScriptTagHelper}"/>.</param> /// <param name="hostingEnvironment">The <see cref="IHostingEnvironment"/>.</param> /// <param name="cache">The <see cref="IMemoryCache"/>.</param> /// <param name="htmlEncoder">The <see cref="IHtmlEncoder"/>.</param> /// <param name="javaScriptEncoder">The <see cref="IJavaScriptStringEncoder"/>.</param> public ScriptTagHelper( ILogger<ScriptTagHelper> logger, IHostingEnvironment hostingEnvironment, IMemoryCache cache, IHtmlEncoder htmlEncoder, IJavaScriptStringEncoder javaScriptEncoder) { Logger = logger; HostingEnvironment = hostingEnvironment; Cache = cache; HtmlEncoder = htmlEncoder; JavaScriptEncoder = javaScriptEncoder; }
/// <summary> /// If the specified <paramref name="writer"/> is a <see cref="StringCollectionTextWriter"/> the contents /// are copied. It is just written to the <paramref name="writer"/> otherwise. /// </summary> /// <param name="writer">The <see cref="TextWriter"/> to which the content must be copied/written.</param> /// <param name="encoder">The <see cref="IHtmlEncoder"/> to encode the copied/written content.</param> public void CopyTo(TextWriter writer, IHtmlEncoder encoder) { var targetStringCollectionWriter = writer as StringCollectionTextWriter; if (targetStringCollectionWriter != null) { targetStringCollectionWriter.Content.Append(Content); } else { Content.WriteTo(writer, encoder); } }
public static string HtmlContentToString(IHtmlContent content, IHtmlEncoder encoder = null) { if (encoder == null) { encoder = new CommonTestEncoder(); } using (var writer = new StringWriter()) { content.WriteTo(writer, encoder); return writer.ToString(); } }
public static string HtmlContentToString(IHtmlContent content, IHtmlEncoder encoder = null) { if (encoder == null) { encoder = new CommonTestEncoder(); } using (var writer = new StringWriter()) { content.WriteTo(writer, encoder); return(writer.ToString()); } }
public DefaultAntiforgery( IOptions<AntiforgeryOptions> antiforgeryOptionsAccessor, IAntiforgeryTokenGenerator tokenGenerator, IAntiforgeryTokenSerializer tokenSerializer, IAntiforgeryTokenStore tokenStore, IHtmlEncoder htmlEncoder) { _options = antiforgeryOptionsAccessor.Options; _tokenGenerator = tokenGenerator; _tokenSerializer = tokenSerializer; _tokenStore = tokenStore; _htmlEncoder = htmlEncoder; }
/// <summary> /// Creates a new <see cref="ScriptTagHelper"/>. /// </summary> /// <param name="logger">The <see cref="ILogger{ScriptTagHelper}"/>.</param> /// <param name="hostingEnvironment">The <see cref="IHostingEnvironment"/>.</param> /// <param name="cache">The <see cref="IMemoryCache"/>.</param> /// <param name="htmlEncoder">The <see cref="IHtmlEncoder"/>.</param> /// <param name="javaScriptEncoder">The <see cref="IJavaScriptStringEncoder"/>.</param> public ScriptTagHelper( ILogger <ScriptTagHelper> logger, IHostingEnvironment hostingEnvironment, IMemoryCache cache, IHtmlEncoder htmlEncoder, IJavaScriptStringEncoder javaScriptEncoder) { Logger = logger; HostingEnvironment = hostingEnvironment; Cache = cache; HtmlEncoder = htmlEncoder; JavaScriptEncoder = javaScriptEncoder; }
/// <summary> /// Writes the specified <paramref name="value"/> with HTML encoding to given <paramref name="content"/>. /// </summary> /// <param name="content">The <see cref="TagHelperContent"/> to write to.</param> /// <param name="encoder">The <see cref="IHtmlEncoder"/> to use when encoding <paramref name="value"/>.</param> /// <param name="encoding">The character encoding in which the <paramref name="value"/> is written.</param> /// <param name="value">The <see cref="object"/> to write.</param> /// <returns><paramref name="content"/> after the write operation has completed.</returns> /// <remarks> /// <paramref name="value"/>s of type <see cref="Rendering.HtmlString"/> are written without encoding and /// <see cref="HelperResult.WriteTo"/> is invoked for <see cref="HelperResult"/> types. For all other types, /// the encoded result of <see cref="object.ToString"/> is written to the <paramref name="content"/>. /// </remarks> public static TagHelperContent Append( [NotNull] this TagHelperContent content, [NotNull] IHtmlEncoder encoder, [NotNull] Encoding encoding, object value) { using (var writer = new TagHelperContentWrapperTextWriter(encoding, content)) { RazorPage.WriteTo(writer, encoder, value, escapeQuotes: true); } return(content); }
public DefaultAntiforgery( IOptions <AntiforgeryOptions> antiforgeryOptionsAccessor, IAntiforgeryTokenGenerator tokenGenerator, IAntiforgeryTokenSerializer tokenSerializer, IAntiforgeryTokenStore tokenStore, IHtmlEncoder htmlEncoder) { _options = antiforgeryOptionsAccessor.Value; _tokenGenerator = tokenGenerator; _tokenSerializer = tokenSerializer; _tokenStore = tokenStore; _htmlEncoder = htmlEncoder; }
internal AntiForgeryWorker([NotNull] IAntiForgeryTokenSerializer serializer, [NotNull] AntiForgeryOptions config, [NotNull] IAntiForgeryTokenStore tokenStore, [NotNull] IAntiForgeryTokenGenerator generator, [NotNull] IAntiForgeryTokenValidator validator, [NotNull] IHtmlEncoder htmlEncoder) { _serializer = serializer; _config = config; _tokenStore = tokenStore; _generator = generator; _validator = validator; _htmlEncoder = htmlEncoder; }
/// <summary> /// Method invoked to produce content from the <see cref="HelperResult"/>. /// </summary> /// <param name="writer">The <see cref="TextWriter"/> instance to write to.</param> /// <param name="encoder">The <see cref="IHtmlEncoder"/> to encode the content.</param> public virtual void WriteTo(TextWriter writer, IHtmlEncoder encoder) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (encoder == null) { throw new ArgumentNullException(nameof(encoder)); } _asyncAction(writer).GetAwaiter().GetResult(); }
/// <inheritdoc /> public void WriteTo(TextWriter writer, IHtmlEncoder encoder) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (encoder == null) { throw new ArgumentNullException(nameof(encoder)); } encoder.HtmlEncode(_input, writer); }
/// <summary> /// Creates a new <see cref="HtmlLocalizer"/>. /// </summary> /// <param name="localizer">The <see cref="IStringLocalizer"/> to read strings from.</param> /// <param name="encoder">The <see cref="IHtmlEncoder"/>.</param> public HtmlLocalizer(IStringLocalizer localizer, IHtmlEncoder encoder) { if (localizer == null) { throw new ArgumentNullException(nameof(localizer)); } if (encoder == null) { throw new ArgumentNullException(nameof(encoder)); } _localizer = localizer; _encoder = encoder; }
/// <summary> /// Initializes a new instance of <see cref="RazorView"/> /// </summary> /// <param name="viewEngine">The <see cref="IRazorViewEngine"/> used to locate Layout pages.</param> /// <param name="pageActivator">The <see cref="IRazorPageActivator"/> used to activate pages.</param> /// <param name="viewStartProvider">The <see cref="IViewStartProvider"/> used for discovery of _ViewStart /// <param name="razorPage">The <see cref="IRazorPage"/> instance to execute.</param> /// <param name="htmlEncoder">The HTML encoder.</param> /// <param name="isPartial">Determines if the view is to be executed as a partial.</param> /// pages</param> public RazorView( IRazorViewEngine viewEngine, IRazorPageActivator pageActivator, IViewStartProvider viewStartProvider, IRazorPage razorPage, IHtmlEncoder htmlEncoder, bool isPartial) { _viewEngine = viewEngine; _pageActivator = pageActivator; _viewStartProvider = viewStartProvider; RazorPage = razorPage; _htmlEncoder = htmlEncoder; IsPartial = isPartial; }
public GutekScriptTagHelper(ILogger<GutekScriptTagHelper> logger , IHostingEnvironment env , IMemoryCache cache , IHtmlEncoder htmlEncoder , IJavaScriptStringEncoder javaScriptEncoder , IUrlHelper urlHelper) : base(urlHelper, htmlEncoder) { Logger = logger; HostingEnvironment = env; Cache = cache; JavaScriptEncoder = javaScriptEncoder; logger.LogInformation("Initializing Gutek Script Tag Helper"); }
public OpenIdConnectMiddlewareForTestingAuthenticate( RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IUrlEncoder encoder, IServiceProvider services, IOptions<SharedAuthenticationOptions> sharedOptions, OpenIdConnectOptions options, IHtmlEncoder htmlEncoder, OpenIdConnectHandler handler = null ) : base(next, dataProtectionProvider, loggerFactory, encoder, services, sharedOptions, options, htmlEncoder) { _handler = handler; }
/// <summary> /// Creates a new <see cref="HtmlLocalizer"/>. /// </summary> /// <param name="localizerFactory">The <see cref="IStringLocalizerFactory"/>.</param> /// <param name="encoder">The <see cref="IHtmlEncoder"/>.</param> public HtmlLocalizerFactory(IStringLocalizerFactory localizerFactory, IHtmlEncoder encoder) { if (localizerFactory == null) { throw new ArgumentNullException(nameof(localizerFactory)); } if (encoder == null) { throw new ArgumentNullException(nameof(encoder)); } _factory = localizerFactory; _encoder = encoder; }
/// <summary> /// Creates a new <see cref="WebpackDevServerLinkTagHelper"/>. /// </summary> /// <param name="logger">The <see cref="ILogger{ScriptTagHelper}"/>.</param> /// <param name="hostingEnvironment">The <see cref="IHostingEnvironment"/>.</param> /// <param name="cache">The <see cref="IMemoryCache"/>.</param> /// <param name="htmlEncoder">The <see cref="IHtmlEncoder"/>.</param> /// <param name="javaScriptEncoder">The <see cref="IJavaScriptStringEncoder"/>.</param> /// <param name="urlHelper">The <see cref="IUrlHelper"/>.</param> public WebpackDevServerLinkTagHelper( ILogger<WebpackDevServerLinkTagHelper> logger, IHostingEnvironment hostingEnvironment, IMemoryCache cache, IHtmlEncoder htmlEncoder, IJavaScriptStringEncoder javaScriptEncoder, IUrlHelper urlHelper, IOptions<DevelopmentSettings> options) : base(urlHelper, htmlEncoder) { Logger = logger; HostingEnvironment = hostingEnvironment; Cache = cache; JavaScriptEncoder = javaScriptEncoder; devSettings = options.Value; }
/// <summary> /// Generates an HTML view for a directory. /// </summary> public virtual Task GenerateContentAsync(HttpContext context, IEnumerable<IFileInfo> contents) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (contents == null) { throw new ArgumentNullException(nameof(contents)); } if (_htmlEncoder == null) { _htmlEncoder = context.ApplicationServices.GetHtmlEncoder(); } context.Response.ContentType = TextHtmlUtf8; if (Helpers.IsHeadMethod(context.Request.Method)) { // HEAD, no response body return Constants.CompletedTask; } PathString requestPath = context.Request.PathBase + context.Request.Path; var builder = new StringBuilder(); builder.AppendFormat( @"<!DOCTYPE html> <html lang=""{0}"">", CultureInfo.CurrentUICulture.TwoLetterISOLanguageName); builder.AppendFormat(@" <head> <title>{0} {1}</title>", HtmlEncode(Resources.HtmlDir_IndexOf), HtmlEncode(requestPath.Value)); builder.Append(@" <style> body { font-family: ""Segoe UI"", ""Segoe WP"", ""Helvetica Neue"", 'RobotoRegular', sans-serif; font-size: 14px;} header h1 { font-family: ""Segoe UI Light"", ""Helvetica Neue"", 'RobotoLight', ""Segoe UI"", ""Segoe WP"", sans-serif; font-size: 28px; font-weight: 100; margin-top: 5px; margin-bottom: 0px;} #index { border-collapse: separate; border-spacing: 0; margin: 0 0 20px; } #index th { vertical-align: bottom; padding: 10px 5px 5px 5px; font-weight: 400; color: #a0a0a0; text-align: center; } #index td { padding: 3px 10px; } #index th, #index td { border-right: 1px #ddd solid; border-bottom: 1px #ddd solid; border-left: 1px transparent solid; border-top: 1px transparent solid; box-sizing: border-box; } #index th:last-child, #index td:last-child { border-right: 1px transparent solid; } #index td.length, td.modified { text-align:right; } a { color:#1ba1e2;text-decoration:none; } a:hover { color:#13709e;text-decoration:underline; } </style> </head> <body> <section id=""main"">"); builder.AppendFormat(@" <header><h1>{0} <a href=""/"">/</a>", HtmlEncode(Resources.HtmlDir_IndexOf)); string cumulativePath = "/"; foreach (var segment in requestPath.Value.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)) { cumulativePath = cumulativePath + segment + "/"; builder.AppendFormat(@"<a href=""{0}"">{1}/</a>", HtmlEncode(cumulativePath), HtmlEncode(segment)); } builder.AppendFormat(CultureInfo.CurrentUICulture, @"</h1></header> <table id=""index"" summary=""{0}""> <thead> <tr><th abbr=""{1}"">{1}</th><th abbr=""{2}"">{2}</th><th abbr=""{3}"">{4}</th></tr> </thead> <tbody>", HtmlEncode(Resources.HtmlDir_TableSummary), HtmlEncode(Resources.HtmlDir_Name), HtmlEncode(Resources.HtmlDir_Size), HtmlEncode(Resources.HtmlDir_Modified), HtmlEncode(Resources.HtmlDir_LastModified)); foreach (var subdir in contents.Where(info => info.IsDirectory)) { builder.AppendFormat(@" <tr class=""directory""> <td class=""name""><a href=""./{0}/"">{0}/</a></td> <td></td> <td class=""modified"">{1}</td> </tr>", HtmlEncode(subdir.Name), HtmlEncode(subdir.LastModified.ToString(CultureInfo.CurrentCulture))); } foreach (var file in contents.Where(info => !info.IsDirectory)) { builder.AppendFormat(@" <tr class=""file""> <td class=""name""><a href=""./{0}"">{0}</a></td> <td class=""length"">{1}</td> <td class=""modified"">{2}</td> </tr>", HtmlEncode(file.Name), HtmlEncode(file.Length.ToString("n0", CultureInfo.CurrentCulture)), HtmlEncode(file.LastModified.ToString(CultureInfo.CurrentCulture))); } builder.Append(@" </tbody> </table> </section> </body> </html>"); string data = builder.ToString(); byte[] bytes = Encoding.UTF8.GetBytes(data); context.Response.ContentLength = bytes.Length; return context.Response.Body.WriteAsync(bytes, 0, bytes.Length); }
/// <summary> /// Abstract base class constructor. /// </summary> /// /// <param name="options"> /// Options for controlling the operation. /// </param> /// <param name="encoder"> /// The encoder. /// </param> public FormatDefault(DomRenderingOptions options, IHtmlEncoder encoder) { DomRenderingOptions = options; MergeDefaultOptions(); HtmlEncoder = encoder ?? HtmlEncoders.Default; }
public SmidgeScriptTagHelper(SmidgeHelper smidgeHelper, BundleManager bundleManager, IHtmlEncoder encoder) { _smidgeHelper = smidgeHelper; _bundleManager = bundleManager; _encoder = encoder; }
public void WriteTo(TextWriter writer, IHtmlEncoder encoder) { foreach (IHtmlContent htmlContent in this.htmlContents) htmlContent.WriteTo(writer, encoder); }
/// <summary> /// Initializes a new instance of the <see cref="GlimpseConfiguration" /> class. /// </summary> /// <param name="frameworkProvider">The framework provider.</param> /// <param name="endpointConfiguration">The resource endpoint configuration.</param> /// <param name="clientScripts">The client scripts collection.</param> /// <param name="logger">The logger.</param> /// <param name="defaultRuntimePolicy">The default runtime policy.</param> /// <param name="htmlEncoder">The Html encoder.</param> /// <param name="persistenceStore">The persistence store.</param> /// <param name="inspectors">The inspectors collection.</param> /// <param name="resources">The resources collection.</param> /// <param name="serializer">The serializer.</param> /// <param name="tabs">The tabs collection.</param> /// <param name="runtimePolicies">The runtime policies collection.</param> /// <param name="defaultResource">The default resource.</param> /// <param name="proxyFactory">The proxy factory.</param> /// <param name="messageBroker">The message broker.</param> /// <param name="endpointBaseUri">The endpoint base Uri.</param> /// <param name="timerStrategy">The timer strategy.</param> /// <param name="runtimePolicyStrategy">The runtime policy strategy.</param> /// <exception cref="System.ArgumentNullException">An exception is thrown if any parameter is <c>null</c>.</exception> public GlimpseConfiguration( IFrameworkProvider frameworkProvider, ResourceEndpointConfiguration endpointConfiguration, ICollection<IClientScript> clientScripts, ILogger logger, RuntimePolicy defaultRuntimePolicy, IHtmlEncoder htmlEncoder, IPersistenceStore persistenceStore, ICollection<IInspector> inspectors, ICollection<IResource> resources, ISerializer serializer, ICollection<ITab> tabs, ICollection<IDisplay> displays, ICollection<IRuntimePolicy> runtimePolicies, IResource defaultResource, IProxyFactory proxyFactory, IMessageBroker messageBroker, string endpointBaseUri, Func<IExecutionTimer> timerStrategy, Func<RuntimePolicy> runtimePolicyStrategy) { if (frameworkProvider == null) { throw new ArgumentNullException("frameworkProvider"); } if (endpointConfiguration == null) { throw new ArgumentNullException("endpointConfiguration"); } if (logger == null) { throw new ArgumentNullException("logger"); } if (htmlEncoder == null) { throw new ArgumentNullException("htmlEncoder"); } if (persistenceStore == null) { throw new ArgumentNullException("persistenceStore"); } if (clientScripts == null) { throw new ArgumentNullException("clientScripts"); } if (resources == null) { throw new ArgumentNullException("inspectors"); } if (serializer == null) { throw new ArgumentNullException("serializer"); } if (tabs == null) { throw new ArgumentNullException("tabs"); } if (displays == null) { throw new ArgumentNullException("displays"); } if (runtimePolicies == null) { throw new ArgumentNullException("runtimePolicies"); } if (defaultResource == null) { throw new ArgumentNullException("defaultResource"); } if (proxyFactory == null) { throw new ArgumentNullException("proxyFactory"); } if (messageBroker == null) { throw new ArgumentNullException("messageBroker"); } if (endpointBaseUri == null) { throw new ArgumentNullException("endpointBaseUri"); } if (timerStrategy == null) { throw new ArgumentNullException("timerStrategy"); } if (runtimePolicyStrategy == null) { throw new ArgumentNullException("runtimePolicyStrategy"); } Logger = logger; ClientScripts = clientScripts; FrameworkProvider = frameworkProvider; HtmlEncoder = htmlEncoder; PersistenceStore = persistenceStore; Inspectors = inspectors; ResourceEndpoint = endpointConfiguration; Resources = resources; Serializer = serializer; Tabs = tabs; Displays = displays; RuntimePolicies = runtimePolicies; DefaultRuntimePolicy = defaultRuntimePolicy; DefaultResource = defaultResource; ProxyFactory = proxyFactory; MessageBroker = messageBroker; EndpointBaseUri = endpointBaseUri; TimerStrategy = timerStrategy; RuntimePolicyStrategy = runtimePolicyStrategy; }
public void WriteTo(TextWriter writer, IHtmlEncoder encoder) { writer.Write(_value); }
public void WriteTo(TextWriter writer, IHtmlEncoder encoder) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (encoder == null) { throw new ArgumentNullException(nameof(encoder)); } var formatProvider = new EncodingFormatProvider(_formatProvider, encoder); writer.Write(string.Format(formatProvider, _format, _args)); }