コード例 #1
0
 private int Update(InCategory category)
 {
     String Query = "UPDATE [SecLockCategory] SET [Name] = '" + category.Name
         + "' WHERE [Code] = '" + category.Code + "'";
     OleDbDataManager oDm = new OleDbDataManager(this.ConnectionString, Query, true);
     return oDm.RunActionQuery();
 }
コード例 #2
0
 private int Insert(InCategory category)
 {
     String Query = "INSERT INTO [SecLockCategory]([Code],[Name]) VALUES('"
         + category.Code + "','" + category.Name + "');";
     OleDbDataManager oDm = new OleDbDataManager(this.ConnectionString, Query, true);
     return oDm.RunActionQuery();
 }
コード例 #3
0
 public int Save(InCategory category)
 {
     var x = GetData(category);
     if (x.Count > 0)
         return Update(category);
     else
         return Insert(category);
 }
コード例 #4
0
 public List<InCategory> GetData(InCategory category)
 {
     String Query = "SELECT * FROM SecLockCategory WHERE Code = '" + category.Code+ "' ORDER BY Name";
     OleDbDataManager oDm = new OleDbDataManager(this.ConnectionString, Query, true);
     return DataParser.ToList<InCategory>(oDm.GetTable());
 }
コード例 #5
0
        private void GetCategoryProductsFromSite(InCategory category)
        {
            String Url = string.Format("http://www.seclock.com/products/ajax/advanced-search-results.asp?i=&m=&c={0}&search_in=all", category.Code);
            HtmlAgilityPack.HtmlDocument document = browser.GetWebRequest(Url);
            HtmlNodeCollection productNodes = document.DocumentNode.SelectNodes("//a[@class='product-detail-from-search']");

            foreach (HtmlNode productNode in productNodes)
            {
                InProduct product = new InProduct();
                product.Code = productNode.InnerHtml;

                var dbProducts = new InProductManager(Constants.ConnectionString).GetData(product);
                if (dbProducts.Count() > 0)
                {
                    product = dbProducts[0];
                }
                product.Name = productNode.InnerHtml;
                product.Url = productNode.Attributes["href"].Value;
                product.CategoryName = category.Name;
                product.CategoyCode = category.Code;

                new InProductManager(Constants.ConnectionString).Save(product);

                category.Products.Add(product);
            }
        }
コード例 #6
0
        private List<InCategory> GetAllCategoriesFromSite()
        {
            if (!LoggedIn)
                Login();
            HtmlAgilityPack.HtmlNode.ElementsFlags.Remove("option");
            HtmlAgilityPack.HtmlDocument document = browser.GetWebRequest("http://www.seclock.com/products/search.asp?type=all");
            HtmlNodeCollection categoriesNodes = document.DocumentNode.SelectNodes("//select[@id='search_c']//option");
            List<InCategory> categories = new List<InCategory>();
            foreach (HtmlNode categoryNode in categoriesNodes)
            {
                InCategory c = new InCategory() { Code = categoryNode.Attributes["value"].Value, Name = categoryNode.InnerText };
                if (c.Name.Trim().ToUpper() == "ALL CATEGORIES")
                    continue;
                new InCategoryManager(Constants.ConnectionString).Save(c);
                categories.Add(c);

            }

            exportManager.Insert(Constants.SiteName.SECLOCK, Constants.ExportType.SECLOCK_CATEGORY, Constants.ExportType.SECLOCK_CATEGORY);
            return categories;
        }
コード例 #7
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);
            }
        }
コード例 #8
0
 public void GetCategoryProducts(InCategory category)
 {
     GetCategoryProductsFromSite(category);
 }