Ejemplo n.º 1
0
        private void ResetCacheProduct(long companyID)
        {
            ProductAdapter productAdapter = new ProductAdapter(new SqlDb(ConfigCrawler.ConnectProduct));

            QT.Entities.Server.ConnectionString = ConfigCrawler.ConnectProduct;
            QT.Moduls.CrawlerProduct.Cache.CacheProductHash       cashProductHash        = QT.Moduls.CrawlerProduct.Cache.CacheProductHash.Instance();
            QT.Moduls.CrawlerProduct.Cache.RedisLastUpdateProduct cacheLastUpdateProduct = QT.Moduls.CrawlerProduct.Cache.RedisLastUpdateProduct.Instance();
            List <QT.Entities.CrawlerProduct.Cache.ProductHash>   lst = new List <QT.Entities.CrawlerProduct.Cache.ProductHash>();
            List <long> lstLastUpdate = new List <long>();
            Company     cmp           = new Company(companyID);

            productAdapter.DeleteProductUnvalidOfCOmpany(companyID);
            DataTable tbl = productAdapter.GetProductResetColumnDuplicateAndChange(companyID);

            foreach (DataRow rowProduct in tbl.Rows)
            {
                long   ProductId = QT.Entities.Common.Obj2Int64(rowProduct["ID"]);
                string Name = rowProduct["Name"].ToString();
                long   Price = QT.Entities.Common.Obj2Int64(rowProduct["Price"]);
                string ImageUrl = Convert.ToString(rowProduct["ImageUrls"]);
                string DetailUrl = Convert.ToString(rowProduct["DetailUrl"]);
                int    InStock = QT.Entities.Common.Obj2Int(rowProduct["InStock"]); long OriginPrice = QT.Entities.Common.Obj2Int(rowProduct["OriginPrice"]);
                bool   Valid            = QT.Entities.Common.Obj2Bool(rowProduct["Valid"]);
                string shortDescription = QT.Entities.Common.CellToString(rowProduct["ShortDescription"], "");
                bool   IsDeal           = QT.Entities.Common.Obj2Bool(rowProduct["IsDeal"]);
                long   CategoryID       = rowProduct["ClassificationID"] == DBNull.Value ? 0 : QT.Entities.Common.Obj2Int64(rowProduct["ClassificationID"]);
                long   HashChange       = QT.Entities.ProductEntity.GetHashChangeInfo(InStock, Valid, Price, Name, ImageUrl, CategoryID, shortDescription, OriginPrice);
                long   HashDuplicate    = QT.Entities.Product.GetHashDuplicate(cmp.Domain, Price, Name, ImageUrl);
                long   HashImage        = QT.Entities.Product.GetHashImageInfo(ImageUrl);
                lst.Add(new QT.Entities.CrawlerProduct.Cache.ProductHash()
                {
                    HashChange    = HashChange,
                    HashDuplicate = HashDuplicate,
                    HashImage     = HashImage,
                    Id            = ProductId,
                    Price         = Price,
                    url           = DetailUrl
                });
                lstLastUpdate.Add(ProductId);
            }
            cashProductHash.SetCacheProductHash(companyID, lst, 100);
            cacheLastUpdateProduct.RemoveAllLstProduct(companyID);
            cacheLastUpdateProduct.UpdateBathLastUpdateProduct(companyID, lstLastUpdate, DateTime.Now.AddDays(-1));
            productAdapter.UpdateCountProductForCompany(companyID, lstLastUpdate.Count, lstLastUpdate.Count);
            lst.Clear();
            lstLastUpdate.Clear();
            this.Invoke(new Action(() =>
            {
                try
                {
                    richTextBox1.AppendText(string.Format("Refresh Complete Company: {0}", _CompanyID));
                }
                catch (Exception ex01)
                {
                }
            }));
        }
Ejemplo n.º 2
0
        public void Run(System.Threading.CancellationToken token)
        {
            List <long> companyCrawelrs = productAdapter.GetAllCompanyIdCrawler();
            int         Count           = 0;

            foreach (long CompanyID in companyCrawelrs)
            {
                Count++;
                DataTable tbl = productAdapter.sqlDb.GetTblData("select id from product where company = @CompanyID", CommandType.Text, new System.Data.SqlClient.SqlParameter[] {
                    SqlDb.CreateParamteterSQL("@CompanyID", CompanyID, SqlDbType.BigInt)
                });

                List <long> productIDs = new List <long>();
                foreach (DataRow rowInfo in tbl.Rows)
                {
                    productIDs.Add(Convert.ToInt64(rowInfo["id"]));
                }
                redisLastUpdate.RemoveAllLstProduct(CompanyID);
                redisLastUpdate.UpdateBathLastUpdateProduct(CompanyID, productIDs, DateTime.Now);
                log.Info(string.Format("Reseted all products for company {0}/{1} LastUpdate in cache", Count, companyCrawelrs.Count));
            }
        }