Beispiel #1
0
        public static void BuildCategory(string connProductString)
        {
            try
            {
                var productTableAdapter = new ProductTableAdapter
                {
                    Connection = { ConnectionString = connProductString }
                };
                var companyTableAdapter = new CompanyTableAdapter()
                {
                    Connection = { ConnectionString = connProductString }
                };
                var companyDataTable = companyTableAdapter.GetAllCompanies();

                for (int companyRowIndex = 0; companyRowIndex < companyDataTable.Rows.Count; companyRowIndex++)
                {
                    var companyRow = companyDataTable[companyRowIndex];
                    try
                    {
                        var startTime        = DateTime.Now;
                        var companyID        = companyRow.ID;
                        var productDataTable = productTableAdapter.GetAllProductName(companyID);
                        List <KeyValuePair <long, int> > productCategoryMap = new List <KeyValuePair <long, int> >();
                        for (int productRowIndex = 0; productRowIndex < productDataTable.Rows.Count; productRowIndex++)
                        {
                            var productRow = productDataTable[productRowIndex];
                            if (productRow["Name"] == DBNull.Value)
                            {
                                continue;
                            }
                            int categoryID = GetCategory(productRow.Name);
                            if (categoryID >= 0)
                            {
                                productCategoryMap.Add(new KeyValuePair <long, int>(productRow.ID, categoryID));
                            }
                            if (productCategoryMap.Count >= 1000)
                            {
                                var database = RedisManager.GetRedisServer("redisProductCategory").GetDatabase(0);
                                database.StringSet(productCategoryMap.Select(x => new KeyValuePair <RedisKey, RedisValue>(string.Format(productCategoryKeyFormat, x.Key), x.Value)).ToArray());
                                productCategoryMap.Clear();
                            }
                            //Thread.Sleep(10);
                        }
                        if (productCategoryMap.Count > 0)
                        {
                            var database = RedisManager.GetRedisServer("redisProductCategory").GetDatabase(0);
                            database.StringSet(productCategoryMap.Select(x => new KeyValuePair <RedisKey, RedisValue>(string.Format(productCategoryKeyFormat, x.Key), x.Value)).ToArray());
                        }
                        Log.InfoFormat("Insert MerchantProductCategory - Company [{0}/{1}]. {2} products", companyRowIndex, companyDataTable.Rows.Count, productDataTable.Rows.Count);
                        var totalTime = (DateTime.Now - startTime).TotalSeconds;
                        Log.InfoFormat("Time: {0} s", totalTime);
                    }
                    catch (Exception innerException)
                    {
                        Log.Error("Insert MerchantProductCategory. Company: " + companyRow.ID, innerException);
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error("Insert MerchantProductCategory", exception);
            }
        }
Beispiel #2
0
        public static void BuildNameHash(string connProductString)
        {
            try
            {
                var productTableAdapter = new ProductTableAdapter
                {
                    Connection = { ConnectionString = connProductString }
                };
                var companyTableAdapter = new CompanyTableAdapter()
                {
                    Connection = { ConnectionString = connProductString }
                };
                var companyDataTable = companyTableAdapter.GetAllCompanies();

                for (int companyRowIndex = 0; companyRowIndex < companyDataTable.Rows.Count; companyRowIndex++)
                {
                    var startTime  = DateTime.Now;
                    var companyRow = companyDataTable[companyRowIndex];
                    var companyID  = companyRow.ID;
                    try
                    {
                        //Calculate Hash
                        HashSet <ProductSign> insertedProducts = new HashSet <ProductSign>(new ProductSignComparer());
                        var productDataTable = productTableAdapter.GetAllProductName(companyID);
                        for (int productRowIndex = 0; productRowIndex < productDataTable.Rows.Count; productRowIndex++)
                        {
                            var productSign = new ProductSign();
                            var productRow  = productDataTable[productRowIndex];
                            if (productRow["Name"] == DBNull.Value)
                            {
                                continue;
                            }
                            productSign.Name = productRow.Name;
                            if (productRow["Price"] == DBNull.Value)
                            {
                                productSign.Price = productRow.Price;
                            }
                            if (productRow["ImageUrls"] == DBNull.Value)
                            {
                                productSign.ImageUrl = productRow.ImageUrls;
                            }
                            if (insertedProducts.Contains(productSign))
                            {
                                continue;
                            }
                            int rootID = 0;
                            if (productRow["ProductID"] != DBNull.Value)
                            {
                                rootID = productRow.ProductID;
                            }
                            ProductNameHashBAL.InsertProductNameHash(productRow.ID, productRow.Name, companyID, rootID, productRow.Price);
                            insertedProducts.Add(productSign);
                        }
                        Log.InfoFormat("Insert MerchantProductHash - Company [{0}/{1}]. {2} products", companyRowIndex, companyDataTable.Rows.Count, productDataTable.Rows.Count);
                        var totalTime = (DateTime.Now - startTime).TotalSeconds;
                        Log.InfoFormat("Time: {0} s", totalTime);
                    }
                    catch (Exception innerException)
                    {
                        Log.Error("BuildNameHash. CompanyID: " + companyID, innerException);
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error("BuildNameHash", exception);
            }
        }