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();
            }));
        }
Exemple #2
0
        /// <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) }));

                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));
                }
            });
        }
Exemple #3
0
        protected virtual Task LoadProductsAssociationsAsync(IEnumerable <Product> products, WorkContext workContext)
        {
            if (products == null)
            {
                throw new ArgumentNullException(nameof(products));
            }

            foreach (var product in products)
            {
                //Associations
                product.Associations = new MutablePagedList <ProductAssociation>((pageNumber, pageSize, sortInfos, @params) =>
                {
                    var criteria = new ProductAssociationSearchCriteria
                    {
                        PageNumber    = pageNumber,
                        PageSize      = pageSize,
                        ProductId     = product.Id,
                        ResponseGroup = ItemResponseGroup.ItemInfo | ItemResponseGroup.ItemWithPrices | ItemResponseGroup.Inventory | ItemResponseGroup.ItemWithVendor
                    };
                    if (!sortInfos.IsNullOrEmpty())
                    {
                        criteria.Sort = SortInfo.ToString(sortInfos);
                    }
                    if (@params != null)
                    {
                        criteria.CopyFrom(@params);
                    }
                    var cacheKey     = CacheKey.With(GetType(), "SearchProductAssociations", criteria.GetCacheKey());
                    var searchResult = _memoryCache.GetOrCreateExclusive(cacheKey, cacheEntry =>
                    {
                        cacheEntry.AddExpirationToken(CatalogCacheRegion.CreateChangeToken());
                        cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken());
                        return(_productsApi.SearchProductAssociations(criteria.ToProductAssociationSearchCriteriaDto()));
                    });
                    //Load products for resulting associations
                    var associatedProducts = GetProductsAsync(searchResult.Results.Select(x => x.AssociatedObjectId).ToArray(), criteria.ResponseGroup).GetAwaiter().GetResult();
                    var result             = new List <ProductAssociation>();
                    foreach (var associationDto in searchResult.Results)
                    {
                        var productAssociation     = associationDto.ToProductAssociation();
                        productAssociation.Product = associatedProducts.FirstOrDefault(x => x.Id.EqualsInvariant(productAssociation.ProductId));
                        result.Add(productAssociation);
                    }
                    return(new StaticPagedList <ProductAssociation>(result, pageNumber, pageSize, searchResult.TotalCount ?? 0));
                }, 1, ProductSearchCriteria.DefaultPageSize);
            }
            return(Task.CompletedTask);
        }
Exemple #4
0
        /// <summary>
        /// Check that blob or folder with passed path exist
        /// </summary>
        /// <param name="path">relative path /folder/blob.md</param>
        /// <returns></returns>
        public virtual bool PathExists(string path)
        {
            var cacheKey = CacheKey.With(GetType(), "PathExists", path);

            return(_memoryCache.GetOrCreateExclusive(cacheKey, (cacheEntry) =>
            {
                path = NormalizePath(path);
                cacheEntry.AddExpirationToken(Watch(path));
                cacheEntry.AddExpirationToken(ContentBlobCacheRegion.CreateChangeToken());
                var retVal = Directory.Exists(path);
                if (!retVal)
                {
                    retVal = File.Exists(path);
                }
                return retVal;
            }));
        }
        public virtual IPagedList <Vendor> SearchVendors(Store store, Language language, string keyword, int pageNumber, int pageSize, IEnumerable <SortInfo> sortInfos)
        {
            // TODO: implement indexed search for vendors
            var criteria = new customerDto.MembersSearchCriteria
            {
                SearchPhrase = keyword,
                DeepSearch   = true,
                Skip         = (pageNumber - 1) * pageSize,
                Take         = pageSize
            };

            if (!sortInfos.IsNullOrEmpty())
            {
                criteria.Sort = SortInfo.ToString(sortInfos);
            }
            var cacheKey = CacheKey.With(GetType(), "SearchVendors", keyword, pageNumber.ToString(), pageSize.ToString(), criteria.Sort);
            var result   = _memoryCache.GetOrCreateExclusive(cacheKey, cacheEntry =>
            {
                return(_customerApi.SearchVendors(criteria));
            });
            var vendors = result.Vendors.Select(x => x.ToVendor(language, store));

            return(new StaticPagedList <Vendor>(vendors, pageNumber, pageSize, result.TotalCount.Value));
        }