public string GetResourceUrl(ILocalResourceLocation resource, IDotvvmRequestContext context, string name) { return(resourceRoute.BuildUrl(new Dictionary <string, object?> { [HashParameterName] = GetVersionHash(resource, context, name), [NameParameterName] = EncodeResourceName(name) })); }
public static string ReadToString(this ILocalResourceLocation location, IDotvvmRequestContext context) { using (var resourceStream = location.LoadResource(context)) { using (var resourceStreamReader = new StreamReader(resourceStream)) { return(resourceStreamReader.ReadToEnd()); } } }
protected byte[] GetHash(ILocalResourceLocation resourceLocation, IDotvvmRequestContext context) { if (context.Configuration.Debug) { using (var stream = resourceLocation.LoadResource(context)) { return(ComputeHash(stream)); } } else { return(hashCache.GetValue(resourceLocation, l => { using (var stream = resourceLocation.LoadResource(context)) { return ComputeHash(stream); } })); } }
public InlineScriptResource(ILocalResourceLocation resourceLocation, ResourceRenderPosition renderPosition = ResourceRenderPosition.Body) : base(renderPosition) { this.resourceLocation = resourceLocation; }
protected virtual string GetVersionHash(ILocalResourceLocation location, IDotvvmRequestContext context, string name) => suppressVersionHash? // don't generate the hash iff !Debug, as it clears breakpoints in debugger when url changes EncodeResourceName(name) : hasher.GetVersionHash(location, context);
public string GetVersionHash(ILocalResourceLocation resource, IDotvvmRequestContext context) => Convert.ToBase64String(GetHash(resource, context)) .Remove(20) // take only 20 chars (120 bits) .Replace('/', '-').Replace('+', '_'); // `/` and `+` are not url-safe
public string GetIntegrityHash(ILocalResourceLocation resource, IDotvvmRequestContext context) => $"{hashFunctionName}-{Convert.ToBase64String(GetHash(resource, context))}";
public InlineStylesheetResource(ILocalResourceLocation resourceLocation) : base(ResourceRenderPosition.Head) { this.resourceLocation = resourceLocation; }
public string GetResourceUrl(ILocalResourceLocation resource, IDotvvmRequestContext context, string name) => resourceRoute.BuildUrl(new Dictionary <string, object> { ["hash"] = GetVersionHash(resource, context, name), ["name"] = EncodeResourceName(name) });