Esempio n. 1
0
        private void PushProduct()
        {
            while (true)
            {
                try
                {
                    var       productAdapter = new ProductAdapter(new SqlDb(QT.Entities.Server.ConnectionString));
                    DataTable tbl            = productAdapter.GetListCompanyIDToPush();
                    foreach (DataRow row in tbl.Rows)
                    {
                        long   companyID = Convert.ToInt64(row["ID"]);
                        string domain    = Convert.ToString(row["Domain"]);
                        this.Invoke(new Action(() =>
                        {
                            lblCompany.Text = domain;
                        }));

                        int iPage = 0;
                        while (true)
                        {
                            DataTable tblProduct = productAdapter.GetTblProductPushRedisForCompany(companyID, iPage);
                            if (tblProduct.Rows.Count == 0)
                            {
                                break;
                            }
                            iPage++;

                            this.Invoke(new Action(() =>
                            {
                                lblPageIDProduct.Text = iPage.ToString();
                            }));

                            foreach (DataRow rowProduct in tblProduct.Rows)
                            {
                                long   ProductID    = Convert.ToInt64(rowProduct["ID"]);
                                long   CompanyID    = Convert.ToInt64(rowProduct["Company"]);
                                string ProductName  = Common.Obj2String(rowProduct["Name"]);
                                int    ProductPrice = Common.Obj2Int(rowProduct["Price"]);
                                bool   Valid        = Common.Obj2Bool(rowProduct["Valid"]);
                                string keyRedis     = "product:" + ProductID.ToString();
                                int    Status       = Common.Obj2Int(rowProduct["Status"]);
                                string ImageUrl     = Common.Obj2String(rowProduct["ImageUrls"]);
                                bool   IsDea        = Common.Obj2Bool(rowProduct["IsDeal"]);
                                long   IDCategory   = Common.Obj2Int64(rowProduct["ClassificationID"]);
                                if (!RedisCacheProductInfo.Instance().ExistsInCache(companyID, ProductID))
                                {
                                    int count = 0;
                                    while (true)
                                    {
                                        try
                                        {
                                            break;
                                        }
                                        catch (Exception ex)
                                        {
                                            count++;
                                            if (count > 5)
                                            {
                                                break;
                                            }
                                            else
                                            {
                                                Thread.Sleep(1000);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        productAdapter.UpdateLastSyncProductRedisForCompany(companyID);
                    }
                }
                catch (ThreadAbortException ex)
                {
                    return;
                }
                catch (Exception ex1)
                {
                    Thread.Sleep(1000);
                }
            }
        }