コード例 #1
0
 private int Insert(InManufacturer manufacturer)
 {
     String Query = "INSERT INTO [SecLockManufacturer]([Code],[Name],[ImagePath],[Url]) VALUES('"
         + manufacturer.Code + "','" + manufacturer.Name + "','" + manufacturer.ImagePath + "','" + manufacturer.Url + "');";
     OleDbDataManager oDm = new OleDbDataManager(this.ConnectionString, Query, true);
     return oDm.RunActionQuery();
 }
コード例 #2
0
 public int Save(InManufacturer manufacturer)
 {
     var x = GetData(manufacturer);
     if (x.Count > 0)
         return Update(manufacturer);
     else
         return Insert(manufacturer);
 }
コード例 #3
0
 private int Update(InManufacturer manufacturer)
 {
     String Query = "UPDATE [SecLockManufacturer] SET [Name] = '" + manufacturer.Name
         + "',[ImagePath] = '" + manufacturer.ImagePath
         + "', [Url] = '" + manufacturer.Url
         + "' WHERE [Code] = '" + manufacturer.Code + "'";
     OleDbDataManager oDm = new OleDbDataManager(this.ConnectionString, Query, true);
     return oDm.RunActionQuery();
 }
コード例 #4
0
 public List<InManufacturer> GetData(InManufacturer manufacturer)
 {
     String Query = "SELECT * FROM SecLockManufacturer WHERE Code = '" + manufacturer.Code +"' ORDER BY Name";
     OleDbDataManager oDm = new OleDbDataManager(this.ConnectionString, Query, true);
     return DataParser.ToList<InManufacturer>(oDm.GetTable());
 }
コード例 #5
0
 public List<InManufacturerSeries> GetData(InManufacturer manufacturer)
 {
     String Query = "SELECT * FROM SecLockManufacturerSeries WITH (NOLOCK) WHERE ManufacturerCode = '" + manufacturer.Code + "' ORDER BY Name";
     SqlCeDataManager oDm = new SqlCeDataManager(this.ConnectionString, Query, true);
     return DataParser.ToList<InManufacturerSeries>(oDm.GetTable());
 }
コード例 #6
0
 public int Count(InManufacturer manufacturer)
 {
     String Query = "SELECT COUNT(1) FROM SecLockManufacturerSeries WITH (NOLOCK) WHERE ManufacturerCode = '" + manufacturer.Code + "'";
     OleDbDataManager oDm = new OleDbDataManager(this.ConnectionString, Query, true);
     return (int)oDm.GetTable().Rows[0][0];
 }
コード例 #7
0
 private void GetProductsByManufacturerFromDb(InManufacturer manufacturer)
 {
     var series = new InManufacturerSeriesManager(Constants.ConnectionString).GetData(manufacturer);
     manufacturer.SeriesList.AddRange(series);
 }
コード例 #8
0
 private void GetProductsByManufacturer(InManufacturer manufacturer)
 {
     //if (new InManufacturerSeriesManager(Constants.ConnectionString).Count(manufacturer) > 0)
     //    GetProductsByManufacturerFromDb(manufacturer);
     //else
         GetProductsByManufacturerFromSite(manufacturer);
 }
コード例 #9
0
        private static void ExportManufacturerSeries(String ManufacturerCode)
        {
            String ConnStr = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True", Settings.GetValue("WebSpiderDB"));

            InManufacturer manufacturer = new InManufacturer();
            manufacturer.Code = ManufacturerCode;
            List<InManufacturerSeries> series = new InManufacturerSeriesManager(Constants.ConnectionString).GetData(manufacturer);

            foreach (InManufacturerSeries s in series)
                new ManufacturerSeriesManager(ConnStr).Save(ManufacturerCode, s);
        }
コード例 #10
0
        public static void Crawl(object objItem)
        {
            TaskDetailManager taskDetailManager = new TaskDetailManager(Constants.ConnectionString);
            TaskDetail taskDetail = (TaskDetail)objItem;
            try
            {

                if (!ReferenceEquals(taskDetail, null))
                {
                    taskDetail.TaskStatusText = Constants.PROCESSING_TEXT;
                    taskDetail.TaskStatus = TaskDetailStatus.Processing;
                    taskDetailManager.UpdateStatus(taskDetail.TaskID, taskDetail.TaskStatusText, taskDetail.TaskStatus);

                    LoginCheck(taskDetail);

                    List<InProduct> products = new List<InProduct>();
                    if (taskDetail.TaskMode == Constants.TaskMode.SECLOCK_MANUFACTURER_CRAWL){
                        InManufacturer manufacturer = new InManufacturer();
                        manufacturer.Name = taskDetail.TaskNameText;
                        manufacturer.Code = taskDetail.TaskNameValue;
                        new SecLockSpider().GetProductsByManufacturer(manufacturer);
                        foreach (InManufacturerSeries s in manufacturer.SeriesList)
                            products.AddRange(s.Products);
                    }
                    else if (taskDetail.TaskMode == Constants.TaskMode.SECLOCK_CATEGORY_CRAWL)
                    {
                        InCategory category = new InCategory();
                        category.Name = taskDetail.TaskNameText;
                        category.Code = taskDetail.TaskNameValue;
                        new SecLockSpider().GetCategoryProducts(category);
                        products = category.Products;
                    }
                    double totalProducts = products.Count();
                    for (int index = 0; index < totalProducts; index++)
                    {
                        try
                        {
                            products[index] = new SecLockSpider().GetProductFromSite(products[index].Code, taskDetail.IncognitoMode);

                            if (taskDetail.DownloadImages)
                                new SecLockSpider().DownloadProductImages(taskDetail, products[index]);

                            new InProductManager(Constants.ConnectionString).Save(products[index]);

                            FinalExport fe = new FinalExport();
                            fe.ExportSite = Constants.SiteName.SECLOCK;
                            fe.ExportType = Constants.ExportType.SECLOCK_CRAWL;
                            fe.ExportValue = products[index].Code;
                            exportManager.Insert(fe);
                        }
                        catch (Exception ex)
                        {
                        }
                        finally
                        {
                            taskDetail.TaskStatusText = String.Format("{0} - {1}%", Constants.PROCESSING_TEXT, (index / totalProducts * 100).ToString("0"));
                            taskDetail.TaskStatus = TaskDetailStatus.Processing;
                            taskDetailManager.UpdateStatus(taskDetail.TaskID, taskDetail.TaskStatusText, taskDetail.TaskStatus);
                        }
                    }
                    taskDetail.TaskStatusText = Constants.COMPLETED_TEXT;
                    taskDetail.TaskStatus = TaskDetailStatus.Completed;
                    taskDetailManager.UpdateStatus(taskDetail.TaskID, taskDetail.TaskStatusText, taskDetail.TaskStatus);
                }
            }
            catch (TaskCanceledException ex)
            {
            }
            catch (Exception ex)
            {
                //Utility.ApplicationLog(String.Format("AdiGlobal product Crawling completed with errors for {0}", taskDetail.TaskNameText));
                String json = null;
                Utility.ErrorLog(ex, json);
                if (Settings.GetValue("MailErrors") == true)
                    Utility.ApplicationLog(String.Format("{0}", ex.Message), Constants.EmailErrorFile);
                taskDetail.TaskStatusText = Constants.COMPLETED_ERROR_TEXT;
                taskDetail.TaskStatus = TaskDetailStatus.CompletedWithError;
                taskDetailManager.UpdateStatus(taskDetail.TaskID, taskDetail.TaskStatusText, taskDetail.TaskStatus);
            }
        }
コード例 #11
0
        public void GetProductsByManufacturerFromSite(InManufacturer manufacturer)
        {
            String Url = "http://www.seclock.com/products/items.asp?m=" + manufacturer.Code;

            if (!LoggedIn)
                Login();
            HtmlAgilityPack.HtmlDocument document = browser.GetWebRequest(Url);

            HtmlNodeCollection seriesNodes = document.DocumentNode.SelectNodes("//ul[@class='products']/li");

            manufacturer.SeriesList = new List<InManufacturerSeries>();
            if (!ReferenceEquals(seriesNodes, null))
            {
                foreach (HtmlNode seriesNode in seriesNodes)
                {
                    InManufacturerSeries series = new InManufacturerSeries();

                    var seriesDetail = seriesNode.SelectSingleNode("a");

                    if (!ReferenceEquals(seriesDetail, null))
                    {
                        series.Name = seriesNode.SelectSingleNode("a").InnerText;
                        series.Products = new List<InProduct>();

                        HtmlNodeCollection anchorNodes = seriesNode.SelectNodes("ul/li/a");

                        foreach (HtmlNode anchorNode in anchorNodes)
                        {
                            InProduct product = new InProduct();
                            product.Code = anchorNode.InnerHtml;
                            var dbProducts = new InProductManager(Constants.ConnectionString).GetData(product);
                            if (dbProducts.Count() > 0)
                            {
                                product = dbProducts[0];
                            }

                            product.Name = anchorNode.InnerText;
                            product.Url = anchorNode.Attributes["href"].Value;
                            product.ManufacturerSeries = series.Name;
                            product.ManufacturerName = manufacturer.Name;
                            product.ManufacturerCode = manufacturer.Code;

                            new InProductManager(Constants.ConnectionString).Save(product);
                            series.Products.Add(product);

                        }

                        new InManufacturerSeriesManager(Constants.ConnectionString).Save(manufacturer.Code, series);
                        manufacturer.SeriesList.Add(series);
                    }
                }
                exportManager.Insert(Constants.SiteName.SECLOCK, Constants.ExportType.SECLOCK_MANUFACTURER_SERIES, manufacturer.Code);
            }
        }