Пример #1
0
        private static void CacheIsBizwebsource()
        {
            List <long>    lstCompanyBizweb      = new List <long>();
            ProductAdapter productAdapter        = new ProductAdapter(new SqlDb(QT.Entities.Server.ConnectionString));
            List <long>    lstCompanyCheckBizweb = productAdapter.GetCompanyIdsCheckBizweb();
            Queue <long>   queueCompany          = new Queue <long>();

            foreach (long companyID in lstCompanyCheckBizweb)
            {
                queueCompany.Enqueue(companyID);
            }
            int numberThread = 10;

            for (int i = 0; i < numberThread; i++)
            {
                Task.Factory.StartNew(() =>
                {
                    int countCompany = 0;
                    int iThread      = i;
                    while (true)
                    {
                        countCompany++;
                        long companyID = 0;
                        lock (queueCompany)
                        {
                            if (queueCompany.Count > 0)
                            {
                                companyID = queueCompany.Dequeue();
                            }
                        }
                        if (companyID > 0)
                        {
                            string website   = QT.Entities.Common.GetWebsiteFromUrl((new Company(companyID).Website)) + @"/admin";
                            string html      = GABIZ.Base.HtmlUrl.HTMLTransmitter.getHTML(website, 45, 2);
                            html             = html.Replace("<form", "<div");
                            html             = html.Replace("</form", "</div");
                            string xpathTest = "//div[@class='login-logo text-center']//img";
                            GABIZ.Base.HtmlAgilityPack.HtmlDocument document = new GABIZ.Base.HtmlAgilityPack.HtmlDocument();
                            document.LoadHtml(html);
                            var nodeCheck = document.DocumentNode.SelectSingleNode(xpathTest);
                            if (nodeCheck != null)
                            {
                                if ((nodeCheck.Attributes.Contains("src") && nodeCheck.Attributes["src"].Value.Contains("bizweb")) ||
                                    (nodeCheck.Attributes.Contains("alt") && nodeCheck.Attributes["alt"].Value.Contains("bizweb")))
                                {
                                    lstCompanyBizweb.Add(companyID);
                                    log.Info(string.Format("Bizweb companys:{0}", lstCompanyBizweb.Count));
                                }
                            }
                            log.Info(string.Format("Thread {0} cCompany {1} Company {2}", iThread, countCompany, companyID));
                        }
                        else
                        {
                            log.Info("End check in thread");
                            productAdapter.UpdateSourceWebType(lstCompanyCheckBizweb, 1);
                            break;
                        }
                    }
                    return;
                });
            }

            return;
        }