Exemplo n.º 1
1
        /// <summary>
        /// Initializes a new instance of <see cref="MvcForm"/>.
        /// </summary>
        /// <param name="viewContext">The <see cref="ViewContext"/>.</param>
        /// <param name="htmlEncoder">The <see cref="HtmlEncoder"/>.</param>
        public MvcForm(ViewContext viewContext, HtmlEncoder htmlEncoder)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException(nameof(viewContext));
            }

            if (htmlEncoder == null)
            {
                throw new ArgumentNullException(nameof(htmlEncoder));
            }

            _viewContext = viewContext;
            _htmlEncoder = htmlEncoder;
        }
Exemplo n.º 2
0
 public void WriteTo(TextWriter writer, HtmlEncoder encoder)
 {
     foreach (var fragment in _fragments)
     {
         fragment.WriteTo(writer, encoder);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new instance of <see cref="ViewBufferTextWriter"/>.
        /// </summary>
        /// <param name="buffer">The <see cref="ViewBuffer"/> for buffered output.</param>
        /// <param name="encoding">The <see cref="System.Text.Encoding"/>.</param>
        /// <param name="htmlEncoder">The HTML encoder.</param>
        /// <param name="inner">
        /// The inner <see cref="TextWriter"/> to write output to when this instance is no longer buffering.
        /// </param>
        public ViewBufferTextWriter(ViewBuffer buffer, Encoding encoding, HtmlEncoder htmlEncoder, TextWriter inner)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            if (htmlEncoder == null)
            {
                throw new ArgumentNullException(nameof(htmlEncoder));
            }

            if (inner == null)
            {
                throw new ArgumentNullException(nameof(inner));
            }

            Buffer = buffer;
            Encoding = encoding;
            _htmlEncoder = htmlEncoder;
            _inner = inner;
        }
 /// <summary>
 /// Creates a new <see cref="CacheTagHelper"/>.
 /// </summary>
 /// <param name="distributedCacheService">The <see cref="IDistributedCacheTagHelperService"/>.</param>
 /// <param name="htmlEncoder">The <see cref="HtmlEncoder"/>.</param>
 public DistributedCacheTagHelper(
     IDistributedCacheTagHelperService distributedCacheService,
     HtmlEncoder htmlEncoder)
     : base(htmlEncoder)
 {
     _distributedCacheService = distributedCacheService;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RazorViewEngine" />.
        /// </summary>
        public RazorViewEngine(
            IRazorPageFactoryProvider pageFactory,
            IRazorPageActivator pageActivator,
            HtmlEncoder htmlEncoder,
            IOptions<RazorViewEngineOptions> optionsAccessor,
            ILoggerFactory loggerFactory)
        {
            _options = optionsAccessor.Value;

            if (_options.ViewLocationFormats.Count == 0)
            {
                throw new ArgumentException(
                    Resources.FormatViewLocationFormatsIsRequired(nameof(RazorViewEngineOptions.ViewLocationFormats)),
                    nameof(optionsAccessor));
            }

            if (_options.AreaViewLocationFormats.Count == 0)
            {
                throw new ArgumentException(
                    Resources.FormatViewLocationFormatsIsRequired(nameof(RazorViewEngineOptions.AreaViewLocationFormats)),
                    nameof(optionsAccessor));
            }

            _pageFactory = pageFactory;
            _pageActivator = pageActivator;
            _htmlEncoder = htmlEncoder;
            _logger = loggerFactory.CreateLogger<RazorViewEngine>();
            ViewLookupCache = new MemoryCache(new MemoryCacheOptions
            {
                CompactOnMemoryPressure = false
            });
        }
Exemplo n.º 6
0
        /// <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="buffer">The <see cref="ViewBuffer"/> to buffer output to.</param>
        /// <param name="encoder">The HTML encoder.</param>
        public RazorTextWriter(TextWriter unbufferedWriter, ViewBuffer buffer, HtmlEncoder encoder)
        {
            UnbufferedWriter = unbufferedWriter;
            Buffer = buffer;
            HtmlEncoder = encoder;

            BufferedWriter = new HtmlContentWrapperTextWriter(buffer, unbufferedWriter.Encoding);
            TargetWriter = BufferedWriter;
        }
Exemplo n.º 7
0
 /// <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="htmlEncoder">The <see cref="HtmlEncoder"/> to use.</param>
 /// <param name="urlHelperFactory">The <see cref="IUrlHelperFactory"/>.</param>
 public ImageTagHelper(
     IHostingEnvironment hostingEnvironment,
     IMemoryCache cache,
     HtmlEncoder htmlEncoder,
     IUrlHelperFactory urlHelperFactory)
     : base(urlHelperFactory, htmlEncoder)
 {
     HostingEnvironment = hostingEnvironment;
     Cache = cache;
 }
Exemplo n.º 8
0
        public static string HtmlContentToString(IHtmlContent content, HtmlEncoder encoder = null)
        {
            if (encoder == null)
            {
                encoder = new HtmlTestEncoder();
            }

            using (var writer = new StringWriter())
            {
                content.WriteTo(writer, encoder);
                return writer.ToString();
            }
        }
Exemplo n.º 9
0
        /// <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="HtmlEncoder"/> to encode the content.</param>
        public virtual void WriteTo(TextWriter writer, HtmlEncoder encoder)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (encoder == null)
            {
                throw new ArgumentNullException(nameof(encoder));
            }

            _asyncAction(writer).GetAwaiter().GetResult();
        }
Exemplo n.º 10
0
        /// <inheritdoc />
        public void WriteTo(TextWriter writer, HtmlEncoder encoder)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (encoder == null)
            {
                throw new ArgumentNullException(nameof(encoder));
            }

            encoder.Encode(writer, _input);
        }
Exemplo n.º 11
0
        public async Task Invoke(HttpContext httpContext, HtmlEncoder htmlEncoder)
        {
            // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase
            if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) ||
                httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase))
            {
                var rows = await LoadRows(_connectionString, _dbProviderFactory);

                await RenderHtml(rows, httpContext, htmlEncoder);

                return;
            }

            await _next(httpContext);
        }
        /// <inheritdoc />
        public void WriteTo(TextWriter writer, HtmlEncoder 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));
        }
Exemplo n.º 13
0
        private static async Task RenderHtml(IEnumerable<Fortune> model, HttpContext httpContext, HtmlEncoder htmlEncoder)
        {
            httpContext.Response.StatusCode = StatusCodes.Status200OK;
            httpContext.Response.ContentType = "text/html; charset=UTF-8";

            await httpContext.Response.WriteAsync("<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>");

            foreach (var item in model)
            {
                await httpContext.Response.WriteAsync(
                    $"<tr><td>{htmlEncoder.Encode(item.Id.ToString())}</td><td>{htmlEncoder.Encode(item.Message)}</td></tr>");
            }

            await httpContext.Response.WriteAsync("</table></body></html>");
        }
Exemplo n.º 14
0
        //IRazorViewEngine
        public CoreViewEngine(
            IRazorPageFactoryProvider pageFactory,
            IRazorPageActivator pageActivator,
            HtmlEncoder htmlEncoder,
            IOptions<RazorViewEngineOptions> optionsAccessor,
            ILoggerFactory loggerFactory
            ) :base(pageFactory, pageActivator, htmlEncoder, optionsAccessor, loggerFactory)
        {
            //https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Razor/RazorViewEngine.cs

            // {0} represents the name of the view
            // {1} represents the name of the controller
            // {2} represents the name of the area
            

        }
Exemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RazorPageActivator"/> class.
 /// </summary>
 public RazorPageActivator(
     IModelMetadataProvider metadataProvider,
     IUrlHelperFactory urlHelperFactory,
     IJsonHelper jsonHelper,
     DiagnosticSource diagnosticSource,
     HtmlEncoder htmlEncoder,
     IModelExpressionProvider modelExpressionProvider)
 {
     _activationInfo = new ConcurrentDictionary<Type, PageActivationInfo>();
     _metadataProvider = metadataProvider;
     _urlHelperAccessor = context => urlHelperFactory.GetUrlHelper(context);
     _jsonHelperAccessor = context => jsonHelper;
     _diagnosticSourceAccessor = context => diagnosticSource;
     _htmlEncoderAccessor = context => htmlEncoder;
     _modelExpressionProviderAccessor = context => modelExpressionProvider;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RazorViewEngine" />.
 /// </summary>
 public MultiTemplateEngine(
     IRazorPageFactoryProvider pageFactory,
     IRazorPageActivator pageActivator,
     HtmlEncoder htmlEncoder,
     IOptions<RazorViewEngineOptions> optionsAccessor,
     ILoggerFactory loggerFactory)
 {
     _options = optionsAccessor.Value;
     _pageFactory = pageFactory;
     _pageActivator = pageActivator;
     _htmlEncoder = htmlEncoder;
     _logger = loggerFactory.CreateLogger<RazorViewEngine>();
     ViewLookupCache = new MemoryCache(new MemoryCacheOptions
     {
         CompactOnMemoryPressure = false
     });
 }
Exemplo n.º 17
0
        public ViewComponentResultExecutor(
            IOptions<MvcViewOptions> mvcHelperOptions,
            IViewComponentHelper viewComponentHelper,
            ILoggerFactory loggerFactory,
            HtmlEncoder htmlEncoder,
            IModelMetadataProvider modelMetadataProvider,
            ITempDataDictionaryFactory tempDataDictionaryFactory)
        {
            if (mvcHelperOptions == null)
            {
                throw new ArgumentNullException(nameof(mvcHelperOptions));
            }

            if (viewComponentHelper == null)
            {
                throw new ArgumentNullException(nameof(viewComponentHelper));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (htmlEncoder == null)
            {
                throw new ArgumentNullException(nameof(htmlEncoder));
            }

            if (modelMetadataProvider == null)
            {
                throw new ArgumentNullException(nameof(modelMetadataProvider));
            }

            if (tempDataDictionaryFactory == null)
            {
                throw new ArgumentNullException(nameof(tempDataDictionaryFactory));
            }

            _htmlHelperOptions = mvcHelperOptions.Value.HtmlHelperOptions;
            _viewComponentHelper = viewComponentHelper;
            _logger = loggerFactory.CreateLogger<ViewComponentResult>();
            _htmlEncoder = htmlEncoder;
            _modelMetadataProvider = modelMetadataProvider;
            _tempDataDictionaryFactory = tempDataDictionaryFactory;
        }
Exemplo n.º 18
0
        public async Task Invoke(HttpContext httpContext, HtmlEncoder htmlEncoder)
        {
            // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase
            if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) ||
                httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase))
            {
                var db = (ApplicationDbContext)httpContext.RequestServices.GetService(typeof(ApplicationDbContext));
                db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

                var rows = await LoadRows(db);

                await RenderHtml(rows, httpContext, htmlEncoder);

                return;
            }

            await _next(httpContext);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Creates a new <see cref="ViewComponentContext"/>.
        /// </summary>
        /// <param name="viewComponentDescriptor">
        /// The <see cref="ViewComponentContext"/> for the view component being invoked.
        /// </param>
        /// <param name="arguments">The view component arguments.</param>
        /// <param name="viewContext">The <see cref="ViewContext"/>.</param>
        /// <param name="writer">The <see cref="TextWriter"/> for writing output.</param>
        public ViewComponentContext(
            ViewComponentDescriptor viewComponentDescriptor,
            IDictionary<string, object> arguments,
            HtmlEncoder htmlEncoder,
            ViewContext viewContext,
            TextWriter writer)
        {
            if (viewComponentDescriptor == null)
            {
                throw new ArgumentNullException(nameof(viewComponentDescriptor));
            }

            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            if (htmlEncoder == null)
            {
                throw new ArgumentNullException(nameof(htmlEncoder));
            }

            if (viewContext == null)
            {
                throw new ArgumentNullException(nameof(viewContext));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            ViewComponentDescriptor = viewComponentDescriptor;
            Arguments = arguments;
            HtmlEncoder = htmlEncoder;

            // We want to create a defensive copy of the VDD here so that changes done in the VC
            // aren't visible in the calling view.
            ViewContext = new ViewContext(
                viewContext,
                viewContext.View,
                new ViewDataDictionary(viewContext.ViewData),
                writer);
        }
        /// <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="HtmlEncoder"/> to use when encoding <paramref name="value"/>.</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.IHtmlContent"/> are written using
        /// <see cref="Html.IHtmlContent.WriteTo(TextWriter, HtmlEncoder)"/>.
        /// 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, HtmlEncoder encoder, object value)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            if (encoder == null)
            {
                throw new ArgumentNullException(nameof(encoder));
            }

            if (value == null)
            {
                // No real action but touch content to ensure IsModified is true.
                content.Append((string)null);
                return content;
            }

            string stringValue;
            var htmlString = value as HtmlEncodedString;
            if (htmlString != null)
            {
                // No need for a StringWriter in this case.
                stringValue = htmlString.ToString();
            }
            else
            {
                using (var stringWriter = new StringWriter())
                {
                    RazorPage.WriteTo(stringWriter, encoder, value);
                    stringValue = stringWriter.ToString();
                }
            }

            // In this case the text likely came directly from the Razor source. Since the original string is
            // an attribute value that may have been quoted with single quotes, must handle any double quotes
            // in the value. Writing the value out surrounded by double quotes.
            content.AppendHtml(stringValue.Replace("\"", "&quot;"));

            return content;
        }
Exemplo n.º 21
0
        public NotifyFilter(
            IHttpContextAccessor httpContextAccessor,
            INotifier notifier,
            ILayoutAccessor layoutAccessor,
            IShapeFactory shapeFactory,
            ShellSettings shellSettings,
            IDataProtectionProvider dataProtectionProvider,
            HtmlEncoder htmlEncoder)
        {
            _htmlEncoder = htmlEncoder;
            _dataProtectionProvider = dataProtectionProvider;
            _shellSettings = shellSettings;

            _layoutAccessor = layoutAccessor;
            _httpContextAccessor = httpContextAccessor;
            _notifier = notifier;
            _shapeFactory = shapeFactory;

            _tenantPath = "/" + _shellSettings.RequestUrlPrefix;
        }
        public static async Task RenderFortunesHtml(IEnumerable<Fortune> model, HttpContext httpContext, HtmlEncoder htmlEncoder)
        {
            httpContext.Response.StatusCode = StatusCodes.Status200OK;
            httpContext.Response.ContentType = "text/html; charset=UTF-8";

            var sb = new StringBuilder();
            sb.Append("<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>");
            foreach (var item in model)
            {
                sb.Append("<tr><td>");
                sb.Append(item.Id.ToString(CultureInfo.InvariantCulture));
                sb.Append("</td><td>");
                sb.Append(htmlEncoder.Encode(item.Message));
                sb.Append("</td></tr>");
            }

            sb.Append("</table></body></html>");
            var response = sb.ToString();
            // fortunes includes multibyte characters so response.Length is incorrect
            httpContext.Response.ContentLength = Encoding.UTF8.GetByteCount(response);
            await httpContext.Response.WriteAsync(response);
        }
        /// <summary>
        /// Initializes a new instance of <see cref="DefaultViewComponentHelper"/>.
        /// </summary>
        /// <param name="descriptorProvider">The <see cref="IViewComponentDescriptorCollectionProvider"/>
        /// used to locate view components.</param>
        /// <param name="htmlEncoder">The <see cref="HtmlEncoder"/>.</param>
        /// <param name="selector">The <see cref="IViewComponentSelector"/>.</param>
        /// <param name="invokerFactory">The <see cref="IViewComponentInvokerFactory"/>.</param>
        /// <param name="viewBufferScope">The <see cref="IViewBufferScope"/> that manages the lifetime of
        /// <see cref="ViewBuffer"/> instances.</param>
        public DefaultViewComponentHelper(
            IViewComponentDescriptorCollectionProvider descriptorProvider,
            HtmlEncoder htmlEncoder,
            IViewComponentSelector selector,
            IViewComponentInvokerFactory invokerFactory,
            IViewBufferScope viewBufferScope)
        {
            if (descriptorProvider == null)
            {
                throw new ArgumentNullException(nameof(descriptorProvider));
            }

            if (htmlEncoder == null)
            {
                throw new ArgumentNullException(nameof(htmlEncoder));
            }

            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            if (invokerFactory == null)
            {
                throw new ArgumentNullException(nameof(invokerFactory));
            }

            if (viewBufferScope == null)
            {
                throw new ArgumentNullException(nameof(viewBufferScope));
            }

            _descriptorProvider = descriptorProvider;
            _htmlEncoder = htmlEncoder;
            _selector = selector;
            _invokerFactory = invokerFactory;
            _viewBufferScope = viewBufferScope;
        }
Exemplo n.º 24
0
        /// <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="viewStartPages">The sequence of <see cref="IRazorPage" /> instances executed as _ViewStarts.
        /// </param>
        /// <param name="razorPage">The <see cref="IRazorPage"/> instance to execute.</param>
        /// <param name="htmlEncoder">The HTML encoder.</param>
        public RazorView(
            IRazorViewEngine viewEngine,
            IRazorPageActivator pageActivator,
            IReadOnlyList<IRazorPage> viewStartPages,
            IRazorPage razorPage,
            HtmlEncoder htmlEncoder)
        {
            if (viewEngine == null)
            {
                throw new ArgumentNullException(nameof(viewEngine));
            }

            if (pageActivator == null)
            {
                throw new ArgumentNullException(nameof(pageActivator));
            }

            if (viewStartPages == null)
            {
                throw new ArgumentNullException(nameof(viewStartPages));
            }

            if (razorPage == null)
            {
                throw new ArgumentNullException(nameof(razorPage));
            }

            if (htmlEncoder == null)
            {
                throw new ArgumentNullException(nameof(htmlEncoder));
            }

            _viewEngine = viewEngine;
            _pageActivator = pageActivator;
            ViewStartPages = viewStartPages;
            RazorPage = razorPage;
            _htmlEncoder = htmlEncoder;
        }
Exemplo n.º 25
0
        /// <inheritdoc />
        public void WriteTo(TextWriter writer, HtmlEncoder encoder)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (encoder == null)
            {
                throw new ArgumentNullException(nameof(encoder));
            }

            var htmlTextWriter = writer as HtmlTextWriter;
            if (htmlTextWriter != null)
            {
                // As a perf optimization, we can buffer this output rather than writing it
                // out character by character.
                htmlTextWriter.Write(this);
            }
            else
            {
                encoder.Encode(writer, _input);
            }
        }
            public EncodingFormatProvider(IFormatProvider formatProvider, HtmlEncoder encoder)
            {
                Debug.Assert(formatProvider != null);
                Debug.Assert(encoder != null);

                _formatProvider = formatProvider;
                _encoder = encoder;
            }
        /// <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.RequestServices.GetRequiredService<HtmlEncoder>();
            }

            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);
        }
 public TagCloudViewComponentTagHelper(HtmlEncoder htmlEncoder)
 {
     _htmlEncoder = htmlEncoder;
 }
Exemplo n.º 29
0
 public NotifyEntryConverter(HtmlEncoder htmlEncoder)
 {
     _htmlEncoder = htmlEncoder;
 }
Exemplo n.º 30
0
 public HtmlEncoder(TextEncoderSettings filter)
 {
     _encoder = System.Text.Encodings.Web.HtmlEncoder.Create(filter);
 }
Exemplo n.º 31
0
 public HtmlEncoder()
 {
     _encoder = System.Text.Encodings.Web.HtmlEncoder.Default;
 }
Exemplo n.º 32
0
 /// <summary>
 /// Creates a new <see cref="ScriptTagHelper"/>.
 /// </summary>
 /// <param name="hostingEnvironment">The <see cref="IHostingEnvironment"/>.</param>
 /// <param name="cache">The <see cref="IMemoryCache"/>.</param>
 /// <param name="htmlEncoder">The <see cref="HtmlEncoder"/>.</param>
 /// <param name="javaScriptEncoder">The <see cref="JavaScriptEncoder"/>.</param>
 /// <param name="urlHelperFactory">The <see cref="IUrlHelperFactory"/>.</param>
 public ScriptTagHelper(
     IHostingEnvironment hostingEnvironment,
     IMemoryCache cache,
     HtmlEncoder htmlEncoder,
     JavaScriptEncoder javaScriptEncoder,
     IUrlHelperFactory urlHelperFactory)
     : base(urlHelperFactory, htmlEncoder)
 {
     HostingEnvironment = hostingEnvironment;
     Cache = cache;
     JavaScriptEncoder = javaScriptEncoder;
 }
Exemplo n.º 33
0
        [MethodImpl(MethodImplOptions.NoInlining)] // the JITter can attempt to inline the caller itself without worrying about us
        private static HtmlEncoder CreateDefaultEncoderSlow()
        {
            var onDemandEncoder = new HtmlEncoder();

            return(Interlocked.CompareExchange(ref _defaultEncoder, onDemandEncoder, null) ?? onDemandEncoder);
        }