Beispiel #1
0
 public string GetResourceUrl(ILocalResourceLocation resource,
                              IDotvvmRequestContext context,
                              string name)
 {
     return(resourceRoute.BuildUrl(new Dictionary <string, object?> {
         [HashParameterName] = GetVersionHash(resource, context, name),
         [NameParameterName] = EncodeResourceName(name)
     }));
 }
Beispiel #2
0
 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);
             }
         }));
     }
 }
Beispiel #4
0
 public InlineScriptResource(ILocalResourceLocation resourceLocation, ResourceRenderPosition renderPosition = ResourceRenderPosition.Body) : base(renderPosition)
 {
     this.resourceLocation = resourceLocation;
 }
Beispiel #5
0
 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))}";
Beispiel #8
0
 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)
 });