/// <summary> /// Return hash of requested asset (used for file versioning) /// </summary> /// <param name="filePath"></param> /// <returns></returns> public string GetAssetHash(string filePath) { var cacheKey = CacheKey.With(GetType(), "GetAssetHash", filePath); return(_memoryCache.GetOrCreateExclusive(cacheKey, (cacheEntry) => { cacheEntry.AddExpirationToken(new CompositeChangeToken(new[] { ThemeEngineCacheRegion.CreateChangeToken(), _themeBlobProvider.Watch(filePath), _themeBlobProvider.Watch(CurrentThemeSettingPath) })); using (var stream = GetAssetStreamAsync(filePath).GetAwaiter().GetResult()) { if (stream == null) { throw new StorefrontException($"Theme resource for path '{filePath}' not found"); } var hashAlgorithm = CryptoConfig.AllowOnlyFipsAlgorithms ? (SHA256) new SHA256CryptoServiceProvider() : new SHA256Managed(); return WebEncoders.Base64UrlEncode(hashAlgorithm.ComputeHash(stream)); } })); }
/// <summary> /// Return hash of requested asset (used for file versioning) /// </summary> /// <param name="filePath"></param> /// <returns></returns> public string GetAssetHash(string filePath) { var cacheKey = CacheKey.With(GetType(), "GetAssetHash", filePath); return(_memoryCache.GetOrCreate(cacheKey, (cacheEntry) => { cacheEntry.AddExpirationToken(new CompositeChangeToken(new[] { ThemeEngineCacheRegion.CreateChangeToken(), _themeBlobProvider.Watch(filePath) })); using (var stream = GetAssetStream(filePath)) { var hashAlgorithm = CryptoConfig.AllowOnlyFipsAlgorithms ? (SHA256) new SHA256CryptoServiceProvider() : new SHA256Managed(); return WebEncoders.Base64UrlEncode(hashAlgorithm.ComputeHash(stream)); } })); }
public IEnumerable <ContentItem> LoadStoreStaticContent(Store store) { var baseStoreContentPath = string.Concat(_basePath, "/", store.Id); var cacheKey = CacheKey.With(GetType(), "LoadStoreStaticContent", store.Id); return(_memoryCache.GetOrCreateExclusive(cacheKey, (cacheEntry) => { cacheEntry.AddExpirationToken(new CompositeChangeToken(new[] { StaticContentCacheRegion.CreateChangeToken(), _contentBlobProvider.Watch(baseStoreContentPath + "/**/*") })); var retVal = new List <ContentItem>(); const string searchPattern = "*.*"; if (_contentBlobProvider.PathExists(baseStoreContentPath)) { // Search files by requested search pattern var contentBlobs = _contentBlobProvider.Search(baseStoreContentPath, searchPattern, true) .Where(x => _extensions.Any(x.EndsWith)) .Select(x => x.Replace("\\\\", "\\")); foreach (var contentBlob in contentBlobs) { var blobRelativePath = "/" + contentBlob.TrimStart('/'); var contentItem = _builder.BuildFrom(baseStoreContentPath, blobRelativePath, GetContent(blobRelativePath)); if (contentItem != null) { retVal.Add(contentItem); } } } return retVal.ToArray(); })); }