public virtual async Task <string> GetDynamicContentHtmlAsync(string storeId, string placeholderName) { string htmlContent = null; var evalContext = _workContextAccessor.WorkContext.ToDynamicContentEvaluationContext(); evalContext.PlaceName = placeholderName; evalContext.StoreId = storeId; var result = await _dynamicContentEvaluator.EvaluateDynamicContentItemsAsync(evalContext); if (result != null) { var htmlContentSpec = new HtmlDynamicContentSpecification(); var htmlDynamicContent = result.FirstOrDefault(htmlContentSpec.IsSatisfiedBy); if (htmlDynamicContent != null) { var dynamicProperty = htmlDynamicContent.DynamicProperties.FirstOrDefault(htmlContentSpec.IsSatisfiedBy); if (dynamicProperty != null && dynamicProperty.Values.Any(v => v.Value != null)) { htmlContent = dynamicProperty.Values.First().Value.ToString(); } } } return(htmlContent); }
public virtual async Task <string> GetDynamicContentHtmlAsync(string storeId, string placeholderName) { string htmlContent = null; //TODO: make full context var evaluationContext = new DynamicContentEvaluationContext { StoreId = storeId, PlaceName = placeholderName }; var cacheKey = CacheKey.With(GetType(), "GetDynamicContentHtmlAsync", storeId, placeholderName); return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(MarketingCacheRegion.CreateChangeToken()); cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken()); var dynamicContentItems = (await _dynamicContentApi.EvaluateDynamicContentAsync(evaluationContext)).Select(x => x.ToDynamicContentItem()); if (dynamicContentItems != null) { var htmlContentSpec = new HtmlDynamicContentSpecification(); var htmlDynamicContent = dynamicContentItems.FirstOrDefault(htmlContentSpec.IsSatisfiedBy); if (htmlDynamicContent != null) { var dynamicProperty = htmlDynamicContent.DynamicProperties.FirstOrDefault(htmlContentSpec.IsSatisfiedBy); if (dynamicProperty != null && dynamicProperty.Values.Any(v => v.Value != null)) { htmlContent = dynamicProperty.Values.First().Value.ToString(); } } } return htmlContent; })); }
public async Task <ActionResult <string> > GetDynamicContent(string placeName) { string htmlContent = null; var evalContext = WorkContext.ToDynamicContentEvaluationContext(); evalContext.PlaceName = placeName; var result = await _dynamicContentEvaluator.EvaluateDynamicContentItemsAsync(evalContext); if (result != null) { var htmlContentSpec = new HtmlDynamicContentSpecification(); var htmlDynamicContent = result.FirstOrDefault(htmlContentSpec.IsSatisfiedBy); if (htmlDynamicContent != null) { var dynamicProperty = htmlDynamicContent.DynamicProperties.FirstOrDefault(htmlContentSpec.IsSatisfiedBy); if (dynamicProperty != null && dynamicProperty.Values.Any(v => v.Value != null)) { htmlContent = dynamicProperty.Values.First().Value.ToString(); } } } return(htmlContent); }