Example #1
0
        public static int InsertAllRootProductMappingIntoCache(string connProductString, string solrProductNodeID, TimeSpan?expiry = null)
        {
            var startTime = DateTime.Now;
            //Select List ProductIdentity
            var listProductIdentities = ProductIdentityBAL.GetListCompletedProductIdentity(connProductString);

            Log.InfoFormat("InsertAllRootProductMappingIntoCache: Get {0} productIdentities", listProductIdentities.Count);
            ProductIdentityCacheTool.InsertProductIdentities(listProductIdentities);
            var insertProductIdentitiesDuration = (DateTime.Now - startTime).TotalSeconds;

            Log.InfoFormat("InsertAllRootProductMappingIntoCache: Insert {0} productIdentities. Duration: {1} s", listProductIdentities.Count, insertProductIdentitiesDuration);
            startTime = DateTime.Now;
            var insertedCount = 0;

            foreach (var productIdentity in listProductIdentities)
            {
                try
                {
                    InsertRootProductMappingCache(productIdentity.ProductID, solrProductNodeID, expiry);
                    insertedCount++;
                }
                catch (Exception ex)
                {
                    Log.Error(string.Format("Insert RootProductMapping Error - ID {0}", productIdentity.ProductID), ex);
                }
            }
            var totalTime = (DateTime.Now - startTime).TotalSeconds;

            Log.InfoFormat("Insert RootProductMapping Completed. Inserted {0}/{1} products. Time: {2} s", insertedCount,
                           listProductIdentities.Count, totalTime);
            return(insertedCount);
        }
Example #2
0
        public static int InsertProductIdentities(IEnumerable <ProductIdentity> productIdentities, TimeSpan?expiry = null)
        {
            var startTime    = DateTime.Now;
            var indexedCount = 0;

            foreach (var productIdentity in productIdentities)
            {
                try
                {
                    if (ProductIdentityBAL.InsertProductIdentityIntoCache(productIdentity, expiry))
                    {
                        indexedCount++;
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Insert ProductIdentity Error", ex);
                }
            }
            var totalTime = (DateTime.Now - startTime).TotalSeconds;

            Log.InfoFormat("Insert ProductIdentities Completed. Inserted {0}/{1} products", indexedCount, productIdentities.Count());
            Log.InfoFormat("Total Time: {0} s", totalTime);
            return(indexedCount);
        }
Example #3
0
        public static int InsertProductIdentities(string connProductString, TimeSpan?expiry = null)
        {
            var startTime             = DateTime.Now;
            var listProductIdentities = ProductIdentityBAL.GetListCompletedProductIdentity(connProductString);
            var indexedCount          = 0;

            foreach (var productIdentityID in listProductIdentities)
            {
                try
                {
                    if (ProductIdentityBAL.InsertProductIdentityIntoCache(productIdentityID, expiry))
                    {
                        indexedCount++;
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Insert ProductIdentity Error", ex);
                }
            }
            var totalTime = (DateTime.Now - startTime).TotalSeconds;

            Log.InfoFormat("Insert ProductIdentities Completed. Inserted {0}/{1} products", indexedCount, listProductIdentities.Count);
            Log.InfoFormat("Total Time: {0} s", totalTime);
            return(indexedCount);
        }
Example #4
0
        public void LoadProductIdentity()
        {
            Log.Debug(string.Format("Loading Product Identity - Product ID: {0}", _productID));
            _productIdentity = ProductIdentityBAL.GetProductIdentity(_productID, Server.ConnectionString);
            if (_productIdentity == null)
            {
                isUpdate = false;
                textBoxLastUpdate.Text = "";
                _productIdentity       = new ProductIdentity()
                {
                    ProductID = _productID
                };
            }
            else
            {
                isUpdate = true;
            }

            textBoxProductID.Text = _productID.ToString();
            richTextBoxConfusedProductList.Text = _productIdentity.GetConfusedProductListString();
            richTextBoxAdditionProductIDs.Text  = _productIdentity.GetAdditionProductIDsString();
            richTextBoxKeywords.Text            = _productIdentity.GetKeywordSetsString();
            richTextBoxExcludeKeywords.Text     = _productIdentity.GetExcludeKeywordsString();
            richTextBoxProductBlackList.Text    = _productIdentity.GetProductBlackListString();
            richTextBoxCompanyBlackList.Text    = _productIdentity.GetCompanyBlackListString();
            textBoxLastUpdate.Text  = _productIdentity.LastUpdate.ToString("G");
            spintEditMinPrice.Value = _productIdentity.MinPrice;
            spinEditMaxPrice.Value  = _productIdentity.MaxPrice;
            richTextBoxNote.Text    = _productIdentity.Note;
        }
Example #5
0
        public static void BuildProductIdentitiesDict(string connProductString)
        {
            var cacheKey    = "ProductIdentitiesDict";
            var cacheServer = CacheManager.GetCacheServer("ProductIdentity");

            ProductIdentitiesDict = cacheServer.Get <Dictionary <int, List <WebProductIdentity> > >(cacheKey, true);
            if (ProductIdentitiesDict == null)
            {
                var startTime = DateTime.Now;
                ProductIdentitiesDict = new Dictionary <int, List <WebProductIdentity> >();
                var listProductIdentities = ProductIdentityBAL.GetListCompletedProductIdentity(connProductString);
                var getDBDuration         = (DateTime.Now - startTime).TotalSeconds;
                startTime = DateTime.Now;
                foreach (var productIdentity in listProductIdentities)
                {
                    var webProductIdentity = new WebProductIdentity()
                    {
                        SynonymsKeywordSet = new List <SynonymsKeywordHash>(),
                        KeywordBlackList   = new List <int>(),
                        ProductID          = productIdentity.ProductID,
                        MinPrice           = productIdentity.MinPrice,
                        MaxPrice           = productIdentity.MaxPrice
                    };
                    foreach (var synonymsKeywords in productIdentity.KeywordSets)
                    {
                        var listHash = new List <int>();
                        foreach (var keyword in synonymsKeywords.SynonymKeywords)
                        {
                            listHash.Add(Tools.getCRC32(AutoCorrector.Correct(keyword.Replace('-', ' ')).ToLower()));
                        }
                        webProductIdentity.SynonymsKeywordSet.Add(new SynonymsKeywordHash(listHash));
                    }
                    foreach (var keyword in productIdentity.ExcludeKeywords)
                    {
                        webProductIdentity.KeywordBlackList.Add(Tools.getCRC32(AutoCorrector.Correct(keyword.Replace('-', ' ')).ToLower()));
                    }
                    foreach (var synonymsKeywords in webProductIdentity.SynonymsKeywordSet)
                    {
                        foreach (var hash in synonymsKeywords.KeywordHashList)
                        {
                            if (ProductIdentitiesDict.ContainsKey(hash))
                            {
                                ProductIdentitiesDict[hash].Add(webProductIdentity);
                            }
                            else
                            {
                                ProductIdentitiesDict.Add(hash, new List <WebProductIdentity> {
                                    webProductIdentity
                                });
                            }
                        }
                    }
                }
                var buidDuration = (DateTime.Now - startTime).TotalSeconds;
                Log.InfoFormat("Build ProductIdentities Dict. GetDB Time: {0}, Build Time: {1} s", getDBDuration,
                               buidDuration);
                cacheServer.Set(cacheKey, ProductIdentitiesDict, true, new TimeSpan(20, 0, 0, 0));
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            string rabbitMQServerName = ConfigurationManager.AppSettings["rabbitMQServerName"];
            string updateRootProductMappingGroupName       = ConfigurationManager.AppSettings["updateRootProductMappingGroupName"];
            string updateRootProductMappingJobName         = ConfigurationManager.AppSettings["updateRootProductMappingJobName"];
            int    updateRootProductMappingJobExpirationMS = CommonUtilities.Object2Int(ConfigurationManager.AppSettings["updateRootProductMappingJobExpirationMS"], 0);
            string connectionstring = ConfigurationManager.AppSettings["ConnectionString"];

            if (connectionstring != null)
            {
                var       rabbitMQServer = RabbitMQManager.GetRabbitMQServer(rabbitMQServerName);
                JobClient jobClient      = new JobClient(updateRootProductMappingGroupName, GroupType.Direct, updateRootProductMappingJobName, true, rabbitMQServer);
                Log.InfoFormat("ConnectionString = {0}", connectionstring);
                var listProductIdentities = ProductIdentityBAL.GetListCompletedProductIdentity(connectionstring);
                Log.InfoFormat("Got {0} products.", listProductIdentities.Count);

                foreach (var productIdentity in listProductIdentities)
                {
                    var job = new Job {
                        Data = BitConverter.GetBytes(productIdentity.ProductID)
                    };
                    try
                    {
                        ProductIdentityBAL.InsertProductIdentityIntoCache(productIdentity);
                        jobClient.PublishJob(job, updateRootProductMappingJobExpirationMS);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Publish updateRootProductMapping job error. ProductID:" + productIdentity.ProductID, ex);
                    }
                }
                // Push special ID -> Trigger Update Redis and IndexSolr
                long specialID  = -1;
                var  specialJob = new Job {
                    Data = BitConverter.GetBytes(specialID)
                };
                jobClient.PublishJob(specialJob, updateRootProductMappingJobExpirationMS);
                Log.InfoFormat("Published specialID!");
                Thread.Sleep(100);
                rabbitMQServer.Stop();
            }
            else
            {
                Log.Error("ConnectionString Null");
            }
        }
Example #7
0
 public void SaveProductIdentity()
 {
     if (_productID == 0)
     {
         return;
     }
     UpdateObjectValue();
     if (isUpdate)
     {
         ProductIdentityBAL.UpdateProductIdentity(_productIdentity, Server.ConnectionString);
     }
     else
     {
         ProductIdentityBAL.InsertProductIdentity(_productIdentity, Server.ConnectionString);
     }
     LoadProductIdentity();
 }
Example #8
0
 public static bool InsertProductIdentity(long productID, string connProductString, TimeSpan?expiry = null)
 {
     try
     {
         var productIdentity = ProductIdentityBAL.GetProductIdentity(productID, connProductString);
         if (productIdentity == null)
         {
             Log.WarnFormat("Cannot get productIdentity - ID {0}", productID);
             return(false);
         }
         if (ProductIdentityBAL.InsertProductIdentityIntoCache(productIdentity, expiry))
         {
             return(true);
         }
         Log.ErrorFormat("Insert fail ProductIdentity {0}", productID);
         return(false);
     }
     catch (Exception ex)
     {
         Log.Error(string.Format("Insert ProductIdentity Error - iD {0}", productID), ex);
         return(false);
     }
 }