public static void InsertWebMerchantProductToCache(long companyID, string companyDomain, string connProductString) { try { //Get List Product Of Company var listWebMerchantProducts = WebMerchantProductBAL.GetListWebMerchantProductsOfCompany(companyID, connProductString); //XT. Change link if is MasOffer if (masOffer.CheckIsMasOffer(companyID)) { foreach (var itemProduct in listWebMerchantProducts) { itemProduct.DetailUrl = masOffer.GetFullUrl(companyID, itemProduct.DetailUrl); } Log.Info("Masoffer: " + companyID + " : " + listWebMerchantProducts.Count); } if (listWebMerchantProducts.Count > 0) { var parts = CollectionUtilities.Partition <WebMerchantProduct>(listWebMerchantProducts, 2000); foreach (var part in parts) { WebMerchantProductBAL.InsertWebMerchantProductsIntoCache(part); } } Log.InfoFormat("InsertWebMerchantProductToCache - Company [{0}] - {1} - {2} products]", companyID, companyDomain, listWebMerchantProducts.Count); } catch (Exception ex) { Log.Error("InsertWebMerchantProductToCache Error", ex); } }
public void IdentifyProducts() { if (_productID == 0) { MakeListProductUpToDate(); return; } UpdateObjectValue(); this.dBMap.ProductInfo.Rows.Clear(); int numProductFound = 0; long minPriceFound = 0; long maxPriceFound = 0; var client = new ProtoBufServiceStackClient(_searchEnginesServiceUrl); try { var response = client.Send <GetRootProductMappingResponse>(new GetRootProductMappingByProductIdentityRequest { ProductIdentity = _productIdentity, RegionID = 0, IncludeBlackList = false, GetFacet = true }); if (response.RootProductMapping != null) { listProductFound = new List <long>(); foreach (var merchantProductIDs in response.RootProductMapping.ListMerchantProducts) { listProductFound.AddRange(merchantProductIDs.Value); } this.dBMap.ProductInfo.Clear(); var productIDMap = new Dictionary <RedisKey, RedisValue>(); var listProductMapReverseKey = listProductFound.Select(x => (RedisKey)(ProductConstants.REDIS_PREFIX_PRODUCT_MAP_REVERSE + x)).ToArray(); if (listProductMapReverseKey.Length > 0) { //try //{ // foreach (var item in listProductMapReverseKey) // { // bool bOK = _productMapRedisServer.Exist(item); // if (bOK == false) // { // MessageBox.Show("dfSD"); // } // } productIDMap = _productMapRedisServer.MGet(listProductMapReverseKey); // } // catch(Exception ex) // { // MessageBox.Show(ex.Message); // } } var merchantProducts = WebMerchantProductBAL.GetWebMerchantProductsFromCache(listProductFound); foreach (var item in merchantProducts.Values) { var row = this.dBMap.ProductInfo.NewRow();//.NewRow(); row["Name"] = item.Name; row["Price"] = item.Price; row["ID"] = item.ID; row["Url"] = item.DetailUrl; row["Company"] = item.CompanyID; var redisProductMapReverseKey = ProductConstants.REDIS_PREFIX_PRODUCT_MAP_REVERSE + item.ID; if (productIDMap.ContainsKey(redisProductMapReverseKey)) { row["RootID"] = productIDMap[redisProductMapReverseKey]; } this.dBMap.ProductInfo.Rows.Add(row); } this.dBMap.ProductInfo.AcceptChanges(); // numProductFound = response.RootProductMapping.ListMerchantProducts.Sum(x => x.Value.Count); minPriceFound = response.RootProductMapping.MinPrice; maxPriceFound = response.RootProductMapping.MaxPrice; } else { numProductFound = 0; minPriceFound = 0; maxPriceFound = 0; } } catch (Exception ex) { Log.Error("ERROR client.Send<GetRootProductMappingResponse>", ex); } //XT-2015_08_07 //this.RefreshDataChart(dBMap.ProductInfo); //Comment vì ko dùng đến nữa 19.11.2015 textBoxNumFound.Text = numProductFound.ToString(); spinEditMinPriceFound.Value = minPriceFound; spinEditMaxPriceFound.Value = maxPriceFound; MakeListProductUpToDate(); var adtJob = new QT.Moduls.Company.DBComTableAdapters.Job_WebsiteConfigLogTableAdapter(); adtJob.Connection.ConnectionString = Server.ConnectionString; try { adtJob.Insert(QT.Users.User.UserID, _productID, richTextBoxNote.Text, textBoxNumFound.Text, QT.Users.JobNhapLieuStatus.NhanDienSanPham, DateTime.Now); } catch (Exception) { } }
protected override void OnStart(string[] args) { try { var productConnectionString = ConfigurationManager.ConnectionStrings["productConnectionString"].ConnectionString; MasOfferAdapter.SetConnection(productConnectionString); //WebMerchantProductCacheTool.InsertWebMerchantProductToCache(2642071820174507179, //"tiki.vn", productConnectionString); var userConnecionString = ConfigurationManager.ConnectionStrings["userConnecionString"].ConnectionString; string rabbitMQServerName = ConfigurationManager.AppSettings["rabbitMQServerName"]; string updateAllProductOfMerchantToRedisJobName = ConfigurationManager.AppSettings["updateAllProductOfMerchantToRedisJobName"]; int updateAllProductOfMerchantWorkerCount = CommonUtilities.Object2Int( ConfigurationManager.AppSettings["updateAllProductOfMerchantWorkerCount"], 1); updateAllProductOfMerchantWorkers = new Worker[updateAllProductOfMerchantWorkerCount]; string updateProductToRedisJobName = ConfigurationManager.AppSettings["updateProductToRedisJobName"]; int updateProductWorkerCount = CommonUtilities.Object2Int(ConfigurationManager.AppSettings["updateProductWorkerCount"], 1); var searchEnginesServiceUrl = ConfigurationManager.AppSettings["searchEnginesServiceUrl"]; updateProductWorkers = new Worker[updateProductWorkerCount]; rabbitMQServer = RabbitMQManager.GetRabbitMQServer(rabbitMQServerName); for (int i = 0; i < updateAllProductOfMerchantWorkerCount; i++) { var worker = new Worker(updateAllProductOfMerchantToRedisJobName, false, rabbitMQServer); updateAllProductOfMerchantWorkers[i] = worker; Task workerTask = new Task(() => { worker.JobHandler = (updateAllProductOfMerchantToRedisJob) => { try { var companyID = BitConverter.ToInt64(updateAllProductOfMerchantToRedisJob.Data, 0); if (companyID == -1) //UpdateAlL { WebMerchantProductCacheTool.InsertAllWebMerchantProductToCache( productConnectionString); } else if (companyID == 6619858476258121218) // Websosanh { WebRootProductCacheTool.InsertAllWebRootProductIntoCache(productConnectionString, userConnecionString, searchEnginesServiceUrl); } else { var merchantShortInfo = MerchantBAL.GetMerchantShortInfoFromCache(companyID); if (merchantShortInfo == null) { merchantShortInfo = MerchantBAL.GetMerchantShortInfo(companyID, productConnectionString, userConnecionString); if (merchantShortInfo == null) { return(false); } MerchantBAL.InsertMerchantShortInfoToCache(merchantShortInfo, new TimeSpan(10000, 0, 0, 0, 0)); } WebMerchantProductCacheTool.InsertWebMerchantProductToCache(companyID, merchantShortInfo.Domain, productConnectionString); } return(true); } catch (Exception ex) { Logger.Error("Update All Products Of Merchant To Redis", ex); return(false); } }; worker.Start(); }); workerTask.Start(); Logger.InfoFormat("Worker {0} started", i); } for (int i = 0; i < updateProductWorkerCount; i++) { var worker = new Worker(updateProductToRedisJobName, false, rabbitMQServer); updateProductWorkers[i] = worker; Task workerTask = new Task(() => { worker.JobHandler = (updateProductToRedisJob) => { try { var productID = BitConverter.ToInt64(updateProductToRedisJob.Data, 0); if (productID <= 0) { Logger.WarnFormat("UpdateProductToRedis: Received productID {0}", productID); return(false); } if (updateProductToRedisJob.Type == 1) //RootProduct { WebRootProductCacheTool.InsertWebRootProductIntoCache(productID, productConnectionString, userConnecionString, searchEnginesServiceUrl); } else { var webMerchantProduct = WebMerchantProductBAL.GetWebMerchantProduct(productID, productConnectionString); if (webMerchantProduct != null) { //XT: Change link if masOffer company MasOfferAdapter.SetConnection(productConnectionString); if (massOffer.CheckIsMasOffer(webMerchantProduct.CompanyID)) { webMerchantProduct.DetailUrl = massOffer.GetFullUrl(webMerchantProduct.CompanyID, webMerchantProduct.DetailUrl); } WebMerchantProductBAL.InsertWebMerchantProductsIntoCache(new[] { webMerchantProduct }); } } return(true); } catch (Exception ex) { Logger.Error("Update Product To Redis", ex); return(false); } }; worker.Start(); }); workerTask.Start(); Logger.InfoFormat("Worker {0} started", i); } } catch (Exception excepion) { Logger.Error("Error on start", excepion); throw; } }