private void EnsureFileVersionProvider() { if (_fileVersionProvider == null) { _fileVersionProvider = new FileVersionProvider( HostingEnvironment.WebRootFileProvider, Cache, ViewContext.HttpContext.Request.PathBase); } }
/// <summary> /// Generates a has of the file. /// </summary> protected string AddFileVersionToPath(string fileName, IAsset asset) { if (_fileProvider == null) { _fileProvider = new FileVersionProvider( asset.GetFileProvider(HostingEnvironment), Cache, ViewContext.HttpContext.Request.PathBase); } return(_fileProvider.AddFileVersionToPath(fileName)); }
private void AppendVersionedHref(string hrefName, string hrefValue, TagHelperContent builder) { if (AppendVersion == true) { hrefValue = FileVersionProvider.AddFileVersionToPath(ViewContext.HttpContext.Request.PathBase, hrefValue); } builder .AppendHtml(hrefName) .AppendHtml("=\"") .Append(hrefValue) .AppendHtml("\" "); }
private void EnsureFileVersionProvider() { if (_fileVersionProvider != null) { return; } _fileVersionProvider = new FileVersionProvider( _env.WebRootFileProvider, _cache, ViewContext.HttpContext.Request.PathBase ); }
private async void OnBinFileSave(object sender, RoutedEventArgs e) { using CommonSaveFileDialog dialog = new CommonSaveFileDialog(); dialog.Filters.Add(new CommonFileDialogFilter("BIN Files", "*.bin")); if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { try { BinTree binTree = this.ViewModel.SelectedBinTree.BuildBinTree(); binTree.Write(dialog.FileName, FileVersionProvider.GetSupportedVersions(LeagueFileType.PropertyBin).Last()); } catch (Exception exception) { await DialogHelper.ShowMessgeDialog($"Failed to save BIN Tree\n{exception}"); this.ViewModel.Infobar.Reset(); this.ViewModel.IsGloballyEnabled = true; } } }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } output.CopyHtmlAttribute(SrcAttributeName, context); ProcessUrlAttribute(SrcAttributeName, output); var bareUrl = Src.Substring(0, Src.LastIndexOf('.')); if (AppendVersion) { EnsureFileVersionProvider(); } foreach (var format in SourceFormats) { var formatUrl = $"{bareUrl}.{format}"; var finalUrl = AppendVersion ? FileVersionProvider.AddFileVersionToPath(ViewContext.HttpContext.Request.PathBase, formatUrl) : formatUrl; output.Content.AppendHtml($@"<source type=""image/{format}"" srcset=""{finalUrl}"" />"); } var url = AppendVersion ? FileVersionProvider.AddFileVersionToPath(ViewContext.HttpContext.Request.PathBase, Src) : Src; output.Content.AppendHtml(!Eager ? $@"<img src=""{url}"" alt=""{Alt}"" width=""{Width}"" height=""{Height}"">" : $@"<img src=""{url}"" alt=""{Alt}"" width=""{Width}"" height=""{Height}"" loading=""lazy"">"); output.Attributes.Clear(); }
private void AppendFallbackHrefs(TagHelperContent builder, IReadOnlyList <string> fallbackHrefs) { builder.AppendHtml("["); var firstAdded = false; // Perf: Avoid allocating enumerator and read interface .Count once rather than per iteration var fallbackHrefsCount = fallbackHrefs.Count; for (var i = 0; i < fallbackHrefsCount; i++) { if (firstAdded) { builder.AppendHtml(",\""); } else { builder.AppendHtml("\""); firstAdded = true; } // fallbackHrefs come from bound attributes (a C# context) and globbing. Must always be non-null. Debug.Assert(fallbackHrefs[i] != null); var valueToWrite = fallbackHrefs[i]; if (AppendVersion == true) { valueToWrite = FileVersionProvider.AddFileVersionToPath(ViewContext.HttpContext.Request.PathBase, fallbackHrefs[i]); } // Must HTML-encode the href attribute value to ensure the written <link/> element is valid. Must also // JavaScript-encode that value to ensure the doc.write() statement is valid. valueToWrite = HtmlEncoder.Encode(valueToWrite); valueToWrite = JavaScriptEncoder.Encode(valueToWrite); builder.AppendHtml(valueToWrite); builder.AppendHtml("\""); } builder.AppendHtml("]"); }
/// <inheritdoc /> public override void Process(TagHelperContext context, TagHelperOutput output) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } // Pass through attribute that is also a well-known HTML attribute. if (Src != null) { output.CopyHtmlAttribute(SrcAttributeName, context); } // If there's no "src" attribute in output.Attributes this will noop. ProcessUrlAttribute(SrcAttributeName, output); // Retrieve the TagHelperOutput variation of the "src" attribute in case other TagHelpers in the // pipeline have touched the value. If the value is already encoded this ScriptTagHelper may // not function properly. Src = output.Attributes[SrcAttributeName]?.Value as string; if (!AttributeMatcher.TryDetermineMode(context, ModeDetails, Compare, out var mode)) { // No attributes matched so we have nothing to do return; } if (AppendVersion == true) { EnsureFileVersionProvider(); if (Src != null) { var index = output.Attributes.IndexOfName(SrcAttributeName); var existingAttribute = output.Attributes[index]; output.Attributes[index] = new TagHelperAttribute( existingAttribute.Name, FileVersionProvider.AddFileVersionToPath(ViewContext.HttpContext.Request.PathBase, Src), existingAttribute.ValueStyle); } } var builder = output.PostElement; builder.Clear(); if (mode == Mode.GlobbedSrc || mode == Mode.Fallback && !string.IsNullOrEmpty(SrcInclude)) { BuildGlobbedScriptTags(output.Attributes, builder); if (string.IsNullOrEmpty(Src)) { // Only SrcInclude is specified. Don't render the original tag. output.TagName = null; output.Content.SetContent(string.Empty); } } if (mode == Mode.Fallback) { if (TryResolveUrl(FallbackSrc, resolvedUrl: out string resolvedUrl)) { FallbackSrc = resolvedUrl; } BuildFallbackBlock(output.Attributes, builder); } }
public override void Process(TagHelperContext context, TagHelperOutput output) { try { output.TagName = null; var dependencyLoader = DependencyManager.GetLoader(_httpContextAccessor.HttpContext); var fileVersionProvider = new FileVersionProvider( _hostingEnvironment.WebRootFileProvider, _cache, ViewContext.HttpContext.Request.PathBase); //var sb = new StringBuilder(); var dependencyFiles = dependencyLoader.DependencyFiles .Where(df => df.DependencyType == DependencyType) .OrderBy(df => df.Priority) .ToList(); if (DependencyType == DependencyType.Css) { foreach (var file in dependencyFiles) { TagBuilder itemBuilder = new TagBuilder("link"); string resolvedPath; if (file.FilePath.StartsWith("~")) { TryResolveUrl(file.FilePath, out resolvedPath); //resolvedPath = fileVersionProvider.AddFileVersionToPath(resolvedPath); } else { resolvedPath = file.FilePath; } itemBuilder.MergeAttributes(file.Attributes); itemBuilder.Attributes.Add("href", resolvedPath); itemBuilder.Attributes.Add("rel", "stylesheet"); output.Content.AppendHtml(itemBuilder); output.Content.AppendHtml(Environment.NewLine); } } else if (DependencyType == DependencyType.Script) { var filteredFiles = dependencyFiles.Where(df => df.ScriptLocation == ScriptLocation).ToList(); foreach (var file in filteredFiles) { TagBuilder itemBuilder = new TagBuilder("script"); string resolvedPath; if (file.FilePath.StartsWith("~")) { TryResolveUrl(file.FilePath, out resolvedPath); //resolvedPath = fileVersionProvider.AddFileVersionToPath(resolvedPath); } else { resolvedPath = file.FilePath; } itemBuilder.MergeAttributes(file.Attributes); itemBuilder.Attributes.Add("src", resolvedPath); output.Content.AppendHtml(itemBuilder); output.Content.AppendHtml(Environment.NewLine); } } } catch (Exception ex) { throw ex; } }