Пример #1
0
        private void btnTestProduct_Click(object sender, EventArgs e)
        {
            string urlTest = urlTestTextBox.Text;

            if (!string.IsNullOrWhiteSpace(urlTest))
            {
                string url  = urlTestTextBox.Text;
                string html = GABIZ.Base.HtmlUrl.HTMLTransmitter.getHTML(url, 45, 2);
                GABIZ.Base.HtmlAgilityPack.HtmlDocument doc = new GABIZ.Base.HtmlAgilityPack.HtmlDocument();

                WebExceptionStatus status = WebExceptionStatus.Success;
                html = GABIZ.Base.HtmlUrl.HTMLTransmitter.getHTML(url, 45, 2, out status);
                doc.LoadHtml(html);

                ConfigXPaths config = this.raovatSqlAdapter.GetConfigByID((int)this.configXPathIDSpinEdit.Value);
                if (config == null)
                {
                    config = new ConfigXPaths()
                    {
                        ID = -1
                    }
                }
                ;
                if (this.LoadFormToConfig(ref config))
                {
                    var product = new ProductSaleNew();
                    int iError  = this.hanlerContentOfHtml.AnalyticsProductSaleNew(config.domain, urlTest, config, product,
                                                                                   this.raovatSqlAdapter.GetDicMapClassificationAndCategories(config.website_id),
                                                                                   this.raovatSqlAdapter.GetDicCityAndRegex());

                    FrmDataShow frmDataShow = new FrmDataShow(product.ToString());
                    frmDataShow.btnSave.Click += new EventHandler(delegate(object obj, EventArgs eventArg)
                    {
                        if (MessageBox.Show("Save to Cassandra?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
                        {
                            bool bExits = this.mongoDbAdapter.CheckExistsProductSalenew(product.id);
                            if (bExits)
                            {
                                mongoDbAdapter.UpdateProduct(product);
                                mongoDbAdapter.SaveHtml(product.id, html, bExits);
                            }
                            else
                            {
                                mongoDbAdapter.InsertProduct(product);
                                mongoDbAdapter.SaveHtml(product.id, html, bExits);
                            }
                        }
                    });
                    frmDataShow.ShowDialog();
                }
            }
            else
            {
                MessageBox.Show("Not url test");
            }
        }
Пример #2
0
        public override void ProcessProductData(Job job, GABIZ.Base.HtmlAgilityPack.HtmlDocument document)
        {
            bool bSkip = false;

            //long a = QT.Entities.Common.PhanTichGiaTuNoiDung(document.ToString(), 0, 10000000);
            //if (iTypeCrawler==ETypeCrawlRaoVat.CrawlerKeyWord)
            //{
            //    bSkip = false;
            //}
            //else if (configXPath.is_find_new && configXPath.is_reload)
            //{
            //    bSkip = false;
            //}
            //else if (!configXPath.is_find_new && !CheckProductExists(Common.CrcProductID(job.url)))
            //{
            //    bSkip = true;
            //}
            //else if (!configXPath.is_reload && CheckProductExists(Common.CrcProductID(job.url)))
            //{
            //    bSkip = true;
            //}


            if (!bSkip)
            {
                ProductSaleNew product = new ProductSaleNew();
                int            iError  = (new HandlerContentOfHtml()).AnalyticsProductSaleNew(configXPath.domain, job.url, configXPath, product
                                                                                              , this.dicMapClassificationAndCategories, dicCityAndRegex);

                if (iTypeCrawler == ETypeCrawlRaoVat.CrawlerKeyWord && product.tags != null && product.tags.Count > 0)
                {
                    foreach (var keyword in product.tags)
                    {
                        long crcKeyword   = Math.Abs(GABIZ.Base.Tools.getCRC64(keyword));
                        int  statusInsert = sqlRaoVatAdapter.UpdateKeyword(crcKeyword, keyword);
                        if (statusInsert == 1 && eventWhenSuccessProduct != null)
                        {
                            this.eventWhenSuccessProduct(this, string.Format("Insert keyword {0}", keyword));
                        }
                    }
                }
                else if (product.IsDetailSucess)
                {
                    if (product.classification_id > 0 && !dicClassification.ContainsKey(product.classification_id))
                    {
                        dicClassification.Add(product.classification_id, new RaoVatClassification()
                        {
                            id           = product.classification_id,
                            category_ids = new int[] { },
                            name         = product.web_category,
                            website_id   = configXPath.website_id
                        });

                        bool bInsert = sqlRaoVatAdapter.InserClassification(new RaoVatClassification()
                        {
                            id         = product.classification_id,
                            name       = product.web_category,
                            website_id = configXPath.website_id
                        });
                    }

                    //Phân tích category.
                    if (product.category_ids == null || product.category_ids.Count() == 0)
                    {
                        product.category_ids = new List <int> {
                            31
                        };
                        sqlRaoVatAdapter.InsertToNeedAdapter(product.id, product.url, product.web_category);
                    }

                    if (this.eventWhenSuccessProduct != null)
                    {
                        this.eventWhenSuccessProduct(this, product.ToString());
                    }

                    string _id    = this.mongoDbAdapter.GetProductbyID(product.id).Result;
                    bool   bExits = _id != "";
                    if (bExits)
                    {
                        mongoDbAdapter.UpdateProduct(product);
                    }
                    else
                    {
                        mongoDbAdapter.InsertProduct(product);
                    }
                }
            }
        }