예제 #1
0
        public void RunSync(int numberItem)
        {
            MySqlAdapterRaoVat       mySqlAdapterRaoVat = null;
            Dictionary <int, string> dicCity            = null;
            RaoVatSQLAdapter         configXPathAdapter = new RaoVatSQLAdapter(
                new SqlDb(QT.Entities.Server.ConnectionStringCrawler));

            MongoDbRaoVat mongoDb = new MongoDbRaoVat();

            while (!this.bPause)
            {
                try
                {
                    if (TypeProcess == TypeRunSync.ReloadAllProuduct)
                    {
                        bool bOK = ReloadAllProduct(numberItem, mongoDb).Result;
                        WriteLog(string.Format("Commit {0} data", numberItem));
                        Thread.Sleep(1000);
                    }
                    else if (TypeProcess == TypeRunSync.AnalyscFieldProduct)
                    {
                        mySqlAdapterRaoVat = new MySqlAdapterRaoVat();
                        dicCity            = mySqlAdapterRaoVat.GetDicCity();
                        bool bOK = AnalysicField(numberItem, mongoDb, dicCity).Result;
                        WriteLog(string.Format("Commit {0} data", numberItem));
                        Thread.Sleep(1000);
                    }
                    else if (TypeProcess == TypeRunSync.FixSlug)
                    {
                        bool OK = AnalysicKeyword(10000, mongoDb, null).Result;
                        WriteLog(string.Format("Commit {0} data", numberItem));
                        Thread.Sleep(1000);
                    }
                    else if (TypeProcess == TypeRunSync.ReloadAllKeyWord)
                    {
                        bool iProductAnalysic = AnalysicKeyword(10000, mongoDb, null).Result;
                    }
                }
                catch (OperationAbortedException ex1)
                {
                    break;
                }
                catch (Exception ex)
                {
                    WriteLog(ex.Message);
                    Thread.Sleep(10000);
                }
            }
        }
예제 #2
0
        private void LoadCitys()
        {
            this.dicCity = mySqlAdapterRaoVat.GetDicCity();
            DataTable tblRegexCity = this.sqlDbRaoVat.GetTblData("SELECT * FROM RegexCity");

            foreach (DataRow row in tblRegexCity.Rows)
            {
                this.dicRegexCity.Add(Convert.ToInt32(row["id"]), Convert.ToString(row["regex"]));
            }

            int number = dicCity.Count;

            for (int i = 0; i < number; i++)
            {
                int key = dicCity.ElementAt(i).Key;
                if (this.dicRegexCity.ContainsKey(key))
                {
                    dicCity[key] = this.dicRegexCity[key];
                }
            }
        }
예제 #3
0
        private void RunData(string textProcess)
        {
            this.Invoke(new Action(() =>
            {
                this.btnStart.Visible = false;
            }));

            SqlDb sqlDb = new SqlDb(QT.Entities.Server.ConnectionStringCrawler);
            MySqlAdapterRaoVat mySqlAdapterRaoVat = new MySqlAdapterRaoVat();
            RaoVatSQLAdapter   sqlAdapterRaoVat   = new RaoVatSQLAdapter(sqlDb);

            if (textProcess == "cities")
            {
                var dicCity = mySqlAdapterRaoVat.GetDicCity();
                for (int i = 0; i < dicCity.Count; i++)
                {
                    var itemCity = dicCity.ElementAt(i);
                    if (sqlAdapterRaoVat.CheckExistCity(itemCity.Key))
                    {
                        sqlAdapterRaoVat.UpdateCity(itemCity.Key, itemCity.Value);
                    }
                    else
                    {
                        sqlAdapterRaoVat.InsertCity(itemCity.Key, itemCity.Value);
                    }
                    this.Invoke(new Action(() =>
                    {
                        this.progressBar1.Value = Convert.ToInt32(((double)i / (double)dicCity.Count) * 100);
                    }));
                }
            }
            else if (textProcess == "categories")
            {
                DataTable tblcategories = mySqlAdapterRaoVat.GetTableCategories();
                for (int i = 0; i < tblcategories.Rows.Count; i++)
                {
                    var itemCity = tblcategories.Rows[i];
                    if (sqlAdapterRaoVat.CheckExistCategories(Convert.ToInt32(itemCity["id"])))
                    {
                        sqlAdapterRaoVat.UpdateCategories(new QT.Entities.RaoVat.RaoVatCategory()
                        {
                            id        = Convert.ToInt32(itemCity["id"]),
                            level     = Convert.ToInt32(itemCity["level"]),
                            name      = Common.Obj2String(itemCity["name"]),
                            parent_id = Common.Obj2Int(itemCity["parent_id"]),
                            slug      = Common.Obj2String(itemCity["slug"]),
                            path      = Common.Obj2String(itemCity["path"])
                        });
                    }
                    else
                    {
                        sqlAdapterRaoVat.InsertCategory(new QT.Entities.RaoVat.RaoVatCategory()
                        {
                            id        = Convert.ToInt32(itemCity["id"]),
                            level     = Convert.ToInt32(itemCity["level"]),
                            name      = Common.Obj2String(itemCity["name"]),
                            parent_id = Common.Obj2Int(itemCity["parent_id"]),
                            slug      = Common.Obj2String(itemCity["slug"]),
                            path      = Common.Obj2String(itemCity["path"])
                        });
                    }
                    this.Invoke(new Action(() =>
                    {
                        this.progressBar1.Value = Convert.ToInt32(((double)i / (double)tblcategories.Rows.Count) * 100);
                    }));
                }
            }

            this.Invoke(new Action(() =>
            {
                this.btnStart.Visible = true;
            }));
        }