Example #1
0
        public static void InsertAllWebRootProductIntoCache(string productConnectionString, string userConnectionString, string searchEnginesServiceUrl)
        {
            var startTime = DateTime.Now;
            var products  = WebRootProductBAL.GetAllWebRootProducts(productConnectionString, userConnectionString);
            var parts     = products.Partition(100);

            foreach (var productPart in parts)
            {
                foreach (var product in productPart)
                {
                    var rootProductMapping = RootProductMappingBAL.GetRootProductMappingFromCache(product.ID, 0, RootProductMappingSortType.PriceWithVAT, false);
                    if (rootProductMapping == null)
                    {
                        RootProductMappingCacheTool.InsertRootProductMappingCache(product.ID, searchEnginesServiceUrl);
                        rootProductMapping = RootProductMappingBAL.GetRootProductMappingFromCache(product.ID, 0, RootProductMappingSortType.PriceWithVAT, false);
                    }
                    if (rootProductMapping == null || rootProductMapping.NumMerchant == 0)
                    {
                        product.Price      = 0;
                        product.NumProduct = 0;
                    }
                    else
                    {
                        product.Price      = rootProductMapping.MinPrice;
                        product.NumProduct = rootProductMapping.NumMerchant;
                    }
                }
                WebRootProductBAL.InsertWebRootProductsIntoCache(productPart);
            }
            var insertAllWebRootProductDuration = (DateTime.Now - startTime).TotalSeconds;

            Logger.InfoFormat("InsertAllWebRootProductIntoCache: {0} products. Duration: {1} s", products.Count, insertAllWebRootProductDuration);
        }
Example #2
0
        public static bool InsertRootProductMappingCacheWithBlackList(long productID, string searchEnginesServiceUrl, TimeSpan?expiry = null)
        {
            var client   = new ProtoBufServiceStackClient(searchEnginesServiceUrl);
            var response = client.Send <GetRootProductMappingResponse>(new GetRootProductMappingRequest {
                ProductID = productID, RegionID = 0, IncludeBlackList = true, GetFacet = false, SortType = RootProductMappingSortType.PriceWithVAT
            });

            if (response.RootProductMapping != null)
            {
                RootProductMappingBAL.InsertRootProductMappingIntoCache(response.RootProductMapping, 0, RootProductMappingSortType.PriceWithVAT, true, expiry);
                return(true);
            }
            else
            {
                Log.ErrorFormat("InsertRootProductMappingWithBlackListIntoCache failed - ProductID {0}", productID);
                return(false);
            }
        }
Example #3
0
        private void UpdateProductRootId(long rootId)
        {
            int rootIDtemp = 0;

            int.TryParse(rootId.ToString(), out rootIDtemp);
            if (rootIDtemp == 0)
            {
                Log.Error(string.Format("RootID = {0} vượt quá int =)) ", rootId));
                return;
            }
            UpdateProductCategoryToZero((int)rootId);
            var rootProductMapping = RootProductMappingBAL.GetRootProductMappingFromCache(rootId, 0, RootProductMappingSortType.PriceWithVAT, true);

            if (rootProductMapping == null)
            {
                Log.WarnFormat("Get RootProductMapping return null! with ProductID = {0}", rootId);
                return;
            }
            if (rootProductMapping.ListMerchantProducts == null)
            {
                Log.WarnFormat("Root Product {0} have no product", rootId);
                return;
            }
            var dt = new DataTable();

            dt.Columns.Add("ID", typeof(long));
            dt.Columns.Add("ProductID", typeof(int));
            dt.Columns.Add("CategoryID", typeof(int));

            int categoryId = GetProductCategoryId(rootId);

            foreach (var productIdGroup in rootProductMapping.ListMerchantProducts)
            {
                foreach (var merchantProductId in productIdGroup.Value)
                {
                    dt.Rows.Add(merchantProductId, rootId, categoryId);
                }
            }
            //Update ProductID và CategoryID các sản phẩm merchant theo nhận diện mới
            UpdateBulk(dt);
            Log.Info(string.Format("Update rootID for rootProduct {0} - {1} products", rootId, dt.Rows.Count));
        }
Example #4
0
        public static bool InsertRootProductMappingCache(long productID, string searchEnginesServiceUrl, TimeSpan?expiry = null)
        {
            var client   = new ProtoBufServiceStackClient(searchEnginesServiceUrl);
            var response = client.Send <GetRootProductMappingResponse>(new GetRootProductMappingRequest {
                ProductID = productID, RegionID = 0, IncludeBlackList = false, GetFacet = true, SortType = RootProductMappingSortType.PriceWithVAT
            });

            if (response.RootProductMapping != null)
            {
                if (response.RootProductMapping.NumMerchant > 0)
                {
                    RedisPriceLogAdapter.PushRootProductPrice(productID, response.RootProductMapping.MinPrice, response.RootProductMapping.MaxPrice, response.RootProductMapping.MeanPrice, DateTime.Now.Date);
                }
                RootProductMappingBAL.InsertRootProductMappingIntoCache(response.RootProductMapping, 0, RootProductMappingSortType.PriceWithVAT, false, expiry);
                return(true);
            }
            else
            {
                Log.ErrorFormat("InsertRootProductMappingIntoCache failed - ProductID {0}", productID);
                return(false);
            }
        }
Example #5
0
        public static bool InsertWebRootProductIntoCache(long productID, string productConnectionString, string userConnectionString, string searchEnginesServiceUrl)
        {
            var product = WebRootProductBAL.GetWebRootProduct(productID, productConnectionString, userConnectionString);

            if (product == null)
            {
                return(false);
            }
            var rootProductMapping = RootProductMappingBAL.GetRootProductMappingFromCache(product.ID, 0, RootProductMappingSortType.PriceWithVAT, false);

            if (rootProductMapping == null)
            {
                RootProductMappingCacheTool.InsertRootProductMappingCache(product.ID, searchEnginesServiceUrl);
                rootProductMapping = RootProductMappingBAL.GetRootProductMappingFromCache(product.ID, 0, RootProductMappingSortType.PriceWithVAT, false);
                if (rootProductMapping == null)
                {
                    return(false);
                }
            }
            product.Price      = rootProductMapping.MinPrice;
            product.NumProduct = rootProductMapping.NumMerchant;
            return(WebRootProductBAL.InsertWebRootProductsIntoCache(new[] { product }));
        }