Example #1
0
 public Product(RelevanceInfo info)
 {
     Id                    = info.ProductId;
     Relevance             = info.Relevance.ToString();
     LastPublished         = info.LastPublished;
     LastPublishedUserName = info.LastPublishedUserName;
 }
Example #2
0
        private void AddRelevanceData(Article article, RelevanceInfo relevanceInfo)
        {
            var statusText = ProductCardStrings.NotRelevant;

            if (relevanceInfo.Relevance == ProductRelevance.Missing)
            {
                statusText = ProductCardStrings.Missing;
            }
            else if (relevanceInfo.Relevance == ProductRelevance.Relevant)
            {
                statusText = ProductCardStrings.Relevant;
            }

            article
            .AddPlainField("ConsumerCulture", relevanceInfo.Culture.NativeName, ProductCardStrings.FrontLanguage)
            .AddPlainField("ConsumerStatusText", statusText, ProductCardStrings.FrontStatus)
            .AddPlainField("ConsumerStatusCode", relevanceInfo.Relevance.ToString(), ProductCardStrings.FrontStatusCode)
            .AddPlainField("ConsumerLastPublished", relevanceInfo.LastPublished.ToString(), ProductCardStrings.Published)
            .AddPlainField("ConsumerLastPublishedUserName", relevanceInfo.LastPublishedUserName, ProductCardStrings.PublishedBy);
        }
Example #3
0
        private RelevanceInfo GetRelevance(Article localizedProduct, CultureInfo culture, bool isLive)
        {
            var sw = new Stopwatch();

            sw.Start();
            var consumerMonitoringService = _consumerMonitoringServiceFunc(isLive, culture);

            if (consumerMonitoringService == null)
            {
                return(null);
            }

            var relevanceInfo = new RelevanceInfo
            {
                ProductId             = localizedProduct.Id,
                Culture               = culture,
                LastPublished         = null,
                LastPublishedUserName = null,
                Relevance             = ProductRelevance.Missing
            };

            var consumerProductInfo = consumerMonitoringService.GetProductInfo(localizedProduct.Id);

            sw.Stop();
            _logger.Debug("Relevance: Product info receiving for {1} took {0} sec", sw.Elapsed.TotalSeconds, localizedProduct.Id);

            if (consumerProductInfo != null)
            {
                sw.Reset();
                sw.Start();
                relevanceInfo.LastPublished         = consumerProductInfo.Updated;
                relevanceInfo.LastPublishedUserName = consumerProductInfo.LastPublishedUserName;

                var allArticlesNeededToCheck = GetAllProductChildAtriclesToPublish(localizedProduct).ToArray();

                sw.Stop();
                _logger.Debug("Relevance: Status checking for {1} took {0} sec", sw.Elapsed.TotalSeconds, localizedProduct.Id);

                if (isLive && allArticlesNeededToCheck.Any(x => !x.IsPublished))
                {
                    relevanceInfo.Relevance = ProductRelevance.NotRelevant;
                }
                else
                {
                    sw.Reset();
                    sw.Start();

                    string localizedProductData = _formatter.Serialize(localizedProduct, ArticleFilter.DefaultFilter, true);

                    sw.Stop();
                    _logger.Debug("Relevance: Product serializing for {1} took {0} sec", sw.Elapsed.TotalSeconds, localizedProduct.Id);


                    sw.Reset();
                    sw.Start();

                    string localizedProductHash = GetHash(localizedProductData);

                    sw.Stop();
                    _logger.Debug("Relevance: Hash computing for {1} took {0} sec", sw.Elapsed.TotalSeconds, localizedProduct.Id);

                    if (localizedProductHash == consumerProductInfo.Hash)
                    {
                        relevanceInfo.Relevance = ProductRelevance.Relevant;
                    }
                    else
                    {
                        relevanceInfo.Relevance = ProductRelevance.NotRelevant;
                    }
                }
            }

            return(relevanceInfo);
        }