예제 #1
0
        private dynamic GetProductsByPcmIdAction(DealFinderContext context, ObjectId pcmId)
        {
            var appCachedValue = string.Format("GetProductsByPcmId:{0}", pcmId);
            var products       = new List <CseProductInfo>();
            var pcmInfo        = new CsePcmInfo();

            context.Status = 1;

            if (MemoryCache.Default.Get(appCachedValue) == null || context.QaMode == true)
            {
                var pcmProvider = new PcmProvider(context);
                pcmInfo = pcmProvider.GetProductFromPcmById(pcmId);

                context.IsExistInPcm   = true;
                context.ProductName    = pcmInfo.ProductName;
                context.Price          = pcmInfo.Price;
                context.IsDefaultPrice = pcmInfo.IsDefaultPrice;

                var productsProvider = new ProductsProvider(context);
                products = productsProvider.GetProductsFromPcm(pcmInfo);

                dynamic cacheObject = new
                {
                    products = products,
                    pcm      = pcmInfo
                };

                MemoryCache.Default.Add(appCachedValue, cacheObject, DateTimeOffset.Now.AddHours(4));
            }
            else
            {
                var cacheOject = (dynamic)MemoryCache.Default[appCachedValue];

                products = cacheOject.products;
                pcmInfo  = cacheOject.pcm;
            }

            context.Currency = pcmInfo.Currency;

            var result = GetResult(context, pcmInfo, products);

            return(result);
        }
예제 #2
0
        public List <CseProductInfo> GetProductsFromPcm(CsePcmInfo pcmInfo)
        {
            var products = GetProductsFromPcmAction(pcmInfo, _context.Op);

            if (products.Count == 0)
            {
                products = GetProductsFromCseAction(1);

                var pcmProvider = new PcmProvider(_context);
                pcmProvider.UpsertProductToPcm(products);

                return(products);
            }

            var filterProvider = new FilterProvider(_context);

            products = filterProvider.FilterSameStore(products);
            products = filterProvider.FilterPriceRange(products);
            products = filterProvider.FilterDuplicateStores(products);
            products = filterProvider.FilterDuplicateProductId(products);

            return(products);
        }
예제 #3
0
        private List <CseProductInfo> RetrieveProducts(DealFinderContext context, out CsePcmInfo pcmInfo)
        {
            var timer   = new TimerProvider(context, "extract-cache-value-and-domain");
            var domains = GetDomainCache(context.DomainName);

            if (domains.Length > 0)
            {
                context.IsDomainInDataBase = true;
            }

            if (context.PageType == "product")
            {
                int priority = 0;

                context.CachedValue         = GetCachedValue(domains, context.Url, context.DomainName, out priority);
                context.CachedValuePriority = priority == 0 ? "" : priority.ToString();
            }

            timer.StopTimer();

            var pcmProvider = new PcmProvider(context);

            pcmInfo = pcmProvider.GetProductFromPcmByCacheValueAndDomain();
            var products = new List <CseProductInfo>();

            if (pcmInfo == null)
            {
                if (context.PageType == "product")
                {
                    timer = new TimerProvider(context, "get-site-data");

                    var getSiteDataProvider = new GetSiteDataProvider(context, true);
                    var siteData            = getSiteDataProvider.GetSiteData();

                    timer.StopTimer();

                    context.IsGetSiteDataExecuted = true;

                    if (siteData == null)
                    {
                        context.IsGetSiteDataFailed = true;

                        pcmInfo = new CsePcmInfo();

                        return(products);
                    }
                }

                var productsProvider = new ProductsProvider(context);

                products = productsProvider.GetProductsFromCse(1);

                timer   = new TimerProvider(context, "insert-product-to-pcm");
                pcmInfo = pcmProvider.UpsertProductToPcm(products);
                timer.StopTimer();
            }
            else
            {
                context.IsExistInPcm   = true;
                context.Status         = 1;
                context.ProductName    = pcmInfo.ProductName;
                context.Price          = pcmInfo.Price;
                context.IsDefaultPrice = pcmInfo.IsDefaultPrice;

                timer = new TimerProvider(context, "get-data-from-pcm");

                var productsProvider = new ProductsProvider(context);
                products = productsProvider.GetProductsFromPcm(pcmInfo);

                timer.StopTimer();
            }

            context.ProductName     = pcmInfo.ProductDisplayName;
            context.Price           = pcmInfo.Price;
            context.DomainPriceRule = pcmInfo.DomainPriceRule;

            return(products);
        }